# lvcreate -L *[nMgGtT] –p r –s –n snapshot_lv_name original_lv_name
-L *[nMgGtT] :创建大小
–p r:只读权限
–s:建立快照
–n snapshot_lv_name:指明快照卷名字
original_lv_name:原卷名称
快照
[root@sctest ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda6 vg1 lvm2 a--u 5.01g 2.01g
/dev/sda7 vg1 lvm2 a--u 8.00g 8.00g
/dev/sda8 vg1 lvm2 a--u 10.00g 10.00g
/dev/sda9 vg1 lvm2 a--u 20.01g 20.01g
[root@sctest ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 4 1 0 wz--n- 43.02g 40.02g
[root@sctest ~]# lvc
lvchange lvconvert lvcreate
在vg1上新建快照逻辑分区lv1_snap
[root@sctest ~]# lvcreate -L 512M -s -p r -n lv1_snap /dev/vg1/lv1
Logical volume "lv1_snap" created.
将新建快照挂载
[root@sctest ~]# mount /dev/vg1/lv1_snap /mnt
mount: block device /dev/mapper/vg1-lv1_snap is write-protected, mounting read-only
更改源文件后,查看快照文件内容为旧文件
[root@sctest mnt]# vim /test1/issue
[root@sctest mnt]# cat /test1/issue
Red Hat Enterprise Linux Server release 6.9 (Santiago)
Kernel \r on an \m
test build new line
[root@sctest mnt]# cat issue
Red Hat Enterprise Linux Server release 6.9 (Santiago)
Kernel \r on an \m
复制新文件到源文件后,快照中无此新文件
[root@sctest mnt]# cp /etc/rc.d/init.d/functions /test1/
[root@sctest mnt]# cd /test1/
[root@sctest test1]# ls
functions grub.conf issue lost+found
[root@sctest test1]# cd /mnt
[root@sctest mnt]# ls
grub.conf issue lost+found
复制还原文件
[root@sctest test1]# cp -ra /mnt /test1/
cp:是否覆盖"/test1/mnt/issue"? y
cp:是否覆盖"/test1/mnt/grub.conf"? y
[root@sctest test1]# ls /test1/
functions grub.conf issue lost+found mnt
卸载
[root@sctest test1]# umount /mnt
删除快照
[root@sctest test1]# lvremove /dev/vg1/lv1_snap
Do you really want to remove active logical volume lv1_snap? [y/n]: y
Logical volume "lv1_snap" successfully removed
[root@sctest test1]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-ao---- 3.00g
(之前VG挂载在/test1)卸载
[root@sctest 桌面]# umount /test1/
umount: /test1: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
查看占用
[root@sctest 桌面]# fuser -mu /test1/
/test1/: 4631c(root)
[root@sctest 桌面]# ps xa | grep 4631
4631 pts/0 Ss+ 0:00 /bin/bash
30560 pts/1 S+ 0:00 grep 4631
[root@sctest 桌面]# tty
/dev/pts/1
解除占用后卸载成功
[root@sctest 桌面]# umount /test1/
[root@sctest 桌面]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 3.00g
LV,VG,PV全部删除
[root@sctest 桌面]# lvremove /dev/vg1/lv1
Do you really want to remove active logical volume lv1? [y/n]: y
Logical volume "lv1" successfully removed
[root@sctest 桌面]# lvs
[root@sctest 桌面]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 4 0 0 wz--n- 43.02g 43.02g
[root@sctest 桌面]# vgremove vg1
Volume group "vg1" successfully removed
[root@sctest 桌面]# vgs
[root@sctest 桌面]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda6 lvm2 ---- 5.01g 5.01g
/dev/sda7 lvm2 ---- 8.01g 8.01g
/dev/sda8 lvm2 ---- 10.00g 10.00g
/dev/sda9 lvm2 ---- 20.01g 20.01g
[root@sctest 桌面]# pvremove /dev/sda6
Labels on physical volume "/dev/sda6" successfully wiped
[root@sctest 桌面]# pvremove /dev/sda7
Labels on physical volume "/dev/sda7" successfully wiped
[root@sctest 桌面]# pvremove /dev/sda8
Labels on physical volume "/dev/sda8" successfully wiped
[root@sctest 桌面]# pvremove /dev/sda9
Labels on physical volume "/dev/sda9" successfully wiped
[root@sctest 桌面]# pvs
[root@sctest 桌面]#