Chapter 18: Logical volume management
Exercise: LVM review
Build a small storage system with LVM on serverb: a volume group with a custom extent size, three logical volumes, a second disk added when the group runs out of room, an online extension of a mounted volume, and permanent mounts.
LVM review
- Build PV, VG and LVs with a chosen extent size.
- Add a PV when the group is full and extend a mounted volume.
- Make mounts and swap permanent.
Before you start: reset the servers and complete this chapter's lessons. You work on serverb as root (sudo -i), on the spare disk /dev/sdb; lab start and lab grade run on workstation.
On serverb:
- Create two LVM partitions of 1.5 GiB on
/dev/sdb. - Create the volume group
vgappon the first one with 8 MiB extents. - Create
lvweb(1 GiB, XFS,/srv/web),lvdb(400 MiB, ext4,/srv/db) andlvswap(256 MiB, swap). When the group is full, add the second partition. - Write
seq 1 100000into/srv/web/numbers.txt, then extendlvwebto at least 2000 MiB while it is mounted. - Make everything permanent in
/etc/fstaband test it. - On workstation, fill in
answers.txt.
Start the exercise
[student@workstation ~]$ lab start sa-lvm-review
[student@workstation ~]$ ssh student@serverb
[student@serverb ~]$ sudo -i
[root@serverb ~]#Partitions, group and the first volumes
[root@serverb ~]# parted -s /dev/sdb mklabel gpt mkpart pv1 1MiB 1537MiB mkpart pv2 1537MiB 3073MiB set 1 lvm on set 2 lvm on
[root@serverb ~]# udevadm settle
[root@serverb ~]# pvcreate /dev/sdb1
[root@serverb ~]# vgcreate -s 8M vgapp /dev/sdb1
[root@serverb ~]# lvcreate -n lvweb -L 1G vgapp
[root@serverb ~]# lvcreate -n lvdb -L 400M vgapp
[root@serverb ~]# lvcreate -n lvswap -L 256M vgapp
Volume group "vgapp" has insufficient free space (13 extents): 32 required.
[root@serverb ~]# pvcreate /dev/sdb2; vgextend vgapp /dev/sdb2
[root@serverb ~]# lvcreate -n lvswap -L 256M vgapp
Logical volume "lvswap" created.
[root@serverb ~]# vgs -o vg_name,pv_count,vg_extent_size,vg_size,vg_free vgapp
VG #PV Ext VSize VFree
vgapp 2 8.00m 2.98g 1.34gWith 8 MiB extents, 256 MiB needs 32 extents and the group had only 13 left, hence the message.
File systems, data and the online extension
[root@serverb ~]# mkfs.xfs /dev/vgapp/lvweb > /dev/null
[root@serverb ~]# mkfs.ext4 /dev/vgapp/lvdb > /dev/null 2>&1
[root@serverb ~]# mkswap /dev/vgapp/lvswap
[root@serverb ~]# mkdir -p /srv/web /srv/db
[root@serverb ~]# mount /dev/vgapp/lvweb /srv/web; mount /dev/vgapp/lvdb /srv/db
[root@serverb ~]# seq 1 100000 > /srv/web/numbers.txt
[root@serverb ~]# lvextend -r -L 2G /dev/vgapp/lvweb
Extended file system xfs on vgapp/lvweb.
Logical volume vgapp/lvweb successfully resized.
[root@serverb ~]# df -h /srv/web | tail -1; tail -1 /srv/web/numbers.txt
/dev/mapper/vgapp-lvweb 2.0G 51M 1.9G 3% /srv/web
100000Permanent, and test
[root@serverb ~]# cp /etc/fstab /root/fstab.bak
[root@serverb ~]# cat >> /etc/fstab <<'EOT'
/dev/vgapp/lvweb /srv/web xfs defaults 0 0
/dev/vgapp/lvdb /srv/db ext4 defaults 0 0
/dev/vgapp/lvswap none swap defaults 0 0
EOT
[root@serverb ~]# systemctl daemon-reload; findmnt --verify | tail -1
0 parse errors, 0 errors, 1 warning
[root@serverb ~]# mount -a && swapon -a; df -hT /srv/web /srv/db | tail -2; swapon --showA reboot (systemctl reboot) is the final proof. Afterwards check vgs, lvs and the mounts again.
Grade
On workstation, fill in answers.txt and grade:
Check your work with lab grade sa-lvm-review, then put the exercise away with lab finish sa-lvm-review.