LVM
Logical Volume Management
See also
- OpenZFS (Volume Manager + File System)
Config file
/etc/lvm/lvm.conf
Abbreviation | Name |
---|---|
PV | Physical Volume |
VG | Volume Group |
LV | Logical Volume |
Scan for all available devices for LVM
lvmdiskscan
pvscan
Change partition type ID to LVM
Optional
gdisk <device>
Command (? for help): t
Partition number (1-X): <partition>
Hex code or GUID (L to show codes, Enter = 8300): 8e00
Command (? for help): w
fdisk <device>
Command (m for help): t
Partition type (type L to list all types): L
Partition type (type L to list all types): <Linux LVM type ID>
Command (m for help): w
PV (Physical Volume)
Create PV
# <device> = <disk> | <partition>
pvcreate <device>[ ...]
Remove PV
vgreduce <VG> <PV>
pvremove <PV>
Show PV information
pvs
pvdisplay
Resize PV
pvs
will auto detect available space and extend the PV
# pvs <pv> [--setphysicalvolumesize <size>]
pvs /dev/sda1
# or specify size 1T
pvs /dev/sda1 --setphysicalvolumesize 1T
VG (Volume Group)
Create VG
vgcreate <VG name> <PV> ...
Add PV to VG
vgextend <VG name> <PV> ...
Remove VG
vgremove <VG name>
Show VG information
vgs
vgdisplay
LV (Logical Volume)
Create LV
lvcreate
[
-L <size>[K|M|G|T|P|E] |
-l <percent>[%{VG|FREE}]
]
-–type { linear | raid1 | raid5 | raid6 }
-n <LV name>
<VG name>
Show LV information
lvs
lvdisplay
Remove LV
lvremove <LV>
Resize LV
lvresize
{
{ -L | --size } {+|-}<size>[K|M|G|T|P|E] |
{ -l | --extends } {+|-}<percent>[%{VG|FREE}]
}
# Auto resize2fs
[ -r | --resizefs ]
<LV>
Unmount LV (Optional)
umount <LV>
Resize LV to use all free space
# lvresize -l +100%FREE -r <LV>
lvresize -l +100%FREE -r /dev/ubuntu-vg/ubuntu-lv
--resizefs
is similar to do the following
-
Check file system
fsck -f <LV>
-
Resize file system
resize2fs <LV> <size>[s|K|M|G]
Troubleshooting
Device <device>
excluded by a filter
pvcreate -vvv <device> |& grep <device>
Skipping: Partition table signature found
# Wipe all magic strings (BE CAREFUL!)
wipefs --all <device>