如何扩容LV磁盘分区

前面其实也发了2个教程了。http://www.v2kt.com/archives/446.html是新建lv磁盘,然后挂载某个目录,相当于新建一个LV磁盘。http://www.v2kt.com/archives/451.html是存在多余的VG空间,直接可以扩容现有的LV磁盘。本教程是不存在多余的VG空间,要先创建PV,然后扩容VG空间后,再扩容现有的LV分区。

先查看下磁盘分区情况:

root@103 [/]# fdisk -l

Disk /dev/sda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000049b5

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 5222 41430016 8e Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 40.3 GB, 40340815872 bytes
255 heads, 63 sectors/track, 4904 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 2080 MB, 2080374784 bytes
255 heads, 63 sectors/track, 252 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

再df -h看看文件系统:

root@103 [~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
37G 7.2G 28G 21% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 485M 62M 398M 14% /boot
/usr/tmpDSK 1.5G 35M 1.4G 3% /tmp

实际上160G的磁盘,根目录只挂载了37G,客户是做虚拟主机业务的,当然磁盘越大越好,肿么办?只有把现有的LV磁盘VolGroup-lv_root分区搞大,才是硬道理。也就是扩容下LV磁盘。

再看看下面的数据:

root@103 [~]# pvdisplay
— Physical volume —
PV Name /dev/sda2
VG Name VolGroup
PV Size 39.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 10114
Free PE 0
Allocated PE 10114
PV UUID 0VQB8r-ur7Z-poo6-e0pb-b383-d8TY-dg3FqY

root@103 [~]# vgdisplay
— Volume group —
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 39.51 GiB
PE Size 4.00 MiB
Total PE 10114
Alloc PE / Size 10114 / 39.51 GiB
Free PE / Size 0 / 0
VG UUID 6qeLUV-dteH-quoB-kjqy-kzLh-02oz-PpKH1w

root@103 [~]# lvdisplay
— Logical volume —
LV Path /dev/VolGroup/lv_root
LV Name lv_root
VG Name VolGroup
LV UUID qhXZ3r-oW19-8SCj-j0F5-v1SP-fEKq-fDB3pH
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2014-08-01 12:15:44 +0800
LV Status available
# open 1
LV Size 37.57 GiB
Current LE 9618
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:0

— Logical volume —
LV Path /dev/VolGroup/lv_swap
LV Name lv_swap
VG Name VolGroup
LV UUID ZKA5FB-JRDL-zB7P-mKZh-qCnn-xz4T-ysVGCx
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2014-08-01 12:15:58 +0800
LV Status available
# open 1
LV Size 1.94 GiB
Current LE 496
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:1

显示没有多余的PV空间可用,只有先用fdisk命令,先创建个分区,然后再扩容VG就可以了。

具体操作如下:

fdisk /dev/sda

m

n

p【敲3】

t【敲8e】

w

partprobe

新建一个分区完毕。然后再看看,多了个/dev/sda3分区,我都是一路回车也就是直接把多余的空间都分到这个区了。

root@103 [/]# fdisk -l

Disk /dev/sda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000049b5

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 5222 41430016 8e Linux LVM
/dev/sda3 5222 20886 125823755 8e Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 40.3 GB, 40340815872 bytes
255 heads, 63 sectors/track, 4904 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 2080 MB, 2080374784 bytes
255 heads, 63 sectors/track, 252 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

新建新的PV,第一次可能会失败,可能是前面partprobe没有生效还是咋的,重启下VPS,然后再操作一遍pvcreate /dev/sda3就ok了。

root@103 [/]# pvcreate /dev/sda3
Device /dev/sda3 not found (or ignored by filtering).

root@103 [~]# pvcreate /dev/sda3
dev_is_mpath: failed to get device for 8:3
Physical volume “/dev/sda3” successfully created

root@103 [~]# pvscan
PV /dev/sda2 VG VolGroup lvm2 [39.51 GiB / 0 free]
PV /dev/sda3 lvm2 [119.99 GiB]
Total: 2 [159.50 GiB] / in use: 1 [39.51 GiB] / in no VG: 1 [119.99 GiB]

看看有多余的PV空间空出来了。利用vgextend命令扩容一下VG。

root@103 [~]# vgextend VolGroup /dev/sda3
Volume group “VolGroup” successfully extended

root@103 [~]# vgdisplay
— Volume group —
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 159.50 GiB
PE Size 4.00 MiB
Total PE 40832
Alloc PE / Size 10114 / 39.51 GiB
Free PE / Size 30718 / 119.99 GiB
VG UUID 6qeLUV-dteH-quoB-kjqy-kzLh-02oz-PpKH1w

扩容后,会看见有119.99空间可以利用。

然后再用lvresize命令可以放大现有LV分区容量

root@103 [~]# lvresize -l +30718 /dev/VolGroup/lv_root
Extending logical volume lv_root to 157.56 GiB
Logical volume lv_root successfully resized

root@103 [~]# resize2fs /dev/VolGroup/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required
old desc_blocks = 3, new_desc_blocks = 10
Performing an on-line resize of /dev/VolGroup/lv_root to 41304064 (4k) blocks.
The filesystem on /dev/VolGroup/lv_root is now 41304064 blocks long.

最后再df -h查看下磁盘文件系统:VolGroup-lv_root有之前的37G变成156G了。

root@103 [~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
156G 7.2G 142G 5% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 485M 62M 398M 14% /boot
/usr/tmpDSK 1.5G 35M 1.4G 3% /tmp

《如何扩容LV磁盘分区》上有1条评论

发表评论

邮箱地址不会被公开。 必填项已用*标注