前提:磁盘已做好raid,格式化,分区,创建好文件系统(文件系统和需扩容目录一致ext4...xfs)
1. 查看磁盘空间大小,使用df -h 命令
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/cl-root 69G 29G 41G 42% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 33M 1.9G 2% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 197M 154M 43M 79% /boot
/dev/mapper/cl-home 5.0G 33M 5.0G 1% /home
tmpfs 379M 0 379M 0% /run/user/0
2.使用fdisk -l命令查看磁盘信息。当看到第一行Disk /dev/sdb: 161.1 GB与实际df -h显示内容不符时,说明增加磁盘成功
root@ubuntu14:/opt# fdisk -l
Disk /dev/sdb: 161.1 GB, 161061273600 bytes
16 heads, 63 sectors/track, 312076 cylinders, total 314572800 sectors
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/Osize (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001a023
3. 创建物理卷,使用pvcreate /dev/sdb1
root@ubuntu14:~# pvcreate /dev/vda4
Physical volume "/dev/vda4"successfully created 表示成功
4.查看新建的物理卷和大小,使用pvdisplay
root@ubuntu:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size 7.63 TiB / not usable 0
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 1999313
Free PE 0
Allocated PE 1999313
PV UUID bpNHUd-W7lC-0cC7-VHJc-8hCQ-WlbJ-so41WI
"/dev/sdb1" is a new physical volume of "2.00 TiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 2.00 TiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 713lyL-WqZr-g0Sn-IkoG-RdXG-KrAz-lbqgXI
新建的物理卷不在卷组中,需添加
4. 将添加新的物理卷,加载到ubuntu-vg卷组,使用vgextend ubuntu-vg /dev/vdb1
root@ubuntu14:~# vgextend ubuntu-vg /dev/sdb1
Volume group "ubuntu-vg"successfully extended
再次pvdisplay 查看,已添加
5. 查看卷组信息,使用vgdisplay命令。
root@ubuntu:~# vgdisplay
--- Volume group ---
VG Name ubuntu-vg
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 9.63 TiB
PE Size 4.00 MiB
Total PE 2523600
Alloc PE / Size 1999313 / 7.63 TiB
Free PE / Size 524287 / 2.00 TiB
VG UUID dYs1Nx-XAU7-kKCe-vQM0-XDbM-E1n0-tjFjn1
Free PE / Size 524287 / 2.00 TiB 可扩容大小
6.增加ubuntu-vg大小,增加2000G。 lvresize -L +2000G /dev/mapper/ubuntu--vg-root
root@ubuntu14:~# lvresize -L +2000G /dev/mapper/ubuntu--vg-root
Extending logical volume root to 147.76 GiB
Logical volume root successfully resized
11. 重新识别ubuntu--vg大小,使用resize2fs /dev/mapper/ubuntu--vg-root命令。
root@ubuntu14:~# resize2fs /dev/mapper/ubuntu--vg-root
root@ubuntu:~# resize2fs /dev/mapper/ubuntu--vg-root
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/mapper/ubuntu--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 473, new_desc_blocks = 598
The filesystem on /dev/mapper/ubuntu--vg-root is now 2504580096 blocks long.
ps:如出现以下情况
resize2fs: Bad magic numberinsuper-block 当尝试打开 /dev/mapper/vg_node003-lv_root时 找不到有效的文件系统超级块
则:xfs_growfs /dev/mapper/vg_node003-lv_root
12.查看扩容后的大小 ,使用df -h命令