1. Create 5 partitions
/**
I * Since there is no free disk space left on the machine, we have to delete swap to make space
*/
1. Delete swap first swapoff /dev/sdax
2. Modify the boot hang Load the file /etc / fstab Delete the swap
line and save it Command to update the partition table 2. PV (physical volume) stage to check whether there is pv pvscan to create a new /dev/sda5-8 four partitions for pv pvcreate /dev/sda{5,6,7,8} to view the newly created pv pvscan lists the pv information on the system in more detail pvdisplay 3. VG (volume user group) stage will create a new partition for /dev/sda{5,6,7,8}
vgcreate -s 16M jisonvg /dev/sda{5,6,7,8}
-s followed by the size of PE (physical extension block)
Check the vg of the machine
vgscan
check the pv of the machine again
pvscan
list the system in more detail vg information
vgdisplay
4. LV (logical volume) phase
Allocate the entire jisonvg to jisonlv
lvcreate -l 72 -n jisonlv jisonvg
-L followed by the capacity, which can be M, G, T
-l followed by the number of PEs
-n The name of the LV is followed by a
more detailed listing of the lv information on the system .
lvdisplay 5. The file system for formatting jisonlv in the file
system phase is ext3 mkfs -t ext3 /dev/jisonvg/jisonlv Mount jisonlv to mkdir on /mnt/lvm /mnt/lvm mount /dev/jisonvg/jisonlv /mnt/lvm View mounted jisonlv df -h
Test using jisonlv
cp -r /etc /mnt/lvm
ll /mnt/lvm/etc
6. Enlarge the capacity of LV and
use the previously created pv (/dev/sda9) that was not added to jisonlv, and add it to jisonvg
vgextend jisonvg /dev/sda9
lists the vg information on the system in detail
vgdisplay
adjusts the size of jisonlv lvresize
-l +18 /dev/jisonvg/jisonlv
lists the lv information above the system in detail
lvdisplay
checks the record of the superblock in the original file system
dumpe2fs /dev /jisonvg/jisonlv
Completely expand the LV capacity to the entire file system
resize2fs /dev/jisonvg/jisonlv
Check the superblock records in the expanded file system
dumpe2fs /dev/jisonvg/jisonlv
Check the expanded file system
df -h / dev/jisonvg/jisonlv
7. Reduce the capacity of LV
First unmount /dev/jisonvg/jisonlv
umount /mnt/lvm
to check the disk
e2fsck -f /dev/jisonvg/jisonlv
Reduce the capacity of the file system
resize2fs /dev/jisonvg/jisonlv 300M
View the file system after the reduced capacity
mount /dev/jisonvg /jisonlv /mnt/lvm
df -h /mnt/lvm
Reduce the size of LV
lvresize -l -18 /dev/jisonvg/jisonlv
Move unused PEs to /dev/sda6
pvdisplay
pvmove /dev/sda6 /dev/sda9
move /dev/sda6 out of jisonvg
vgreduce jisonvg /dev/sda6
delete pv (/dev/sda6) pvremove
/dev/sda6
8.LVM snapshot
Create a snapshot of /dev/jisonvg/jisonlv /dev/jisonvg/jisonss
pvcreate /dev /sda6
vgextend jisonvg /dev/sda6
vgdisplay
lvcreate -l 18 -s -n jisonss /dev/jisonvg/jisonlv
lvdisplay
mount /dev/jisonvg/jisonss
mkdir /mnt/snapshot
mount /dev/jisonvg/jisonss /mnt/snapshot
df -h
You will find that the usage and size of the snapshots /dev/jisonvg/jisonss and /dev/jisonvg/jisonlv are exactly the same, but in fact the snapshot area is not so big, the snapshot area only records the moment when the snapshot was created /dev/jisonvg The content of /jisonlv
After modifying /dev/jisonvg/jisonlv, the content of the snapshot area is still unchanged.
Use the snapshot area to restore the file system
umount /mnt/snapshot
df /mnt/lvm
rm -rf /mnt/lvm/etc
cp -r / boot /mnt/lvm
mount /dev/jisonvg/jisonss /mnt/snapshot
df -h
At this time, you will find that the usage and size of /dev/jisonvg/jisonlv and /dev/jisonvg/jisonlv are different, the content in the snapshot is still the original, and the content of /dev/jisonvg/jisonlv is after the modification
. To restore the content of /dev/jisonvg/jisonlv to the original content, after formatting /dev/jisonvg/jisonlv, copy the content of /dev/jisonvg/jisonss to /dev/jisonvg/jisonlv and
umount /dev /lvm
mkfs -t ext3 /dev/jisonvg/jisonlv
mount /dev/jisonvg/jisonlv /mnt/lvm
cp -r /mnt/snapshot/* /mnt/lvm
cd /mnt/lvm
ls
should be /dev/jisonvg/ The contents of jisonlv and snapshot /dev/jisonvg/jisonss are consistent again
9. Close LVM and restore the disk
Unmount
umount for swap /mnt/lvm
umount /mnt/snapshot
Process snapshot and original system
lvremove /dev/jisonvg/jisonss
lvremove /dev/ jisonvg/jisonlv
make jisonvg inactive
vgchange -an jisonvg
delete jisonvg
vgremove jisonvg
delete all pv pvremove
/dev/sda{5,6,7,8,9}
change /dev/sda{5,6,7,8,9 } Change the 8e flag of the partition back to 83, recreate the partition and format it as swap
fdisk /dev/sda
Use the t parameter to modify the id of the partition /dev/sda{5,6,7,8,9} to 83 and
delete it with the d parameter The /dev/sda{5,6,7,8,9} partition
uses the d parameter to delete the logical partition /dev/sda4
uses the n parameter to create a new partition as /dev/sda2
uses the w parameter to save the partition operation
Use the partprobe command Refresh the partition table
to format /dev/sda2 as swap partition
mkswap /dev/sda2
and
reboot
lvm application of centos7
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326677719&siteId=291194637
Recommended
Ranking