LVM 逻辑卷管理器-缩小LV容量
将/dev/sdb2分区抽离出来,缩小LV容量
(1)首先查看/dev/sdb2的容量大小
[root@centos6 ~]# df -h /mnt/lvm/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_1-lv_1 20G 170M 19G 1% /mnt/lvm [root@centos6 ~]# pvdisplay --- Physical volume --- PV Name /dev/sdb2 VG Name vg_1 PV Size 5.01 GiB / not usable 10.13 MiB Allocatable yes (but full) PE Size 16.00 MiB Total PE 320 Free PE 0 Allocated PE 320 PV UUID Mh3pG8-PHQG-Yexz-PYw0-Jtel-oBWb-lSBdG3 ...以下省略... #从这里可以看出/dev/sdb2容量是5G,有320个PE [root@centos6 ~]# pvscan PV /dev/sdb2 VG vg_1 lvm2 [5.00 GiB / 0 free] PV /dev/sdb3 VG vg_1 lvm2 [5.00 GiB / 0 free] PV /dev/sdb1 VG vg_1 lvm2 [5.00 GiB / 0 free] PV /dev/sdb5 VG vg_1 lvm2 [5.00 GiB / 0 free] Total: 4 [20.00 GiB] / in use: 4 [20.00 GiB] / in no VG: 0 [0 ]
(2)直接降低文件系统的容量
[root@centos6 ~]# resize2fs /dev/vg_1/lv_1 15000M resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vg_1/lv_1 is mounted on /mnt/lvm; on-line resizing required On-line shrinking from 5242880 to 3840000 not supported. [root@centos6 ~]# df -h /mnt/lvm/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_1-lv_1 20G 170M 19G 1% /mnt/lvm #查找文件系统变没有缩小,是因为增大LVM容量可以在线直接进行,缩小文件系统则无法支持,所以要先卸载/mnt/lvm,然后再缩小。 [root@centos6 ~]# umount /mnt/lvm/ [root@centos6 ~]# resize2fs /dev/vg_1/lv_1 15000M resize2fs 1.41.12 (17-May-2010) Please run 'e2fsck -f /dev/vg_1/lv_1' first. #系统让我们执行“e2fsck -f /dev/vg_1/lv_1”命令进行磁盘检查 [root@centos6 ~]# e2fsck -f /dev/vg_1/lv_1 e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vg_1/lv_1: 12/1310720 files (0.0% non-contiguous), 125586/5242880 blocks [root@centos6 ~]# resize2fs /dev/vg_1/lv_1 15000M #再执行一次resize2fs resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/vg_1/lv_1 to 3840000 (4k) blocks. The filesystem on /dev/vg_1/lv_1 is now 3840000 blocks long. [root@centos6 ~]# mount /dev/vg_1/lv_1 /mnt/lvm [root@centos6 ~]# df /mnt/lvm/ Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/vg_1-lv_1 15117312 169460 14183840 2% /mnt/lvm [root@centos6 ~]# df -h /mnt/lvm/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_1-lv_1 15G 166M 14G 2% /mnt/lvm #查看文件系统容量已经变成15G
(3)降低LV的容量,抽离/dev/sdb2,它有320个PE
[root@centos6 ~]# lvresize -l -320 /dev/vg_1/lv_1 WARNING: Reducing active and open logical volume to 15.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv_1? [y/n]: y Reducing logical volume lv_1 to 15.00 GiB Logical volume lv_1 successfully resized [root@centos6 ~]# lvdisplay --- Logical volume --- LV Path /dev/vg_1/lv_1 LV Name lv_1 VG Name vg_1 LV UUID n2bChT-rimu-eRDs-5onU-mgUF-ukuh-NqO7me LV Write Access read/write LV Creation host, time centos6.5, 2016-09-09 19:04:37 +0800 LV Status available # open 1 LV Size 15.00 GiB Current LE 960 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 #这样LV就成功缩小了,接下来就是将/dev/sdb2移出vg_1这个VG之外。
(4)先确认/dev/sdb2是否将PE都移除了;
[root@centos6 ~]# pvdisplay --- Physical volume --- PV Name /dev/sdb2 VG Name vg_1 PV Size 5.01 GiB / not usable 10.13 MiB Allocatable yes (but full) PE Size 16.00 MiB Total PE 320 Free PE 0 Allocated PE 320 PV UUID Mh3pG8-PHQG-Yexz-PYw0-Jtel-oBWb-lSBdG3 ...中间省略... --- Physical volume --- PV Name /dev/sdb5 VG Name vg_1 PV Size 5.01 GiB / not usable 10.10 MiB Allocatable yes PE Size 16.00 MiB Total PE 320 Free PE 320 Allocated PE 0 PV UUID dAooQM-wYka-uR1v-Hccl-7HH1-ljTB-Yhjaif #没有被使用的PE竟然在/dev/sdb5,此时得要搬移PE; [root@centos6 ~]# pvmove /dev/sdb2 /dev/sdb5 /dev/sdb2: Moved: 0.0% /dev/sdb2: Moved: 13.8% /dev/sdb2: Moved: 27.8% /dev/sdb2: Moved: 41.6% /dev/sdb2: Moved: 55.6% /dev/sdb2: Moved: 66.9% /dev/sdb2: Moved: 81.2% /dev/sdb2: Moved: 94.7% /dev/sdb2: Moved: 100.0% #pvmove 来源PV 目标PV,将/dev/sdb2内的PE通通移至/dev/sdb5; [root@centos6 ~]# vgreduce vg_1 /dev/sdb2 #将/dev/sdb2移出vg_1中; Removed "/dev/sdb2" from volume group "vg_1" [root@centos6 ~]# pvscan PV /dev/sdb3 VG vg_1 lvm2 [5.00 GiB / 0 free] PV /dev/sdb1 VG vg_1 lvm2 [5.00 GiB / 0 free] PV /dev/sdb5 VG vg_1 lvm2 [5.00 GiB / 0 free] PV /dev/sdb2 lvm2 [5.01 GiB] Total: 4 [20.01 GiB] / in use: 3 [15.00 GiB] / in no VG: 1 [5.01 GiB] [root@centos6 ~]# pvremove /dev/sdb2 #删除/dev/sdb2 PV Labels on physical volume "/dev/sdb2" successfully wiped [root@centos6 ~]# pvscan PV /dev/sdb3 VG vg_1 lvm2 [5.00 GiB / 0 free] PV /dev/sdb1 VG vg_1 lvm2 [5.00 GiB / 0 free] PV /dev/sdb5 VG vg_1 lvm2 [5.00 GiB / 0 free] Total: 3 [15.00 GiB] / in use: 3 [15.00 GiB] / in no VG: 0 [0 ] #这样文件系统以及实际的LV与VG通通变小了,而且/dev/sdb2已经可以拿出来进行其他用途了;
5、LVM快照区的建立
由于快照区与原本的 LV 共享很多PE区块,因此快照区与被快照的LV必项要在同一个VG上。但是我们刚刚将/dev/sdb2移除vg_1了,目前vg_1剩下的容量为0!因此,在里面我们得要再加入/dev/sdb2 到vg_1后,才能继续建立快照区。
(1)查看vg_1还剩下多少容量
[root@centos6 ~]# vgdisplay --- Volume group --- VG Name vg_1 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 31 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 3 Act PV 3 VG Size 15.00 GiB PE Size 16.00 MiB Total PE 960 Alloc PE / Size 960 / 15.00 GiB Free PE / Size 0 / 0 #没有多余的PE可用 VG UUID NpO8m2-s4rx-WOIA-SbCt-yqQV-MU1w-wru4cS
(2)将/dev/sdb2加入到vg_1中;
[root@centos6 ~]# pvcreate /dev/sdb2 Physical volume "/dev/sdb2" successfully created [root@centos6 ~]# vgextend vg_1 /dev/sdb2 Volume group "vg_1" successfully extended [root@centos6 ~]# vgdisplay --- Volume group --- VG Name vg_1 System ID Format lvm2 Metadata Areas 4 Metadata Sequence No 32 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 4 Act PV 4 VG Size 20.00 GiB PE Size 16.00 MiB Total PE 1280 Alloc PE / Size 960 / 15.00 GiB Free PE / Size 320 / 5.00 GiB #多出了320个PE可用 VG UUID NpO8m2-s4rx-WOIA-SbCt-yqQV-MU1w-wru4cS
(4)利用lvcreate建立系统快照区,取名snaps,且给予100PE
[root@centos6 ~]# lvcreate -l 100 -s -n snaps /dev/vg_1/lv_1 Logical volume "snaps" created # -s:选项代表是snapshot快照功能意思; # -n:选项后面接快照的名称; # /dev/vg_1/lv_1 则是被快照的LV完整的名称; # -l:选项则是接使用多少个PE来作为这个快照区使用; [root@centos6 ~]# lvdisplay --- Logical volume --- LV Path /dev/vg_1/lv_1 LV Name lv_1 VG Name vg_1 LV UUID n2bChT-rimu-eRDs-5onU-mgUF-ukuh-NqO7me LV Write Access read/write LV Creation host, time centos6.5, 2016-09-09 19:04:37 +0800 LV snapshot status source of snaps [active] LV Status available # open 1 LV Size 15.00 GiB Current LE 960 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/vg_1/snaps LV Name snaps VG Name vg_1 LV UUID aCR4bc-n5ib-3iPW-la18-bQZL-EdJS-8f7lZD LV Write Access read/write LV Creation host, time centos6.5, 2016-09-10 02:33:19 +0800 LV snapshot status active destination for lv_1 LV Status available # open 0 LV Size 15.00 GiB #被快照的原LV磁盘容量 Current LE 960 COW-table size 1.56 GiB #快照区的实际容量 COW-table LE 100 #快照区占用的PE数量 Allocated to snapshot 0.00% Snapshot chunk size 4.00 KiB Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 #这样/dev/vg_1/snaps快照区就被建立起来了!而且它的VG容量竟然与/dev/vg_1/lv_1容量相同,也就是说,如果挂载这个装置,看到的数量会跟原本/dev/vg_1/lv_1相同; [root@centos6 ~]# mkdir /mnt/snapshot [root@centos6 ~]# mount /dev/vg_1/snaps /mnt/snapshot/ [root@centos6 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 16G 1.5G 14G 11% / tmpfs 112M 0 112M 0% /dev/shm /dev/sda1 194M 29M 155M 16% /boot /dev/mapper/vg_1-lv_1 15G 166M 14G 2% /mnt/lvm /dev/mapper/vg_1-snaps 15G 166M 14G 2% /mnt/snapshot
原创文章,作者:zhuckee,如若转载,请注明出处:http://www.178linux.com/47592