Increase a virtual machine disk size it’s so easy, on almost all hypervisor: just click and increase the space on the virtual disk. But it’s just one part of the game, the second part it does the same inside the virtual machine, and maybe it’s not so easy or fast increase the partition and the filesystem inside the related guest OS.

For Windows OSes, starting with 2008 (Windows Server 2008 and Vista) it’s quite easy. For Linux, it could be easy with LVM, but a little tricky without it.

If you have a Linux installed without LVM (you can easily check it using df command and looking at the device names) then you have to manually modify your partition table.

First to all, check the geometry of your disk:

  • If you have MBR partition table use fdisk command (or parted)
  • If you have GPT partition table you may need other specific tools, depending on your distribution (but in most cases parted or also fdisk may still work).

Then you need to umount the filesystem inside of the partition that you need to extend. This is needed to avoid inconsistency, but also I/O errors during the operation. For the root filesystem could be more difficult umount the filesystem, in this case, you can use a live distribution or simply mount the filesystem in read-only… you may have some I/O errors, but you preserve the integrity.

At this point, you can resize the partition by defining the new end block. One simple way just deletes the old partition and create a new one (but a better way could modify the partition end). For example, using fdisk command:

  1. Run fdisk on the right disk (X is the correct letter of your disk): fdisk /dev/sdX
  2. Check the partition table by pressing p (to view partition details)
  3. Delete the partition by pressing d (to delete the partition)
  4. Select the right partition that you want to delete, in most cases will be the only on the disk, so press 1 (to select the partition)
  5. Create a new partition by pressing n (to create new partition) and select the partition type whether Primary (by pressing p) and the right number
  6. Get the first block from the partition details in point 2
  7. Press enter to accept the default as the last block.
  8. Check the partition table by pressing p (to list the partition and confirm)
  9. Save your new partition table

Finally, you need to re-read the partition table using this command:

[root@linux ~]# partprobe

Your partition resize is now completed. Note that the partition that you want to resize must be the last one on disk so it can grow contiguously into the free space.

Now it’s the turn of the filesystem inside the partition: you also need to resize it on the extended partition.

First could be useful to check the filesystem. Then you can resize it and this can vary on the filesystem type. For ext3 and ext4 you can use this command:

[root@linux ~]# resize2fs /dev/sdX

If your filesystem is very old (around 2007) and created with an older build of mkfs.ext2, it may not be configured for online resize (missing -O resize_inode flag). In this case, the online resize will not work.

More recent versions of mkfs.ext2 automatically reserve space for block group descriptor tables to enable online resize of the filesystem.

This post has already been read 4869 times.

Andrea MauroAbout Andrea Mauro (2737 Posts)

Virtualization, Cloud and Storage Architect. Tech Field delegate. VMUG IT Co-Founder and board member. VMware VMTN Moderator and vExpert 2010-18. Dell TechCenter Rockstar 2014-15. Microsoft MVP 2014-16. Veeam Vanguard 2015-18. Nutanix NTC 2014-18. PernixPro 2014-16. Several certifications including: VCDX-DCV, VCP-DCV/DT/Cloud, VCAP-DCA/DCD/CIA/CID/DTA/DTD, MCSA, MCSE, MCITP, CCA, NPP.

Related Post: