How to expand a drive in ESXi with Linux
To extend an eagerly zeroed thick drive in ESXi do the following:
- Enable the shell.
- Confirm the vm is turned off or the disk is not active on any vm
- Login to the shell in your favorite terminal
- use the following command:
vmkfstools -X NumberG/T -d eagerzeroedthick /vmfs/volumes/Path/to/your/volume/volume_name.vmdk
- Once completed verify you’ve properly extended the drive with this command:
vmkfstools -D /vmfs/volumes/Path/to/your/volume/volume_name.vmdk
- Back in the web console, remove the drive from the vm, and then re-add it. It should now show the correct size.
To be able to use this extra space in linux you also need to resize the partition and file system in linux. To achieve that do the following:
- Firstly, confirm the disk is not mounted, if you have the disk mounted automatically on boot you’ll need to either unmount it with the command:
sudo umount /dev/sdX
OR if that doesn’t work you should just disable automount entirely here:/etc/fstab
and then restart the machine to unmount- Either
sudo umount /dev/sdX
orsudo vi /etc/fstab
- Either
- Enter command:
sudo parted /dev/sdX print
- Record the partition number of the partition you want to extend
- To automatically extend the partition to take up all available space:
- enter command:
sudo growpart /dev/sdX PartitionNumber
- enter command:
- To begin extending the filesystem, first we need to do a quick diskcheck:
- enter command:
sudo e2fsck -fy /dev/sdXPN
- enter command:
- Once the disk check is completed and all optimizations have been completed, we can now extend the filesystem with the following command:
sudo resize2fs /dev/sdXPN
Congratulations, your disk should now be extended and usable by the OS.