As a VMware sysadmin, you may be asked to extend a file system not by adding another virtual disk, but by extending the vmdk itself.
Such operation is relatively risk free but has to be done with the VM powered down, so the first thing to do is shut down the VM.
Log in any esx in your cluster, go to the vm datastore path and run:
# vmkfstools -X nnG vmname.vmdk
In such command, nn represents the new size of the disk, and obviously vmname is the name of your VM.
Now, you have to mount any redhat CD/DVD to your VM, power it on, and boot it from CD/DVD.
Run the installer with the command: linux rescue
Obtain the recovery shell but skipping any network and disk mounting options, then we’re ready to go.
Assuming you will be extending the root disk, you will have to do the following with fdisk:
# fdisk /dev/sda
remove sda2 partition(d, 2)
create new sda2 partition(n, p, 2)
change partition type in Linux LVM (t, 2, 8e)
write changes and exit (w)
Now, let’s resize the physical partition to the max:
# lvm pvresize /dev/sda2
If you want to check if everything is ok, run:
# lvm pvdisplay
Now, activate the Logical Volumes:
# lvm vgchange -a y
If you want to check the configured Logical Volumes, run:
# lvm lvdisplay
It is mandatory to fscheck the integrity of the Logical Volume to be extended:
#e2fsck -f /dev/VolGroup00/LogVol00
Now, we can extend the Volume Group:
lvm lvextend -L+10G /dev/VolGroup00/LogVol00
And then the file system:
resize2fs /dev/VolGroup00/LogVol00
Finished, reboot the system and that’s it!
Of course you’ll have not just to play a bit in that case, probably you’ll have to spit blood too.
I should have mentioned this tutorial is for disks with no more than the swap and root partition inside, with the root partition on the last section of the disk. Should you have anything past it, you won’t be able to follow this guide. In that case, you’d better add another vmdk disk to the VM, and vgextend the VG by adding another Physical Volume.
But, after all, everyone knows it’s a good practice to keep data off another disk, right? ;)
Quite a noob on VM, so just a question:
When you re-create the sda2 partition you’re allocating all the possible space, right? If you had other partitions after sda2 you should play a bit more with that, isn’t it?