centos7根目录扩容
具体操作步骤
1、查看本机磁盘环境挂载情况
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.7G 0 1.7G 0% /dev
tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs 1.8G 39M 1.8G 3% /run
tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 8.0G 5.5G 2.5G 69% /
/dev/vda2 1014M 182M 833M 18% /boot
tmpfs 357M 0 357M 0% /run/user/0
[root@localhost ~]#
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 492K 0 rom
vda 252:0 0 42G 0 disk
├─vda1 252:1 0 4M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 9G 0 part
├─centos-root 253:0 0 8G 0 lvm /
└─centos-swap 253:1 0 1G 0 lvm [SWAP]
[root@localhost ~]#
可以看到根目录总容量为8G,设备vda的总容量为42G。
2、添加磁盘分区
需要给根目录40G,已有8G,还需添加32G容量。
[root@localhost ~]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): p
Selected partition 4
First sector (20971520-88080383, default 20971520):
Using default value 20971520
Last sector, +sectors or +size{K,M,G} (20971520-88080383, default 88080383):
Using default value 88080383
Partition 4 of type Linux and of size 32 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@localhost ~]#
查看分区是否创建
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 492K 0 rom
vda 252:0 0 42G 0 disk
├─vda1 252:1 0 4M 0 part
├─vda2 252:2 0 1G 0 part /boot
├─vda3 252:3 0 9G 0 part
│ ├─centos-root 253:0 0 8G 0 lvm /
│ └─centos-swap 253:1 0 1G 0 lvm [SWAP]
└─vda4 252:4 0 32G 0 part
[root@localhost ~]#
可以看到vda4分区已创建
3、开始扩容
创建物理卷
[root@localhost ~]# lvm
lvm> pvcreate /dev/vda4
Physical volume "/dev/vda4" successfully created.
lvm>
查看物理卷和卷组:
lvm> pvdisplay
--- Physical volume ---
PV Name /dev/vda3
VG Name centos
PV Size <9.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 2302
Free PE 0
Allocated PE 2302
PV UUID RUHQRO-Cdeh-rV19-yoKc-l9Yf-PlLB-yoSPbw
"/dev/vda4" is a new physical volume of "32.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vda4
VG Name
PV Size 32.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID LuWMZJ-1KQy-uwwG-oUpO-2wwl-ggVY-9ErLaE
lvm>
lvm> vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
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 8.99 GiB
PE Size 4.00 MiB
Total PE 2302
Alloc PE / Size 2302 / 8.99 GiB
Free PE / Size 0 / 0
VG UUID F419sc-7iNH-PkwR-UOQz-FNZJ-5Jcc-oLg9uv
lvm>
将物理卷加入到卷组:
lvm> vgextend centos /dev/vda4
Volume group "centos" successfully extended
lvm>
lvm> vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 7
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 <40.99 GiB
PE Size 4.00 MiB
Total PE 10493
Alloc PE / Size 2302 / 8.99 GiB
Free PE / Size 8191 / <32.00 GiB
VG UUID F419sc-7iNH-PkwR-UOQz-FNZJ-5Jcc-oLg9uv
lvm>
可以看到Free PE / Size增加了
将卷组剩余空间(刚添加的32G)添加到逻辑卷/dev/centos/root
lvm> lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from 7.99 GiB (2046 extents) to <39.99 GiB (10237 extents).
Logical volume centos/root successfully resized.
lvm>
lvm> exit
Exiting.
[root@localhost ~]#
4、同步到文件系统
之前只是对逻辑卷扩容,还要同步到文件系统,实现对根目录的扩容
[root@localhost ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=523776 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=2095104, 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 2095104 to 10482688
[root@localhost ~]#
然后再看挂载情况
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.7G 0 1.7G 0% /dev
tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs 1.8G 39M 1.8G 3% /run
tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 40G 5.5G 35G 14% /
/dev/vda2 1014M 182M 833M 18% /boot
tmpfs 357M 0 357M 0% /run/user/0
[root@localhost ~]#
可以看到有40G的空间挂载在根目录上
参考:
参考链接