How do I resize (specifically increase) the disk size of a Fedora guest VM running under VMWare ESXi 4.1?
I have a Fedora 16 VM with an lvm2 formatted disk, and I've increased its disk size using the vSphere client from 50GB to about 250GB. I rebooted the guest, and it correctly shows this size using fdisk -l /dev/sda
. However, df -H
still shows the old size.
I've found a few KB articles explaining how to resize partitions for some flavors of Linux, but nothing for Fedora with ext4. That article seems to imply I have to create a completely new partition, and that I can't simply expand the existing partition. Using Gparted, it also prevents me from simply resizing the existing partition. Is this impossible to do under Linux?
Edit: It turns out the drive is formatted as LVM2, which apparently most Linux tools, such as GParted, don't support.
Edit: The partition in logical volume I need to resize is the root partition. Is there any way to do this without a LiveCD?
This is a bit of a cut'n'paste of a document I wrote for internal use and although it probably over-answers your question I thought I'd put it on here in case it's of use to you or others OK.
Login to the machine as root or
sudo
each of the following commands, enterfdisk –l
, you should see something like this;In this case I've altered the values but as you can see this machine has a single ~20GB root virtual disk with two partitions, sda1 and sda2, sda2 is our first LVM 'physical volume', see how LVM uses a partition type of '8e'.
Now type
pvdisplay
, you'll see a section for this first PV (sda2) like this;This shows that this second partition (sda2) is mapped to a 'volume group' called 'rootvg'.
Now we can increase the size of the virtual disk using the usual vSphere VSClient by selecting the VM, choosing to 'edit settings', then selecting 'Hard Disk 1'. You can then increase the 'Provisioned Size' number – so long as there are no snapshots in place anyway – and select OK. This will take a few seconds to complete.
If you then switch back to the Linux VM and enter
where the X character is likely to be zero, it will perform a SCSI bus rescan, then run
fdisk –l
, you should see something like;You'll see that the disk size has increased, in this case to ~40GB from ~20GB but that the partition table remains the same.
We now need to create a new LVM partition, type
parted
, you should see something like this;You'll now need to create a new partition for the extra new space, type 'p' to see the current partition table such as this;
Then type
mkpart
, then select 'p' for 'Primary', for file system type enter 'ext3', for start enter a number a little higher than the combination of both 'sizes' listed above (i.e. 107MB + 21.4GB, so say 21.6GB), for end type the size of the disk (i.e. in this case 42.9GB). Once you press enter it will create this new primary partition, type 'p' to show the new partition table, you should see something like;You'll see that the new partition started after the first two and fills the available space, unfortunately we had to set it to a type of 'ext3', so let's change that.
Type 't', then the partition number (in our case 3 as it's the third partition), then for the 'hex code' enter '8e' – once you'd done this type 'p' again and you should see it change to 'Linux LVM';
Now we need to create a new LVM 'physical volume' in this new partition, type
pvcreate /dev/sda3
, this should then create a new LVM PV called /dev/sda3, typepvdisplay
to check;You should see something similar to above.
Now we need to extend the 'rootvg Volume Group', or create a new one for non-root 'volume group', type
vgdisplay
to list all 'volume groups', here's an example;If you want to extend the 'rootvg Volume Group' type
vgextend rootvg /dev/sda3
, once you press enter you should see a message saying the 'volume group' has been extended.If you wanted to create a new 'volume group' you'll need to use the
vgcreate
command – probably best call me for help with that.Once extended enter
vgdisplay
again to see that the 'rootvg' 'volume group' has indeed been extended such as here;You can see the 'VG Size' is as expected.
Now we need to extend the 'logical volume', type
lvdisplay
to show our 'logical volumes', you'll see something like;If we want to expand the /var file system from 3GB to 10GB then type
lvextend –L 10G /dev/rootvg/var
, now typelvdisplay
again, you'll see the 'logical volume' has grown to 10GB;Now the last thing we need to do is to grow the actual file system, this doesn't have to use all of the newly added space by the way. Enter
df –h
to show the current filesystems, here's an example;If we want to expand the /var file system from 3GB to 10GB then type
resize2fs /dev/mapper/rootvg-var
(or on CentOS maybexfs_growfs /dev/mapper/rootvg-var
, or similar commands depending on the type of file system). When you press enter the actual filesystem will grow, this may take time, enterdf –h
once completed to check.You're now finished!
Perform the following steps before lvextend
#pvcreate /dev/sda3 (to create a new physical volume, if you can't create then probably you didn't reboot after creating the partition)
#pvdisplay (to check that you have created a new physical volume)
#vgcreate VolGroup /dev/sda3 (to assign the VolGroup to the new physical volume)
#lvdisplay (to get the logical path name of the partition you want to extend)
#lvcreate -LxxGB -n root_new VolGroup (to assign logical size and create a new logical volume)
#lvextend /dev/mapper/VolGroup-lv_root /dev/sda3 (extend the root(if) partition finally)
#lvdisplay (check the LV size if it has increazed or not)
#resize2fs /dev/mapper/VolGroup-lv_root (to resize the actual file-system)
#df -h (then check whether the actual file-system value has increazed or not)
you have to resize it now
You must be on the 2.6 kernel do this with the file system mounted and the parameter enabled to allow online resizing. Otherwise, you have to first unmount the device, resize, them mount the device again.