Current LVM state
Scan all available block devices and identify those that can be used as LVM physical volumes
BASH
sudo lvmdiskscan
/dev/nvme0n1p1 [ <1.05 GiB] /dev/nvme0n1p2 [ 2.00 GiB] /dev/nvme0n1p3 [ <1.82 TiB] LVM physical volume 0 disks 2 partitions 0 LVM physical volume whole disks 1 LVM physical volume
Multi-line output for each physical volume
BASH
sudo pvdisplay -m
--- Physical volume ---
PV Name /dev/nvme0n1p3
VG Name ubuntu-vg
PV Size <1.82 TiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 476150
Free PE 212470
Allocated PE 263680
PV UUID aO6mUk-cTcH-7meV-IQvj-Vt2i-kKU7-NmVzGp
--- Physical Segments ---
Physical extent 0 to 25599:
Logical volume /dev/ubuntu-vg/lv-root
Logical extents 0 to 25599
Physical extent 25600 to 255999:
Logical volume /dev/ubuntu-vg/lv-pub
Logical extents 0 to 230399
Physical extent 256000 to 263679:
Logical volume /dev/ubuntu-vg/lv-www
Logical extents 0 to 7679
Physical extent 263680 to 476149:
FREE
Add a Logical Volume
Within all remaining free storage
BASH
sudo lvcreate -l 100%FREE -n lv-media ubuntu-vg
pvdisplay now shows
--- Physical volume ---
PV Name /dev/nvme0n1p3
VG Name ubuntu-vg
PV Size <1.82 TiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 476150
Free PE 0
Allocated PE 476150
PV UUID aO6mUk-cTcH-7meV-IQvj-Vt2i-kKU7-NmVzGp
--- Physical Segments ---
Physical extent 0 to 25599:
Logical volume /dev/ubuntu-vg/lv-root
Logical extents 0 to 25599
Physical extent 25600 to 255999:
Logical volume /dev/ubuntu-vg/lv-pub
Logical extents 0 to 230399
Physical extent 256000 to 263679:
Logical volume /dev/ubuntu-vg/lv-www
Logical extents 0 to 7679
Physical extent 263680 to 476149:
Logical volume /dev/ubuntu-vg/lv-media
Logical extents 0 to 212469
Format the newly created Logical Volume
BASH
sudo mkfs.ext4 /dev/ubuntu-vg/lv-media
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 217569280 4k blocks and 54394880 inodes
Filesystem UUID: 352f91d5-202b-44ba-a26a-a79d84e50d4d
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
Change a Logical Volume size
We want /pub to be smaller. First unmount it
BASH
sudo umount /pub
Check partition health with
BASH
sudo fsck -t ext4 -f /dev/ubuntu-vg/lv-pub
If the system asks to create /lost+found, answer y
Shrink the filesystem to a specific size
BASH
sudo resize2fs -p /dev/ubuntu-vg/lv-pub 512G
resize2fs 1.47.0 (5-Feb-2023) Resizing the filesystem on /dev/ubuntu-vg/lv-pub to 134217728 (4k) blocks. Begin pass 2 (max = 233606) Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 3 (max = 7200) Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 4 (max = 10155) Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX The filesystem on /dev/ubuntu-vg/lv-pub is now 134217728 (4k) blocks long.
Shrink the Logical Volume
BASH
sudo lvresize -L 512G ubuntu-vg/lv-pub
WARNING: Reducing active logical volume to 512.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce ubuntu-vg/lv-pub? [y/n]: y Size of logical volume ubuntu-vg/lv-pub changed from 900.00 GiB (230400 extents) to 512.00 GiB (131072 extents). Logical volume ubuntu-vg/lv-pub successfully resized.
Check partition health again, then re-mount the drive
BASH
sudo fsck -t ext4 -f /dev/ubuntu-vg/lv-pub
sudo mount /dev/ubuntu-vg/lv-pub /pub
Reload systemd
BASH
sudo systemctl daemon-reload
Delete a Logical Volume
We want to delete /pub. First unmount it
BASH
sudo umount /pub
Then remove it
BASH
sudo lvremove ubuntu-vg/lv-pub