Intro
I just did this on a vm on my proxmox system when I discovered I had run out of storage space.
Since I remembered the steps incorrectly, and realized I didn't have any notes on how to do this, I thought I'd note them down now, for later.
With no further ado, this is a quick and dirty how-to for extending a lvm.
Info gathering, current state
- Show current status with df:
root@rear:/home# df -h
Filesystem Size Used Avail Use% Mounted on
udev 210M 0 210M 0% /dev
tmpfs 49M 6.1M 43M 13% /run
/dev/mapper/rear--vg-root 491G 491G 0 100% /
tmpfs 241M 0 241M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 241M 0 241M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/1000 - Run lvmdiskscan. Sdb is the new virtual disk I added before.
root@rear:/home# lvmdiskscan
/dev/rear-vg/root [ <499.50 GiB]
/dev/sda1 [ <500.00 GiB] LVM physical volume
/dev/rear-vg/swap_1 [ 512.00 MiB]
/dev/sdb [ 500.00 GiB]
2 disks
1 partition
0 LVM physical volume whole disks
1 LVM physical volume - Show the current physical volumes.
root@rear:/home/# pvdisplay
--- Physical volume ---
PV Name /dev/sda1
VG Name rear-vg
PV Size <500.00 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 127999
Free PE 0
Allocated PE 127999
PV UUID 1M8upJ-yDYM-BZlD-dY9v-n9vO-oJbB-bJZfCT - Show the logical volume info:
root@rear:/home/# lvdisplay
--- Logical volume ---
LV Path /dev/rear-vg/root
LV Name root
VG Name rear-vg
LV UUID pZN6cI-KpB5-5I04-zNMB-LOcU-cEQL-dG6CUy
LV Write Access read/write
LV Creation host, time rear, 2020-04-16 15:25:12 +0200
LV Status available
# open 1
LV Size <499.50 GiB
Current LE 127871
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/rear-vg/swap_1
LV Name swap_1
VG Name rear-vg
LV UUID 8dW0ke-Szeh-iHSN-5GY3-efOB-uRjJ-m9EnHK
LV Write Access read/write
LV Creation host, time rear, 2020-04-16 15:25:12 +0200
LV Status available
# open 2
LV Size 512.00 MiB
Current LE 128
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1 - So I have two volumes. We'll need this info for later, when we're extending the root-volume.
/dev/rear-vg/root
/dev/rear-vg/swap_1 - Running fdisk shows me the new disk as /dev/sdb.
root@rear:/home# fdisk -l
...
Disk /dev/sdb: 500 GiB, 536870912000 bytes, 1048576000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 2A78D1E2-5DE5-4394-ACB3-D58BBF4C1705
Guide
- Create a new physical volume on the new drive.
For partitiontioning this new drive, see Partitioning notes.
The warning message is because I remembered the procedure wrongly and started out with creating a new partiontion on the new disk. This is not needed, so we overwrite it.
root@rear:/home/# pvcreate /dev/sdb1
WARNING: Device for PV tkfk9p-sSl8-c9Ka-SBaX-INta-Q9vl-SiMD8L not found or rejected by a filter.
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
Wiping ext4 signature on /dev/sdb1.
Physical volume "/dev/sdb1" successfully created. - List the new volume.
root@rear:/home/# lvmdiskscan -l
WARNING: only considering LVM devices
/dev/sda1 [ <500.00 GiB] LVM physical volume
/dev/sdb1 [ <500.00 GiB] LVM physical volume
0 LVM physical volume whole disks
2 LVM physical volumes - Add the new physical volume to the logical volume.
root@rear:/home# vgextend rear-vg /dev/sdb1
Volume group "rear-vg" successfully extended - Now we have more disk in the volume group, but we also need to extend the volume to the new disk. Consider it sort of as making the new area available for use.
We will use all of the available new space for extension.root@rear:/home# lvm lvextend -l +100%FREE /dev/rear-vg/root
Size of logical volume rear-vg/root changed from <499.50 GiB (127871 extents) to 999.49 GiB (255870 extents).
Logical volume rear-vg/root successfully resized. - Before the new storage will be available for us, we need to do a last step.
We need to update the filesystem metadata to make it aware or the newly added storage space.root@rear:/home# df -h
Filesystem Size Used Avail Use% Mounted on
udev 210M 0 210M 0% /dev
tmpfs 49M 1.3M 47M 3% /run
/dev/mapper/rear--vg-root 491G 424G 43G 91% /
tmpfs 241M 0 241M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 241M 0 241M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/1000
root@rear:/home# resize2fs -p /dev/mapper/rear--vg-root
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/mapper/rear--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 63, new_desc_blocks = 125
The filesystem on /dev/mapper/rear--vg-root is now 262010880 (4k) blocks long.
root@rear:/home# df -h
Filesystem Size Used Avail Use% Mounted on
udev 210M 0 210M 0% /dev
tmpfs 49M 1.3M 47M 3% /run
/dev/mapper/rear--vg-root 983G 424G 515G 46% /
tmpfs 241M 0 241M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 241M 0 241M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/1000 - We're done.
LVM VM disk resizing in Proxmox
See this article; Proxmox notes.
Sources
https://www.digitalocean.com/community/tutorials/how-to-use-lvm-to-manage-storage-devices-on-ubuntu-18-04
https://www.cyberciti.biz/faq/howto-add-disk-to-lvm-volume-on-linux-to-increase-size-of-pool/
https://www.tecmint.com/add-new-disks-using-lvm-to-linux/
https://unix.stackexchange.com/questions/416886/why-do-i-need-to-do-resize2fs-after-lvextend