Linux操作系统LVM动态扩展root分区
1、查看挂载硬盘 sda已使用,sdb新挂载
[root@nginx1 ~]# fdisk -l
Disk /dev/sda: 161.1 GB, 161061273600 bytes
255 heads, 63 sectors/track, 19581 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: 0x000a881d
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 19582 156773376 8e Linux LVM
Disk /dev/mapper/vg_rhel6moban-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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_rhel6moban-lv_swap: 8438 MB, 8438939648 bytes
255 heads, 63 sectors/track, 1025 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_rhel6moban-lv_home: 98.4 GB, 98406760448 bytes
255 heads, 63 sectors/track, 11963 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: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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
2、查看pv
[root@nginx1 ~]# sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 vg_rhel6moban lvm2 a-- 149.51g 0
3、扩容PV
[root@nginx1 ~]# sudo pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
You have mail in /var/spool/mail/root
4、检查
[root@nginx1 ~]# sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 vg_rhel6moban lvm2 a-- 149.51g 0
/dev/sdb lvm2 a-- 100.00g 100.00g
5、扩容vg
[root@nginx1 ~]# sudo vgextend vg_rhel6moban /dev/sdb
Volume group "vg_rhel6moban" successfully extended
6、查看vg扩容结果
[root@nginx1 ~]# sudo vgdisplay
--- Volume group ---
VG Name vg_rhel6moban
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size 249.50 GiB
PE Size 4.00 MiB
Total PE 63873
Alloc PE / Size 38274 / 149.51 GiB
Free PE / Size 25599 / 100.00 GiB
VG UUID 0Zc1Oa-SkIu-HuU4-12y8-QuY0-E62X-YLVmlY
7、查看df
[root@nginx1 ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/vg_rhel6moban-lv_root
50G 38G 9.4G 80% /
tmpfs 3.9G 148K 3.9G 1% /dev/shm
/dev/sda1 485M 37M 423M 9% /boot
/dev/mapper/vg_rhel6moban-lv_home
91G 830M 85G 1% /home
You have mail in /var/spool/mail/root
8、扩容LV
[root@nginx1 ~]# sudo lvextend -l +25599 /dev/mapper/vg_rhel6moban-lv_root
Extending logical volume lv_root to 150.00 GiB
Logical volume lv_root successfully resized
9、扩容完并没有立刻从df能查看扩容结果
[root@nginx1 ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/vg_rhel6moban-lv_root
50G 38G 9.4G 81% /
tmpfs 3.9G 148K 3.9G 1% /dev/shm
/dev/sda1 485M 37M 423M 9% /boot
/dev/mapper/vg_rhel6moban-lv_home
91G 830M 85G 1% /home
10、ext格式需要 resize2fs 执行命令一下
[root@nginx1 ~]# sudo resize2fs /dev/mapper/vg_rhel6moban-lv_root
xfs格式执行命令
[root@nginx1 ~]#xfs_growfs /dev/mapper/vg_rhel6moban-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_rhel6moban-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 10
Performing an on-line resize of /dev/mapper/vg_rhel6moban-lv_root to 39320576 (4k) blocks.
The filesystem on /dev/mapper/vg_rhel6moban-lv_root is now 39320576 blocks long.
11、再重新df查看,已扩容完成
[root@nginx1 ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/vg_rhel6moban-lv_root
148G 38G 103G 27% /
tmpfs 3.9G 148K 3.9G 1% /dev/shm
/dev/sda1 485M 37M 423M 9% /boot
/dev/mapper/vg_rhel6moban-lv_home
91G 830M 85G 1% /home