背景:
linux操作系统使用lvm管理后,当出现磁盘空间不足的时候,就需要添加硬盘,然后把硬盘添加到vg里面去,在线扩容磁盘空间,业务不受影响。
具体添加流程:
disk--->pv--->vg--->lv
- 添加完硬盘后,进入操作系统,检查是否已经识别到硬盘了,如果没有识别,需要重启操作系统。
[root@cw001 ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00019bb5
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 2611 20458496 8e Linux LVM
Disk /dev/mapper/vg_cw001-lv_root: 16.8 GB, 16752050176 bytes
255 heads, 63 sectors/track, 2036 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/vg_cw001-lv_swap: 4194 MB, 4194304000 bytes
255 heads, 63 sectors/track, 509 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/sdb: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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,然后添加新的硬盘到lvm中的pv组中
[root@cw001 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_cw001
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID ybQPnm-seCs-Np31-Hr64-P5eS-3saW-HQ57u0
[root@cw001 ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
[root@cw001 ~]# pvdiaplay
-bash: pvdiaplay: command not found
[root@cw001 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_cw001
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID ybQPnm-seCs-Np31-Hr64-P5eS-3saW-HQ57u0
"/dev/sdb" is a new physical volume of "60.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 60.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID B0fjek-wMhA-bIQP-wuA1-PRiN-eD3g-rrhyjh
- 检查vg的大小,然后使用vgextend扩容vg空间
[root@cw001 ~]# vgdisplay
--- Volume group ---
VG Name vg_cw001
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 19.51 GiB
PE Size 4.00 MiB
Total PE 4994
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 0 / 0
VG UUID U3tLKK-6I7f-mYJn-qurr-tX45-ubz5-3czoMJ
- 把sdb硬盘添加到vg_cw001这个vg组中
[root@cw001 ~]# vgextend vg_cw001 /dev/sdb
Volume group "vg_cw001" successfully extended
- 添加完后,查看显示大小
[root@cw001 ~]# vgdisplay
--- Volume group ---
VG Name vg_cw001
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 79.50 GiB
PE Size 4.00 MiB
Total PE 20353
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 15359 / 60.00 GiB
VG UUID U3tLKK-6I7f-mYJn-qurr-tX45-ubz5-3czoMJ
[root@cw001 ~]#
- 添加完vg后,现在开始正式扩容lv
#查看lv大小
[root@cw001 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg_cw001/lv_root
LV Name lv_root
VG Name vg_cw001
LV UUID h1F8Vv-xCBt-kRDF-Kkut-0S7F-e9F0-srEdWm
LV Write Access read/write
LV Creation host, time cw001, 2015-07-29 18:45:20 -0400
LV Status available
# open 1
LV Size 15.60 GiB
Current LE 3994
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/vg_cw001/lv_swap
LV Name lv_swap
VG Name vg_cw001
LV UUID QXzVwA-ERYR-f3iw-ZgIn-cxNV-u849-5lQwiM
LV Write Access read/write
LV Creation host, time cw001, 2015-07-29 18:45:22 -0400
LV Status available
# open 1
LV Size 3.91 GiB
Current LE 1000
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
- 执行lv扩容命令lvextend
[root@cw001 ~]# lvextend -L +59G /dev/vg_cw001/lv_root
Extending logical volume lv_root to 74.60 GiB
Logical volume lv_root successfully resized
[root@cw001 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg_cw001/lv_root
LV Name lv_root
VG Name vg_cw001
LV UUID h1F8Vv-xCBt-kRDF-Kkut-0S7F-e9F0-srEdWm
LV Write Access read/write
LV Creation host, time cw001, 2015-07-29 18:45:20 -0400
LV Status available
# open 1
LV Size 74.60 GiB
Current LE 19098
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/vg_cw001/lv_swap
LV Name lv_swap
VG Name vg_cw001
LV UUID QXzVwA-ERYR-f3iw-ZgIn-cxNV-u849-5lQwiM
LV Write Access read/write
LV Creation host, time cw001, 2015-07-29 18:45:22 -0400
LV Status available
# open 1
LV Size 3.91 GiB
Current LE 1000
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
[root@cw001 ~]#
- 检查硬盘扩容是否已经成功
[root@cw001 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_cw001-lv_root
16G 14G 677M 96% /
tmpfs 932M 443M 489M 48% /dev/shm
/dev/sda1 485M 32M 428M 7% /boot
/dev/sr0 4.1G 4.1G 0 100% /media/CentOS_6.4_Final
[root@cw001 ~]#
- 发现没有成功,这个时候,需要使用resize2fs重新刷新一次即可。
[root@cw001 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_cw001-lv_root
16G 14G 677M 96% /
tmpfs 932M 443M 489M 48% /dev/shm
/dev/sda1 485M 32M 428M 7% /boot
/dev/sr0 4.1G 4.1G 0 100% /media/CentOS_6.4_Final
[root@cw001 ~]# res
reset resize2fs resizecons restart restorecon restorecond
[root@cw001 ~]# resize2fs /dev/vg_cw001/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_cw001/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 5
Performing an on-line resize of /dev/vg_cw001/lv_root to 19556352 (4k) blocks.
The filesystem on /dev/vg_cw001/lv_root is now 19556352 blocks long.
[root@cw001 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_cw001-lv_root
74G 14G 56G 20% /
tmpfs 932M 443M 489M 48% /dev/shm
/dev/sda1 485M 32M 428M 7% /boot
/dev/sr0 4.1G 4.1G 0 100% /media/CentOS_6.4_Final
[root@cw001 ~]#
结束: 执行完上面命令后,表示lv已经扩容成功,如果下次磁盘空间不够,可以继续添加物理盘,然后重新扩容,不影响用户使用。