Linux的LVM管理(二)–在线扩容(On-line Extend)
上接Linux的LVM管理(一)—基本知识和创建 ,VG情况如下
[root@dbabc.net /]# vgscan -v Wiping cache of LVM-capable devices Wiping internal VG cache Reading all physical volumes. This may take a while... Finding all volume groups Finding volume group "vg01" Found volume group "vg01" using metadata type lvm2 Finding volume group "vg00" Found volume group "vg00" using metadata type lvm2
先制作一个vg01下的lvol2空间用完的场景,使/test03使用率达到100%:
[root@dbabc.net ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg00-lv_root 6.0G 396M 5.3G 7% / /dev/mapper/vg00-lv_usr 6.8G 1.7G 4.8G 26% /usr /dev/mapper/vg00-lv_data 93M 5.6M 83M 7% /data /dev/sdc1 988M 24M 914M 3% /boot /dev/mapper/vg01-lvol0 4.0G 137M 3.7G 4% /test01 /dev/mapper/vg01-lvol1 1.9G 35M 1.7G 2% /test02 /dev/mapper/vg01-lvol2 109M 109M 0 100% /test03
硬盘情况同上一篇一样,只是剩余sdg未使用,此处用fdisk查看,做pv的硬盘因为并不是直接往单个硬盘里写数据,所以并不会显示使用情况。
[root@dbabc.net ~]# fdisk -l Disk /dev/sda: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 1044 8385898+ 8e Linux LVM Disk /dev/sdb: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 * 1 1044 8385898+ 8e Linux LVM Disk /dev/sdc: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdc1 * 1 130 1044193+ 83 Linux Disk /dev/sdd: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk /dev/sdd doesn't contain a valid partition table Disk /dev/sde: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk /dev/sde doesn't contain a valid partition table Disk /dev/sdf: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk /dev/sdf doesn't contain a valid partition table Disk /dev/sdg: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
要在线扩容,如果vg01还有未使用的空间的话直接扩展即可,如果没有未使用空间的话,则需要添加新的PV到vg01,此处将sdg做为一个PV后,扩展到vg01,此处无可用空间,所以先把/dev/sdg加入vg01后再扩展
[root@dbabc.net ~]# pvcreate /dev/sdg Physical volume "/dev/sdg" successfully created [root@dbabc.net ~]# vgextend vg01 /dev/sdg Volume group "vg01" successfully extended
新加入一个PV后,此时查看vg01包含四个PV,多出来了刚增加的/dev/sdg:
[root@dbabc.net ~]# vgdisplay -v vg01 Using volume group(s) on command line Finding volume group "vg01" --- Volume group --- VG Name vg01 System ID Format lvm2 Metadata Areas 4 Metadata Sequence No 9 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 4 Act PV 4 VG Size 7.98 GB PE Size 4.00 MB Total PE 2044 Alloc PE / Size 1527 / 5.96 GB Free PE / Size 517 / 2.02 GB VG UUID t13Ltu-D9vh-nh78-UwEa-Ho7Q-Zo0o-F2JZfJ --- Logical volume --- LV Name /dev/vg01/lvol0 VG Name vg01 LV UUID DX3lXF-XK3Z-mj2Y-yMnS-Ns1z-8dt4-542pId LV Write Access read/write LV Status available # open 1 LV Size 4.00 GB Current LE 1024 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:4 --- Logical volume --- LV Name /dev/vg01/lvol1 VG Name vg01 LV UUID kFtxX7-2TyK-q8wT-e3cu-TfkE-NEcN-lAtFI7 LV Write Access read/write LV Status available # open 1 LV Size 1.86 GB Current LE 475 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:5 --- Logical volume --- LV Name /dev/vg01/lvol2 VG Name vg01 LV UUID kmPX21-6F9M-LCuI-Gpxq-nHvV-1kcT-WuYyHT LV Write Access read/write LV Status available # open 1 LV Size 112.00 MB Current LE 28 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:6 --- Physical volumes --- PV Name /dev/sdd PV UUID wd8Vy3-Uln9-PyA8-pAcr-2Cj7-D9eF-CVYoDN PV Status allocatable Total PE / Free PE 511 / 0 PV Name /dev/sde PV UUID 2zC9un-1K60-J81Z-LPr6-42Vz-CGl7-cgoA3m PV Status allocatable Total PE / Free PE 511 / 0 PV Name /dev/sdf PV UUID j0LIlX-e3yQ-cgGA-ia2v-Ws6v-3QNW-xg8z21 PV Status allocatable Total PE / Free PE 511 / 6 PV Name /dev/sdg PV UUID 2GG5b0-bzyn-1TYQ-H3DB-RvGC-2QuD-H1oEHk PV Status allocatable Total PE / Free PE 511 / 511
用lvresize命令将此VG中未使用的空间扩展到lvol2,以下是增加1024M。
[root@dbabc.net ~]# lvresize -L+1024 /dev/vg01/lvol2 Extending logical volume lvol2 to 1.11 GB Logical volume lvol2 successfully resized
再看df的状态,/test03使用率仍为100%,因为lvresize只是做一个扩展的映射,并未真正扩展到lv上面。
[root@dbabc.net ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg00-lv_root 6.0G 396M 5.3G 7% / /dev/mapper/vg00-lv_usr 6.8G 1.7G 4.8G 26% /usr /dev/mapper/vg00-lv_data 93M 5.6M 83M 7% /data /dev/sdc1 988M 24M 914M 3% /boot /dev/mapper/vg01-lvol0 4.0G 137M 3.7G 4% /test01 /dev/mapper/vg01-lvol1 1.9G 35M 1.7G 2% /test02 /dev/mapper/vg01-lvol2 109M 109M 0 100% /test03
要将扩展完成,需要一个resize2fs的命令,令新增的空间在线(on-line)生效。
[root@dbabc.net ~]# resize2fs /dev/vg01/lvol2 resize2fs 1.39 (29-May-2006) Filesystem at /dev/vg01/lvol2 is mounted on /test03; on-line resizing required Performing an on-line resize of /dev/vg01/lvol2 to 1163264 (1k) blocks. The filesystem on /dev/vg01/lvol2 is now 1163264 blocks long.
再查看/test03目录的大小:
[root@dbabc.net ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg00-lv_root 6.0G 398M 5.3G 7% / /dev/mapper/vg00-lv_usr 6.8G 1.7G 4.8G 26% /usr /dev/mapper/vg00-lv_data 93M 5.6M 83M 7% /data /dev/sdc1 988M 24M 914M 3% /boot /dev/mapper/vg01-lvol0 4.0G 137M 3.7G 4% /test01 /dev/mapper/vg01-lvol1 1.9G 35M 1.7G 2% /test02 /dev/mapper/vg01-lvol2 1.1G 110M 934M 11% /test03
查看lvol2的信息,可看到空间变大了。
[root@dbabc.net ~]# lvdisplay -v /dev/vg01/lvol2 Using logical volume(s) on command line --- Logical volume --- LV Name /dev/vg01/lvol2 VG Name vg01 LV UUID kmPX21-6F9M-LCuI-Gpxq-nHvV-1kcT-WuYyHT LV Write Access read/write LV Status available # open 1 LV Size 1.11 GB Current LE 284 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:6
Copyright © Dbabc.Net All Rights Reserved.
本站内容仅代表个人观点, 与其他任何组织或公司无关
-The End-