When I create new servers with Proxmox I normally start of with a small disk to cover the expected usage. If like me you find that you need more space the disk will need to be expanded, this is not as hard as you would expect it to be when using LVM.
To expand the disk on your server there are 2 methods you can add a new disk and then format and add to an existing volume group or you can expand the existing volume group, here I will show how to expand an existing volume group.
Please Please Please dont blame me if this does not work for you and you lose all your data, you should always have a backup of any data that you require just in case something does not work out right. With that said I have done this many times with no problems.
I am going to assume that you have a basic LVM structure. Make sure you have a backup of any data on the partitions as we will be making changes to the partitions and it’s easy to make a typo mistake etc and data to vanish!
The main thing to watch out for is the partitioning layout check what you have setup with fdisk -l
Disk /dev/vda: 386.5 GB, 386547056640 bytes 16 heads, 63 sectors/track, 748982 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0002bbc2Device Boot Start End Blocks Id System /dev/vda1 * 3 1222 614400 83 Linux Partition 1 does not end on cylinder boundary. /dev/vda2 1222 499321 251042360 8e Linux LVM Disk /dev/mapper/vg_hosting01-lv_root: 248.5 GB, 248474763264 bytes 255 heads, 63 sectors/track, 30208 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_hosting01-lv_swap: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_hosting01-lv_tmp: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
To check where the mounts are you can run df -h or look in the /dev/ df -h should be fine though.
Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_hosting01-lv_root 228G 211G 5.7G 98% / tmpfs 2.9G 0 2.9G 0% /dev/shm /dev/vda1 575M 179M 367M 33% /boot /dev/mapper/vg_hosting01-lv_tmp 3.9G 8.8M 3.7G 1% /tmp
So we can now see that is on the disks and the basic layout we need to expand the disk, in Proxmox open up the gui and select the disk for your VM and resize it to the required size.
Follow these steps load fdisk with the drive your volume group is on (vda)
fdisk /dev/vda WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help):
We now need to delete the vda2 partition and re-add it. When we re-add it, we change the number of cylinders to fill the partition with the remaining space. Press p to print the current partitions.
Command (m for help): p Disk /dev/vda: 386.5 GB, 386547056640 bytes 16 heads, 63 sectors/track, 748982 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0002bbc2 Device Boot Start End Blocks Id System /dev/vda1 * 3 1222 614400 83 Linux Partition 1 does not end on cylinder boundary. /dev/vda2 1222 499321 251042360 8e Linux LVM Command (m for help):
We want to delete partition 2 and re-add it again so we can fill up the remaining space. Press d and then select partition 2.
Command (m for help): d Partition number (1-4): 2 Command (m for help):
Now we will re-create the partition. Set the partition number to 2, for the starting cylinder, set to whatever was the starting cylinder before (1222). The default should be set as this anyway. For the end cylinder, leave the default as this will have the value of the last available cylinder.
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (1-748982, default 1): 1222 Last cylinder, +cylinders or +size{K,M,G} (1222-748982, default 748982): Using default value 748982 Command (m for help):
Finally we want to change the type to LVM (8E)
Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM) Command (m for help):
Save the changes and quit with W
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
As prompted you will need to reboot for the changes to take affect.
Once the reboot has completed we will use the pvresize command to use the extra space, this will resize the space that a LVM volume group can use on a partition.
pvresize /dev/vda2 Physical volume "/dev/vda2" changed 1 physical volume(s) resized / 0 physical volume(s) not resized
Now we need to resize the logical volume lv_root. Use lvresize for this.
lvresize -l +100%FREE /dev/mapper/vg_hosting01-lv_root Size of logical volume vg_hosting01/lv_root changed from 231.41 GiB (59241 extents) to 351.41 GiB (89961 extents). Logical volume lv_root successfully resized
Finally we want to resize the actual underlying file system. I am using ext3 for the root so I use the resize2fs command
resize2fs /dev/mapper/vg_hosting01-lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/vg_hosting01-lv_root is mounted on /; on-line resizing required old desc_blocks = 15, new_desc_blocks = 22 Performing an on-line resize of /dev/mapper/vg_hosting01-lv_root to 92120064 (4k) blocks. The filesystem on /dev/mapper/vg_hosting01-lv_root is now 92120064 blocks long.
A reboot is not required once this has completed but i always do one just to make sure the VM still boots after all the changes.