Network/Procedures/Grow a VM's disk

From Makers Local 256
Jump to: navigation, search

So you have filled up the disk on one of our VMs, huh? Here is what you do. I will be using the mail VM because that's the one we most recently filled up... whoops.

  • Expand the LVM logical volume that contains the drbd data. Do this on both VM hosts. Replace 8G with the size you want and mail_disk with the name of the disk.
sudo lvresize -L 8G $(hostname)_storage/mail_disk
  Size of logical volume vm4_storage/mail_disk changed from 4.12 GiB (1056 extents) to 8.00 GiB (2048 extents).
  Logical volume mail_disk successfully resized
  • On whichever VM host has the disk as primary (check 'sudo drbd-overview' to see if this box is primary - wherever the VM is running is a good bet), tell drbd to adjust the replicated disk.
sudo drbdadm resize mail_disk
  • Watch drbd-overview and wait for the resynch to complete.
sudo watch drbd-overview
  • This step is only necessary if you are resizing a DISK, not a RAW PARTITION. Makers Local convention is to put _disk at the end of the logical volume name if it's a disk, and something else if it's a partition (_root, _swap, etc.). You can run this command inside of the VM to make sure.
sudo parted -l | grep -E 'dev|Table'                                                                                                                   
Disk /dev/xvda2: 6442MB
Partition Table: loop
Disk /dev/xvda5: 300GB
Partition Table: loop
Disk /dev/xvda6: 2000GB
Partition Table: loop

It says the type of the partition table is "loop". This VM has partitions, so you don't have to do anything.

sudo parted -l | grep -E 'dev|Table'
Disk /dev/xvda: 8590MB
Partition Table: msdos

If it says the partition table type is 'msdos' or anything else, you will need to use parted to manually manipulate the partition table within the VM so that the partition you want to be larger, becomes larger (now that the disk itself is larger). I won't put a lot of detail here because this process sucks and should be obsolete soon. It involves using sectors as the unit in parted to make sure you PERFECTLY align the partitions - because you will be editing the table live. I hate doing this!

  • At this point there is a partition that is larger than the file system it contains. So just run a command like this on that block device to make the file system grow to match its partition.
sudo resize2fs /dev/xvda1 
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/xvda1 is now 1831046 (4k) blocks long.

That's it. Hope you didn't mess up.