[Linux][centOS]调整删除home分区大小 扩大/根分区空间
新的centos系统的时候,默认分区的情况下(如果你的磁盘比较大),他默认会把/根分区分50G,而把其他空间放到/home分区下面,这样的话你的根分区容量就太小了,很容易满。造成了Centos7系统根分区空间小,/home空间大,这样的一个结果,那么怎么样把这个/home给他删除扩容到/根分区呢?
先看下我操作的系统信息:
```bash
# uname -a
Linux centos7_168 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
#
# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
#
```
#### 查看磁盘情况
!(data/attachment/forum/202206/25/162435gfe22gefl2rvvepb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
#### 修改分区表
```bash
# vi /etc/fstab
```
删掉home分区或者注释掉
!(data/attachment/forum/202206/25/162527itg4g4tvttv9kzh9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
卸载掉/home分区,然后查看/home分区已经没有了
ps:如果有需要的数据,记得提前备份,比如:tar cvf /tmp/home.tar /home #备份/home 执行命令之后可以在/tmp文件夹下看到home.tar
!(data/attachment/forum/202206/25/162709cjojzoj24p555pkr.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
`作者:程序员潇然 疯狂的字节X https://crazybytex.com/`
#### 查看逻辑分区
```bash
# lvscan
ACTIVE '/dev/centos/swap' [<7.88 GiB] inherit
ACTIVE '/dev/centos/home' [<41.12 GiB] inherit
ACTIVE '/dev/centos/root' inherit
#
```
!(data/attachment/forum/202206/25/162752xebub9q2g390ibf7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
#### 移除/home的lv分区
```bash
# lvremove /dev/mapper/centos-home
Do you really want to remove active logical volume centos/home? : y
Logical volume "home" successfully removed
```
!(data/attachment/forum/202206/25/162815py3wyl6ytwzrtfgz.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
#### 再次查看分区情况
!(data/attachment/forum/202206/25/162831mp4gz85k4p44pzcf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
#### 查看一下vg的设置
!(data/attachment/forum/202206/25/162904u7w760ywexc2zcc7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
其中,FreePE / Size 10527 / 41.12 GiB
#### 空闲空间扩展到 / 根空间
```bash
# lvextend -l +100%free /dev/mapper/centos-root
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 91.12 GiB (23327 extents).
Logical volume centos/root successfully resized.
```
!(data/attachment/forum/202206/25/162951hglo7yy8y8a9ay97.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
```bash
ps:
关于增加容量,还有其他方式
lvextend -L +1T /dev/mapper/centos-root
lvextend -L +200G /dev/mapper/centos-root
```
#### 刷新
扩容完成之后,查看空间,你会发现他的容量还没有增加,我们需要刷新一下,需要执行一个命令
!(data/attachment/forum/202206/25/163109gmijuiz8mmixzib9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
!(data/attachment/forum/202206/25/163118huc71zgp1pmgpxmz.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
```bash
如果是centos7是xfs_growfs,如果是centos6是resize2fs
xfs_growfs /dev/mapper/centos-root
```
#### 检查确认
!(data/attachment/forum/202206/25/163202ow3df3h735jeoppd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
!(data/attachment/forum/202206/16/141330jha7st9soow8772i.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "common_log.png")
`转载务必注明出处:程序员潇然,疯狂的字节X,https://www.crazybytex.com/thread-14-1-1.html `
页:
[1]