See https://www.thomas-krenn.com/de/wiki/LVM_Grundlagen for the core concepts regarding physical volumes (pv), volume groups (vg) and logival volumes (lv).
Show drives, their sizes and their partitions in the boot log: dmesg | grep sd
(or nvme
on bare-metal; unlikely in virtualized environments)
List a block device tree. Shows in which partition a volume group was placed: lsblk
Grow the third partition to the maximum (if there is empty space afterwards). You may need to reboot afterwards: growpart --verbose /dev/sda 3
pvs
,pvdisplay
,pvscan
vgs
,vgdisplay
,vgscan
lvs
,lvdisplay
,lvscan
- Use the long form of arguments
lvcreate --size
instead oflvcreate -L
. They describe what they do and yout do not have to look them up in the man page.
When you enlarged a partition (e.g. using the growpart
command above), you still have to use pvresize /dev/sda3
to enlarge the physical volume.
- Show current size of the logical volumes:
lvs
/lvscan --verbose
- Resize the "partition" by 120GB:
lvextend --size +120G /dev/vg0/var
or - Resize the "partition" to 700GB:
lvextend --size 700G /dev/vg0/var
- Resize the file system:
resize2fs /dev/vg0/var
(lvextend --resizefs
might do the same for you) - Show the current size of logical volumes:
lvs
/lvscan --verbose
- Show the current size of file systems:
df -h
Ressources:
- https://www.thomas-krenn.com/de/wiki/LVM_Snapshots
- https://devconnected.com/lvm-snapshots-backup-and-restore-on-linux/
- https://www.silvesterlangen.de/?Linux___LVM___LVM_Backup_%26amp%3B_Restore
Information:
- Snapshots are copy-on-write (COW). Although the space is allocated beforehand, actual data is only written if it's changed on the underlying logical volume. This means you can use little space for a snapshot of a logical volume which does not change very much - but if it does change too much, your snapshot will break if it needed more space than available. (Also, I guess you cannot just use the "Used" size from
df -h
, because on the blockdevice, changes yould be made all over the whole space). - Snapshots are NOT read-only! In doubt, use
mount -o ro
to prevent you from destroying your snapshot.
- Create a snapshot for the logical volume
/dev/vg0/root
with 10GB size:lvcreate --size 10G --snapshot --name root_snap /dev/vg0/root
. - Display it:
lvs
,lvdisplay
,lvscan
- Mount snapshot:
mount /dev/vg0/root_snap /mnt/root_snap/
(CAUTION: They are NOT read-only!) - Remove a snapshot:
lvremove /dev/vg0/root_snap
The snapshot of the root filesystem can probably (did not test it yet) be restored on the next reboot:
- https://www.thegeekdiary.com/how-to-create-an-lvm-snapshot-of-the-root-filesystem-and-restore-to-an-earlier-state/
- https://wiki.archlinux.org/title/Create_root_filesystem_snapshots_with_LVM#Revert_updates
- See https://github.com/mpalmer/lvmsync to efficiently sync (the underlying logical volume, not the snapshot!) across a network. (The snapshot is used to determine which blocks changed in the underlying logical volume and have to be considered.)