[root@bogon ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 6.2G 6.2G 51M 100% / devtmpfs 908M 0 908M 0% /dev tmpfs 920M 0 920M 0% /dev/shm tmpfs 920M 8.6M 911M 1% /run tmpfs 920M 0 920M 0% /sys/fs/cgroup /dev/sda1 1014M 175M 840M 18% /boot tmpfs 184M 0 184M 0% /run/user/0
該LVM分區動態擴容分兩種狀況:node
首先在虛擬機控制檯擴容已有的sda後
centos
1 fdisk /dev/sda 對/dev/sda磁盤進行操做(新建分區及格式化) 2 n 3 p 4 回車 默認分區號; 5 回車 默認磁盤建立開始位置; 6 回車 默認磁盤建立結束位置; 7 t 設置分區類型 8 8e LVM類型 9 w 保存 10 重啓 11 ls /dev/sd* 會發現多出一個/dev/sda3 12 lvm 進入lvm管理 13 lvm>pvcreate /dev/sda3 建立邏輯卷 14 lvm>vgextend centos /dev/sda3 //將初始化過的分區加入到虛擬卷組 centos 15 lvm>vgdisplay -v 16 lvm>lvextend -L +100G /dev/mapper/centos-root 17 lvm>pvdisplay //查看卷容量 18 lvm>quit 19 使用命令xfs_growfs /dev/mapper/centos-root擴展容量 20 df -h 進行查看擴容以後的
在虛擬機控制檯新加磁盤後,並重啓虛擬機
bash
[root@bogon ~]# ls /dev/sd* 會發現多出一個/dev/sdb /dev/sda /dev/sda1 /dev/sda2 /dev/sdb [root@bogon ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <7.00g 0 [root@bogon ~]# pvcreate /dev/sdb WARNING: ext4 signature detected on /dev/sdb at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sdb. Physical volume "/dev/sdb" successfully created. [root@bogon ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <7.00g 0 [root@bogon ~]# vgextend centos /dev/sdb Volume group "centos" successfully extended [root@bogon ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 2 0 wz--n- 26.99g <20.00g [root@bogon ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- <6.20g swap centos -wi-ao---- 820.00m [root@bogon ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 6.2G 6.2G 43M 100% / devtmpfs 908M 0 908M 0% /dev tmpfs 920M 0 920M 0% /dev/shm tmpfs 920M 8.6M 911M 1% /run tmpfs 920M 0 920M 0% /sys/fs/cgroup /dev/sda1 1014M 175M 840M 18% /boot tmpfs 184M 0 184M 0% /run/user/0 [root@bogon ~]# lvextend -L +20G /dev/mapper/centos-root Insufficient free space: 5120 extents needed, but only 5119 available [root@bogon ~]# lvextend -L +19G /dev/mapper/centos-root Size of logical volume centos/root changed from <6.20 GiB (1586 extents) to <16.20 GiB (4146 extents). Logical volume centos/root successfully resized. [root@bogon ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=406016 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=1624064, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 1624064 to 4245504 [root@bogon ~]# df -h
完成。