increase virtual disk with lvm
After moving to a new VM platform I had a large amount of data to transfer from the old host to a new disk on a VM. In order to work within the availalbe space I had to transfer a lot of data, delete it from the host and then grow the disk on the VM so I could transfer the rest of the data over.
First step was to add the initial disk to the VM and bring it online and get it mounted.
Stage 1: Existing Disk
As I'm just using the entire disk I created a disk using all the available space and a mount point /media
to mount the disk on.
sudo fdisk /dev/sdb sudo pvcreate /dev/sdb1 sudo vgcreate vg-media /dev/sdb1 sudo lvcreate -n lv-media --size 99G vg-media sudo mkfs.ext4 /dev/vg-media/lv-media
Once the disk was ready I added an entry in /etc/fstab
Next we increase the disk size through the host (Proxmox in this case).
Stage 2: Extend disk
Now we need to extend the existing disk to avail of the new space. Foist we increase the partition using growpart
admin01@jelly-01:~$ lsblk sdb 8:16 0 200G 0 disk └─sdb1 8:17 0 100G 0 part └─vg--media-lv--media 253:1 0 99G 0 lvm /media admin01@jelly-01:~$ sudo growpart /dev/sdb 1 CHANGED: partition=1 start=2048 old: size=209713152 end=209715200 new: size=419428319 end=419430367 admin01@jelly-01:~$ lsblk sdb 8:16 0 200G 0 disk └─sdb1 8:17 0 200G 0 part └─vg--media-lv--media 253:1 0 99G 0 lvm /media
Next we increase the volume
admin01@jelly-01:~$ sudo lvextend -r -l +100%FREE /dev/vg-media/lv-media Size of logical volume vg-media/lv-media changed from 99.00 GiB (25344 extents) to <200.00 GiB (51199 extents). Logical volume vg-media/lv-media successfully resized. resize2fs 1.46.5 (30-Dec-2021) Filesystem at /dev/mapper/vg--media-lv--media is mounted on /media; on-line resizing required old_desc_blocks = 13, new_desc_blocks = 25 The filesystem on /dev/mapper/vg--media-lv--media is now 52427776 (4k) blocks long. admin01@jelly-01:~$ sudo vgs VG #PV #LV #SN Attr VSize VFree vg-media 1 1 0 wz--n- <200.00g 0
And that's it, now we can start copying more data over :)
- note the PV was auto-expaanded, if this does not happen it can be done with
sudo pvresize /dev/sdb1
before increasing the LVM size.