5.创建逻辑卷快照
[root@localhost ~]# cp -a /etc/passwd /etc/shadow /mnt/sdb/
[root@localhost ~]# ll /mnt/sdb/
total 142
drwxr-xr-x. 2 root root 1024 Jan 9 15:24 12
drwx------. 2 root root 12288 Jan 9 15:23 lost+found
-rw-------. 1 root root 125811 Feb 22 2013 moduli
-rw-r--r--. 1 root root 953 Jan 9 13:09 passwd
----------. 1 root root 627 Jan 9 13:09 shadow
[root@localhost ~]# lvcreate -s -L 50M -n sanp /dev/vg0/test --创建50M的逻辑快照
Rounding up size to full physical extent 52.00 MiB
Logical volume "sanp" created
[root@localhost ~]# mkdir /mnt/sdb2
[root@localhost ~]# mount /dev/vg0/sanp /mnt/sdb2/ --挂载快照
[root@localhost ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
ext4 6.9G 6.4G 171M 98% /
tmpfs tmpfs 262M 0 262M 0% /dev/shm
/dev/sda1 ext4 508M 48M 435M 10% /boot
/dev/mapper/vg0-test
ext4 102M 6.0M 91M 7% /mnt/sdb --逻辑卷大小
/dev/mapper/vg0-sanp
ext4 102M 6.0M 91M 7% /mnt/sdb2 --快照大小
[root@localhost ~]# ll /mnt/sdb2/
total 142
drwxr-xr-x. 2 root root 1024 Jan 9 15:24 12
drwx------. 2 root root 12288 Jan 9 15:23 lost+found
-rw-------. 1 root root 125811 Feb 22 2013 moduli
-rw-r--r--. 1 root root 953 Jan 9 13:09 passwd
----------. 1 root root 627 Jan 9 13:09 shadow
[root@localhost ~]#
6.删除卷组(vg),删除物理卷(pv),删除逻辑卷(lv)
[root@localhost ~]# lvscan --查看逻辑卷
ACTIVE Original '/dev/vg0/test' [100.00 MiB] inherit
ACTIVE '/dev/vg0/test1' [152.00 MiB] inherit
ACTIVE Snapshot '/dev/vg0/sanp' [52.00 MiB] inherit
ACTIVE Snapshot '/dev/vg0/sanp1' [52.00 MiB] inherit
ACTIVE '/dev/VolGroup/lv_root' [6.51 GiB] inherit
ACTIVE '/dev/VolGroup/lv_swap' [1.00 GiB] inherit
[root@localhost ~]# lvremove /dev/vg0/test --移除逻辑卷(必须卸载所有目录)
Do you really want to remove active logical volume sanp? [y/n]: y --输入y确认
Logical volume "sanp" successfully removed
Do you really want to remove active logical volume sanp1? [y/n]: y --输入y确认
Logical volume "sanp1" successfully removed
Do you really want to remove active logical volume test? [y/n]: y --输入y确认
Logical volume "test" successfully removed
[root@localhost ~]# vgscan --查看卷组(vg)
Reading all physical volumes. This may take a while...
Found volume group "vg0" using metadata type lvm2
Found volume group "VolGroup" using metadata type lvm2
[root@localhost ~]# vgremove vg0 --移除卷组(vg)
Do you really want to remove volume group "vg0" containing 1 logical volumes? [y/n]: y --输入y确认
Do you really want to remove active logical volume test1? [y/n]: y --输入y确认
Logical volume "test1" successfully removed
Volume group "vg0" successfully removed
[root@localhost ~]# pvscan
PV /dev/sda2 VG VolGroup lvm2 [7.51 GiB / 0 free]
PV /dev/sdb1 lvm2 [200.00 MiB]
PV /dev/sdb2 lvm2 [200.00 MiB]
PV /dev/sdb3 lvm2 [200.00 MiB]
PV /dev/sdb4 lvm2 [200.00 MiB]
Total: 5 [8.29 GiB] / in use: 1 [7.51 GiB] / in no VG: 4 [800.00 MiB]
[root@localhost ~]# pvremove /dev/sdb{1,2,3,4} --移除物理卷
Labels on physical volume "/dev/sdb1" successfully wiped
Labels on physical volume "/dev/sdb2" successfully wiped
Labels on physical volume "/dev/sdb3" successfully wiped
Labels on physical volume "/dev/sdb4" successfully wiped
[root@localhost ~]#
7.在lvm逻辑卷中常用的命令
pvcreate --建物理分区建成pv
pvscan --显示具有pv的磁盘
pvdisplay --列出系统上的pv
pvremove --删除pv属性
vgcreate --创建vg命令
vgscan --查找系统中是否有vg存在
vgdisplay --目前系统vg的状态
vgextend --在vg中增加pv
vgremove --删除一个vg
vgchange --设置vg是否启动
vgreduce --在vg中删除pv
lvcreate --创建lv
lvscan --查询系统上的lv
lvdisplay --显示系统上的lv状态
lvextend --在lv中增加容量
lvreduce --在lv中减少容量
lvremove --删除lv
lvresize --对lv的容量进行调整