Logical Volume Management
Jump to navigation
Jump to search
Logical Volume Management (LVM)
1 Initial partitioning by clean CentOS installation
Automatic partitioning of 120-GiB SSD by clean CentOS-8.1 installation as follows
- /dev/sda1 1 GiB ext4 /boot
- /dev/sda2 118 GiB lvm2_pv cl (cl: volume group name)
- /dev/mapper/cl-swap 8 GiB swap
- /dev/mapper/cl-root 50 GiB XFS /
- /dev/mapper/cl-home 60 GiB XFS /home
Basic commands to display LVM information
- vgdisplay will display volume group information
- pvdisplay will display physical volume information
- lvdisplay will display logical volume information
2 Custom partitioning
2.1 Objective
- /boot (unchanged)
- swap (unchanged)
- / (unchanged)
- /home (XFS reduced to 20 GiB)
- /data1 (new 20 GiB ext4)
- /data2 (new 20 GiB ext4)
XFS doesn't support partition shrinking (scale-down), so the logical volume hosting /home needs first to be deleted and re-created with the scaled-down size.
2.2 How to
- Backup /home
- xfsdump -l 0 -f /var/tmp/home.backup /home
- label? dump-1 (name doesn't matter)
- label? dump-2 (name doesn't matter)
- xfsdump -l 0 -f /var/tmp/home.backup /home
- Reset /home
- umount /home
- lvremove /dev/mapper/cl-home
- lvcreate -L 20G --name home cl
- mkfs.xfs /dev/mapper/cl-home
- mount /home
- xfsrestore -f /var/tmp/home.backup /home
- rm /var/tmp/home.backup
- Create /data1 and /data2 filesystems
- lvcreate --name data1 -L 20G cl
- lvcreate --name data2 -l 100%FREE cl
- mkfs.ext4 /dev/mapper/cl-data1
- mkfs.ext4 /dev/mapper/cl-data2
- mkdir /data1 /data2
- edit /etc/fstab
- /dev/mapper/cl-data1 /data1 ext4 defaults 0 0
- /dev/mapper/cl-data2 /data2 ext4 defaults 0 0
- mount -a
- Create /data{1|2}/tmp directory accessible to everyone
- mkdir /data1/tmp /data2/tmp
- chmod a+trwx /data1/tmp /data2/tmp (only user - or root - can remove files)