Its possible to extend your disk space on your running virtual machine without even needing to reboot! There are a few caveats obviously, you need to be using LVM (if you are not, SHAME ON YOU!) and be comfortable with file systems and VMware.
- First add the new Hard Disk in the virtual machine settings.
- This can be done on the command line on the ESX server, but in this case I am not trying to extend the primary hard disk but just add another one.
- Using this script (It was written by someone named Kurt Garloff) rescan-scsi-bus.sh
- We will also upload this script to the Linux Digest git repo
- Using fdisk create a partition, I’m going to asume you’ll want to use the entire disk but if desired you could create multiple partitions on the new disk. Here we will just be using the entire disk
# fdisk /dev/sdb
- Type n for new partition
- p for primary
- Just hit enter again to use the default last cylinder since we want to use the entire disk in this case
- Finally enter w and enter to write the partition table to disk and sync the disk
- After adding the new partition we have to change the partition type to LVM vs 83 Linux (regular Linux partition type)
# fdisk /dev/sdb
- t (change partition type)
- 8e (for Linux LVM)
- And finally w and enter to write changes to disk
- Now that we have a valid LVM partition we need to Initialize the Physical Volume
# pvcreate /dev/sdb1
- Here using
- Once you have initialized the physical volume you can add it to the volume group that you wish. In this can I want to extend the root volume and I have named it vg00.
# vgextend vg00 /dev/sdb1
- Once you have added it to the volume group, you should see the newly available free space.
- You can see on the Free PE / Size line that I have 29.97 GB of free space, now lets use it!
- What we have to do now is actually extend the logical volume (vg00) so that it consumes the rest of the available space.
Tip: You can find out the path to your volume group with the df command and vgdisplay
# vgextend -L +29G /dev/vg00/rootvol
- Now that we hav extended the volume we have to extend the file system so the available space can be written to by the system. We do this by using the resize2fs command. Now because I am simply using ext3 this is the command for me, but if you were using a different file system such as xfs you need to use the tool available for that FS (xfs_grow for example)
# resize2fs /dev/mapper/vg00-rootvol
- And thats it! Checkout df to see your newly available disk space.
- Check back again for more articles on LVM here at Linux Digest, I will be writing another one on LVM snapshots and choosing the best file system for your needs.
- Also a side note, if you are using SAN backed storage like I am (In this case Netapp). You must make sure you align your VMDK before adding it to your vgroup. I will also be writing an article on how to do this and why its important for performance.
Thanks for reading!