centos7把/home空间合并到/(根目录)
大家在使用虚拟机创建centos系统的时候,会发现原本打算分配的空间,有一部分给/home分配走了,这样就造成我们的根目录空间不够,所以我们要把/home分配走的空间还给根目录.
系统:centos7(64位)
1.先查看空间分配情况
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 38G 978M 37G 3% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.8M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 142M 873M 14% /boot
/dev/mapper/centos-home 19G 33M 19G 1% /home
tmpfs 783M 0 783M 0% /run/user/0
可以看到整个硬盘是60G,根目录只用了38G,/home使用了19G.
2.卸载/home分区
如果你/home里有数据,记得保存,我这是空的,所以直接执行:
umount /home
vim /etc/fstab ###(注释掉/home,避免开机自检)
#
# /etc/fstab
# Created by anaconda on Wed Jul 3 02:57:40 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=d7be0dd8-95ec-4495-a64c-459462ae7256 /boot xfs defaults 0 0
#/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
3.删除/home所在的lv
lvremove /dev/mapper/centos-home
接着会出现确认的内容,输入“y”,回车
Do you really want to remove active logical volume centos/home? [y/n]: y
Logical volume "home" successfully removed
4.查看物理卷情况
vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
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 <59.00 GiB
PE Size 4.00 MiB
Total PE 15103
Alloc PE / Size 10473 / 40.91 GiB
Free PE / Size 4630 / <18.09 GiB
VG UUID damgP3-SFOn-9IfM-k4bX-B2g1-D3HG-otTWEd
ps:
查看 Free PE / Size这项,可以看到还有18.09G可以分配,但我们实际只能分配18G.
5.扩展/root所在的lv
lvextend -L +18G /dev/mapper/centos-root
or
lvextend -l +100%FREE /dev/mapper/centos-root
or
lvextend -l +100%FREE /dev/mapper/centos-root
Size of logical volume centos/root changed from <37.04 GiB (9481 extents) to <55.04 GiB (14089 extents).
Logical volume centos/root successfully resized.
6.扩展/root空间
xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2427136 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=9708544, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=4740, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
7.检查是否成功
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 56G 979M 55G 2% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.8M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 142M 873M 14% /boot
tmpfs 783M 0 783M 0% /run/user/0
可以看到根目录空间已经增大.好了,大家可以自行试试.
评论: