1, Logical volume
1. Definition
- Solve the problem of insufficient partition space or more than enough partition space
pv | Physical volume (processed physical partition) |
pe | Physical expansion (setting the minimum storage unit) |
vg | Physical volume group (bundled pv into a group) |
lv | Logical volume (allocates end use devices) |
When the storage of the logical volume is insufficient, the space will be obtained from the physical volume group. If the storage of the physical volume group is also insufficient, the new physical partition will also be processed as a physical volume and added to the physical volume group.
2. The establishment of lvm
(1) Monitoring the establishment process
watch -n 1 "pvs;echo ===;vgs;echo ===;lvs;echo ===;df -h /sk"
(2) Establish physical partition and set the partition type as lvm
fdisk /dev/vdb
- Refer to the specific meaning of the command—— 6, swap partition
(2) Create pv, vg and lvm
pvcreate /dev/vdb1 ##Create pv vgcreate sk_vg -s 2M /dev/vdb1 ##Create a vg named sk_vg, - s set pe size to 2M lvcreate -L 100M -n sk_lv sk_vg ##Create lvm -L specify size - n specify name lvcreate -l 100 -n sk_lv2 sk_vg ##Create lvm -l specify the number of pe blocks - n specify the name pvdisplay /dev/vdb1 ##View the details of pv vgdisplay sk_vg ##View details of vg lvdisplay /dev/sk_vg/sk_lv ##View the details of lv lvdisplay /dev/sk_vg/sk_lv2
(3) Format and mount
mkfs.xfs /dev/mapper/sk_vg-sk_lv ##format mount /dev/sk_vg/sk_lv /sk ##mount
3. lvm stretching
1. When the capacity in vg is sufficient
Step by step operation:
lvextend -L 200M /dev/sk_vg/sk_lv ##Stretching equipment xfs_growfs /sk ##Stretch file system, rhel7 can use device or mount point, rhel8 can only use mount point
One step operation:
lvextend -r -L 500M /dev/sk_vg/sk_lv ##Stretching equipment and file system
2. When the capacity in vg is not enough
Add a new partition first (refer to create / dev/vdb1)
Then create a new pv, add it to the previous vg, and stretch it
pvcreate /dev/vdb2 ##Create pv vgextend sk_vg /dev/vdb2 ##Add new pv to vg lvextend -r -L 1.5G /dev/sk_vg/sk_lv ##Stretching equipment and file system
3. ext file system
lvextend -L 200M /dev/sk_vg/sk_lv ##Stretching equipment resize2fs /dev/mapper/sk_vg-sk_lv 200M ##Stretch file system
4. lvm reduction
- xfs file system does not support reduction, ext file system can
(1) Converting xfs file to ext file system
umount /sk ##Unload the original mount point first mkfs.ext4 /dev/sk_vg/sk_lv ##Convert file system to ext4 mount /dev/sk_vg/sk_lv /sk ##Remount
(2) Downsizing
umount /sk ##uninstall e2fsck -f /dev/sk_vg/sk_lv ##Test data resize2fs /dev/sk_vg/sk_lv 100M ##Reducing the file system lvreduce -L 100M /dev/sk_vg/sk_lv ##Downsizing equipment
5. lvm delete
umount /dev/sk ##uninstall lvremove /dev/sk_vg/sk_lv ##Delete lv vgremove sk_vg ##Delete vg pvremove /dev/vdb1 ##Delete pv
Experiment: move the data in / dev/vdb1 to / dev/vdb2, delete pv in / dev/vdb1
pvmove /dev/vdb1 /dev/vdb2 ##mobile data vgreduce sk_vg /dev/vdb1 ##Remove / dev/vdb1 from vg pvremove /dev/vdb1 ##Delete pv lvremove /dev/sk_vg/sk_lv2 ##Delete lv (extra operation)
6. lvm snapshot
- To protect the original files and devices from damage is equivalent to device reset
-50: Device data size to be changed, - n: name, - s: snapshot object
lvcreate -L 50M -n sk_lv-backup -s /dev/sk_vg/sk_lv
experiment:
Create a file in the snapshot object, create a snapshot, delete the previously established file, delete the snapshot, re create the snapshot, and observe whether the file can be recovered
mount /dev/sk_vg/sk_lv /sk ##Mount snapshot object touch /sk/file{1..5} ##create file umount /sk ##uninstall lvcreate -L 50M -n sk_lv-backup -s /dev/sk_vg/sk_lv ##Create Snapshot mount /dev/sk_vg/sk_lv-backup /sk ##Mount snapshot rm -fr /sk/* ##Delete build file umount /sk ##uninstall lvremove /dev/sk_vg/sk_lv-backup ##Delete snapshot lvcreate -L 50M -n sk_lv-backup2 -s /dev/sk_vg/sk_lv ##Create a snapshot again mount /dev/sk_vg/sk_lv-backup2 /sk ##Reload snapshot ls /sk ##Observed file recovery
View snapshot details:
lvdisplay /dev/sk_vg/sk_lv-backup2
2, vdo
- vdo (Virtual Data Optimize) virtual data optimizer
- kvdo -- compressed data
- uds -- optimizing duplicate data
1. Establishment of vdo
dnf install vdo -y ##Download vdo, the general system will bring vdo create --name sk_vdo --device /dev/vdb ##Establish vdo vdo status --name sk_vdo | grep Deduplication ##Check whether vdo can detect and delete duplicate data vdo status --name sk_vdo | grep Compression ##Check whether the vdo data compression function is on vdo enableCompression --name sk_vdo ##
How to enable the functions of compressing data and detecting and deleting duplicate data:
vdo enableCompression --name sk_vdo ##Enable the function of detecting and deleting duplicate data vdo enableDeduplication --name sk_vdo ##Enable data compression function
2. Using vdo devices
mkfs.xfs -K /dev/mapper/sk_vdo ##format mount /dev/mapper/sk_vdo /sk ##Mount vdo device
3. Test vdo performance
vdostats --human-readable ##View vdo device usage
Experiment: copy a large file in the mount point many times, observe the usage of vdo device
cp /run/media/root/RHEL-8-2-0-BaseOS-x86_64/images/install.img /sk ##Copy large files
4. Permanent mount of vdo
vim /etc/fstab mount -a ##Read / etc/fstab now
5. Deletion of vdo
umount /dev/mapper/sk_vdo ##uninstall vim /etc/fstab ##Delete mount line vdo remove --name sk_vdo ##Delete vdo