CentOS 7 扩展root根分区
2016-07-15 by dongnan
目标
为 CentOS 7
(XFS文件系统)扩展 root
根分区。
环境
CentOS 7.2 on XenServer 6.5
。- 虚拟机模板初始磁盘
xvda
10GB ,启用后期扩容至 50GB。 - 系统使用
LVM
逻辑卷,XFS
文件系统。
准备工作
备份数据
数据无价,请先备份。
收集信息
# 执行命令
vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- 9.51g 28.00m
# 执行命令
lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
docker-poolmeta centos -wi-a----- 12.00m
root centos -wi-ao---- 8.47g
swap centos -wi-ao---- 1.00g
磁盘分区
磁盘信息
# 执行命令
parted /dev/xvda
(parted) print free
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
32.3kB 1049kB 1016kB Free Space
1 1049kB 525MB 524MB primary xfs boot
2 525MB 10.7GB 10.2GB primary lvm
10.7GB 53.7GB 42.9GB Free Space
创建扩展分区
(parted) mkpart
Partition type? primary/extended? extended
Start? 10.7GB
End? 53.7GB
(parted) print
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 525MB 524MB primary xfs boot
2 525MB 10.7GB 10.2GB primary lvm
3 10.7GB 53.7GB 42.9GB extended lba
创建逻辑分区
(parted) mkpart
Partition type? primary/logical? logical
File system type? [ext2]? xfs
Start? 10.7GB
End? 53.7GB
更改分区类型
(parted) t
Partition number? 5
Flag to Invert? lvm
(parted) print
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 525MB 524MB primary xfs boot
2 525MB 10.7GB 10.2GB primary lvm
3 10.7GB 53.7GB 42.9GB extended lba
5 10.7GB 53.7GB 42.9GB logical lvm
重启系统
# 分区准备完毕后,需要重启系统,才能识别新的分区。
# xenserver 7.0 的vm 系统无需重启系统
sync && reboot
逻辑卷
创建物理卷
pvcreate /dev/xvda5
Physical volume "/dev/xvda5" successfully created
扩展卷组
vgextend centos /dev/xvda5
Volume group "centos" successfully extended
获得可用PE
vgdisplay | grep Free
Free PE / Size 10246 / 40.02 GiB
扩展逻辑卷
lvextend -l +10246 /dev/mapper/centos-root
Size of logical volume centos/root changed from 8.47 GiB (2168 extents) to 48.49 GiB (12414 extents).
Logical volume root successfully resized.
文件系统
XFS文件系统,使用 xfs_growfs
命令扩展根分区。
xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=555008 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=2220032, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
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 2220032 to 12711936
验证
检查分区
df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 49G 5.4G 44G 12% /
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs tmpfs 1.8G 8.4M 1.8G 1% /run
tmpfs tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/xvda1 xfs 497M 167M 330M 34% /boot
tmpfs tmpfs 354M 0 354M 0% /run/user/0
后续
删除 xenserver
虚拟机备份快照。