3

We are managing more and more Linux (Ubuntu) based VMs at work, but I'm starting to struggle with something as simple as expanding an existing VM's disk, something that takes literally seconds to do for our Windows VMs (VM properties -> enter new size -> ok, then diskpart, rescan, sel vol 0, extend, all done).

But when looking at the options under Linux, it seems to boil down to one of these solutions, depending if you use LVM or not.

  1. LVM -> Add new virtual disk, add partition on the disk, extend with the new partition

  2. LVM -> Increase existing disk, add partition on the existing disk, extend with the new partition.

  3. Boot of a GParted LiveCD ISO and either above, or increase the size of the existing partition.

There are several reasons I can't utilize the above:

  1. You end up with a ton of extra hard disks, and there seems to be a limitation on 16 minor numbers for SCSI devices (http://gparted.sourceforge.net/faq.php#faq-8)?, so after you have increased the disk 16 times, you are out of luck.

  2. Similar to the above, even worse if it's not GPT, then we can only extend 3 times assuming no other partitions on the disk.

  3. Some of the stuff can't easily be taken offline, so rebooting to a Live CD isn't possible.

It gets even worse when our corporate policies prevent us from using thin provisioning, and the VMs are stored on all flash SAN arrays where storage is expensive, so we can't just add 500GB and be done with it, we have to keep the wasted space down to 20-30GB at most.

Have I missed any other options? how do other people handle this in production?, most of our stuff is on Ubuntu 16.04 (we try to stay updated on the current LTS version), so open for anything that will work on that, we are currently using ext4, but that's not a requirement, but a journalized filesystem is preferred though.

I've been seriously considering just going with NFS with say NetAPP or similar for our Linux VMs since I'm out of other ideas at this stage, and just stuff anything that grows on the nfs mount point.

karel
  • 114,770
md2017
  • 41
  • ext4 file systems can be grown (right border moved to the right) while mounted, that is not a problem. This works without LVM but only raw partitions, if the unallocated space is located directly right of the partition to grow. Not sure how/whether your virtualization hypervisor allows you to grow connected disk images though. – Byte Commander Feb 21 '17 at 12:31
  • Ok, so the optimal way on 16.04, is to just 1) increase the disk size in VMWare, use fdisk to remove the existing partition entry, add a new one coverering all the space incl. the newly added, then run partprobe, then resize2fs ? (assuming a single disk setup with ext4, without lvm). – md2017 Feb 21 '17 at 13:59
  • No no, don't delete the partition. Just grow it as described in http://askubuntu.com/questions/24027/how-can-i-resize-an-ext-root-partition-at-runtime – Byte Commander Feb 21 '17 at 16:59
  • 1
    Only use LVM for physical disks. On a VM you can just expand the virtual disk, and the rescan and expand the filesystem. Also never have more than one partition on a virtual disk, add more virtual disks in more partitions/filesystems is needed - it's much more simple to manage, and can be done on the fly. – Soren A Feb 23 '17 at 13:14

2 Answers2

1

This is what I came up with, after several different tries, and tested with a VM running Ubuntu 16.04 with ext4 (not using LVM, and not trying to increase the root disk, just an additional disk) on an ESXi 6.0 host.

Just extending the disk size on the VM, did nothing, dmesg didn't mention any changes had happened.

So:

  1. echo 1 > /sys/class/scsi_device/2\0:0\0:/device/rescan

  2. dmesg now mentions there has been a capacity change from old size to new size

  3. Running resize2fs/parted/partprobe at this point, is still completely unaware of the new disk added, fdisk F can see the extra empty space, but there's no way to really add it to the existing partition

  4. run fdisk and delete the partition (yes this needs to happen), then create a new partition, and it will pick up the proper size.

  5. run resize2fs to grow the ext4 filesystem.

I hope that someday Linux gets proper storage management support. It's ridiculous to have to delete partitions to expand disk sizes in 2017.

karel
  • 114,770
md2017
  • 41
  • I always do (1) boot from an installation medium; (2) sudo parted /dev/sda2 resizepart -1s; (3) (if you are using LVM) lvresize or (with no LVM) resize2fs. Takes maybe 3 minutes. – AlexP Feb 23 '17 at 12:46
0

here what I've come up so far using a test machine

  • extend the harddisk in the backend i.e. vsphere hyperv

  • create a snapshot first

  • delete the partition using fdisk and create a new one. Make sure to use 8e system ID for LVM

  • pvresize /dev/sda2 --> this is partition where "/" is mounted.

  • lvextend -l +100%FREE /dev/vg1/lv1

  • xfs_growfs /dev/vg1/lv1 --> this is for XFS filesystem. use resize2fs if applicable

EGV
  • 1