Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Vaardigheden in dit hoofdstuk
- Logische volumes maken en vergroten
Know the three layers
Physical volumes (PV, disks or partitions) go into a volume group (VG, the pool). From the VG you make logical volumes (LV) that carry file systems or swap.
/dev/vdb1 /dev/vdc ← physical volumes (PV)
└──────┬──────┘
vg_data ← volume group (VG): one pool, split into extents (4 MiB)
┌──────┴──────┐
lv_web lv_db ← logical volumes (LV): /dev/vg_data/lv_web …
(xfs) (ext4) ← file systems, mounted like any partition| Word | Meaning |
|---|---|
| Physical extent (PE) | The block size of the VG, 4 MiB by default. LV sizes are a number of extents. |
/dev/VG/LV | The path of a logical volume (also /dev/mapper/VG-LV) |
Create physical volumes and a volume group
pvcreate marks a disk or partition for LVM. vgcreate makes the pool from one or more PVs.
parted /dev/vdb mklabel gpt mkpart lvm1 1MiB 100% set 1 lvm on
pvcreate /dev/vdb1 /dev/vdc
Physical volume "/dev/vdb1" successfully created.
Physical volume "/dev/vdc" successfully created.
vgcreate vg_data /dev/vdb1 /dev/vdc
vgcreate -s 8M vg_big /dev/vdd
pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 rhel lvm2 a-- 19.00g 0
/dev/vdb1 vg_data lvm2 a-- <5.00g <5.00g
/dev/vdc vg_data lvm2 a-- <5.00g <5.00g
vgs
vgdisplay vg_data-s 8M sets the extent size to 8 MiB (it can not change later).
Create logical volumes
lvcreate cuts an LV out of the VG: by size (-L) or by number of extents (-l). Then make a file system and mount it like a partition.
lvcreate -n lv_web -L 2G vg_data
Logical volume "lv_web" created.
lvcreate -n lv_db -l 250 vg_data
lvcreate -n lv_logs -l 50%FREE vg_data
lvcreate -n lv_rest -l 100%FREE vg_data
lvs
LV VG Attr LSize
lv_db vg_data -wi-a----- 1000.00m
lv_web vg_data -wi-a----- 2.00g
mkfs.xfs /dev/vg_data/lv_web
mkfs.ext4 /dev/vg_data/lv_db
mkdir -p /srv/web /srv/db
echo '/dev/vg_data/lv_web /srv/web xfs defaults 0 0' >> /etc/fstab
echo '/dev/vg_data/lv_db /srv/db ext4 defaults 0 0' >> /etc/fstab
systemctl daemon-reload
mount -aExamentip
"An LV of 250 extents with an extent size of 8 MiB" means vgcreate -s 8M and lvcreate -l 250. Read the task for both numbers.
Grow a volume group
When the VG is full, add a new disk with vgextend. Remove a PV with pvmove (move its data away) and vgreduce.
Grow a logical volume and its file system
lvextend -r makes the LV bigger and grows the file system in one step, while it is mounted.
lvextend -r -L +1G /dev/vg_data/lv_web
Size of logical volume vg_data/lv_web changed from 2.00 GiB to 3.00 GiB.
Logical volume vg_data/lv_web successfully resized.
meta-data=/dev/mapper/vg_data-lv_web isize=512 agcount=6, agsize=131072 blks
data blocks changed from 524288 to 786432
lvextend -r -l +100%FREE /dev/vg_data/lv_db
lvextend -r -L 5G /dev/vg_data/lv_web
df -h /srv/web| Form | Meaning |
|---|---|
-L +1G | 1 GiB more |
-L 5G | Make it 5 GiB in total |
-l +100%FREE | All free space of the VG |
-r | Also resize the file system (xfs_growfs or resize2fs) |
Onthoud
Without -r, the LV grows but the file system does not — df shows the old size. Then run xfs_growfs /srv/web (XFS) or resize2fs /dev/vg_data/lv_db (ext4).
Make a logical volume smaller
Only ext4 can shrink, and it must be unmounted. XFS can not shrink: back up, make a new smaller LV, restore.
Use an LV as swap
Swap on LVM can grow later, like any LV.
Remove LVM storage
Remove in the opposite order: unmount, LV, VG, PV — and remove the fstab line.