Adding Space to Linux Partitions

By jbayer - Last updated: Thursday, August 8, 2013 - Save & Share - Leave a Comment

Sometimes after you make a virtual machine, you find that you need to add more space to it.  You are left with two options:

  1. Build a new VM and copy everything over
  2. Expand the existing VM

The first option is slow and subject to error.  It is very easy to miss copying over a file or directory which isn’t obvious.

The second option, while better, still has it’s problems.  It really depends on how the virtual machine is set up.

These instructions address both simple VMs (stored in a disk file), VMs which are stored in an LVM partition, and VMs which are controlled by Ganeti

Resize a partiton/filesystem in a VM which is stored in a disk image file

  1. Stop the VM
  2. If on RHEL6/CentOS 6:

Resize using:

qemu-img resize vmdisk.img +40G

If on RHEL5/CentOS 5:

Resize using:

dd if=/dev/zero of=hdd.img seek=N obs=1MB count=0″

where hdd.img is the raw format image that you want to resize and N is the new size that you want the image to be, in megabytes. To change the units of N, change obs to something else such as 1GB for units in gigabytes (1000x1000x1000).

Pasted from <>


  1. Start vmanager, mount gparted ISO and make it the boot drive
  2. Delete & re-create LVM partition using fdisk
  3. Shutdown, and then boot the gparted cd again
  4. Resize the LVM physical volume:

pvresize /dev/vda2


Resizing an LVM Logical Volume

The following instructions assume that the LVM volume being resized is LogVol00


  1. Resize the LVM Logical Volume
  1. Get number of free PE using command:  pvdisplay
  2. lvresize /dev/VolGroup00/LogVol00 -l +numFree


Resizing an EXT3 filesystem


  1. Do an fsck of the filesystem, and then resize it

e2fsck -f /dev/VolGroup00/LogVol00

resize2fs -p /dev/VolGroup00/LogVol00


Final Steps if in a VM

  1. Shutdown VM
  2. Unmount gparted ISO
  3. Boot VM and test



To add space to a Ganeti system:


These instructions assume the following:

partition layout is simple partitions, no LVM

The partition to be resized is the last one, in the instructions below

The fileystem of the resized partition is either ext3 or ext4

The amount of space to be added is 25 gig


  1. On master ganeti system:

gnt-instance grow-disk ins27.a3k 0 25G

The syntax for the gnt-instance for this is:

gnt-instance grow-disk [–no-wait-for-sync] [–submit] [–absolute]

{instance} {disk} {amount}


  1. Shut down VM (has to be a full shutdown, not a reboot)
  2. Start VM
  3. Log on as root
  4. Using fdisk:
  1. Type “u” to change the units to sectors, necessary in case partition wasn’t lined up properly
  2. Type “p” to print the current partition layout

The following is an example, used for the instructions:

Disk /dev/vda: 247.0 GB, 246960619520 bytes
255 heads, 63 sectors/track, 30024 cylinders, total 482344960 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *          63      208844      104391   83  Linux
/dev/vda2          208845     4417874     2104515   82  Linux swap / Solaris
/dev/vda3         4417875   482335559   238958842+  83  Linux

  1. Record the start sector of vda3, in the example, it is 4417875
  2. Type “d” to delete a partition, when asked, enter “3” to delete vda3
  3. Type “n” to create a partition. use the following answers:
Partition type:                p (for primary)
Partition number:        3
First sector:                enter start sector recorded above
Last sector;                press <cr>
  1. Type “w” to write the updated partition table to the disk
  1. Reboot the VM
  2. after VM has rebooted, log on as root and type:
resize2fs  /dev/vda3


Posted in Linux Installations, Open Source, Virtulization • Tags: , , Top Of Page

Write a comment