安装Linux时全部走的默认,导致home路径过大,由于安装CDH对home没有要求,现将home减小,增大根目录的大小,步骤如下:
1.查看分区空间和格式
df -h
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 16G 0 16G 0% /dev
tmpfs tmpfs 16G 0 16G 0% /dev/shm
tmpfs tmpfs 16G 9.7M 16G 1% /run
tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 50G 6.4G 44G 13% /
/dev/vda2 xfs 1014M 157M 858M 16% /boot
/dev/vda1 vfat 200M 12M 189M 6% /boot/efi
/dev/mapper/centos-home xfs 133G 33M 133G 1% /home
tmpfs tmpfs 3.2G 8.0K 3.2G 1% /run/user/42
tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/0
由此可以看到根目录与home目录都是xfs格式,由于xfs文件系统只支持增大分区空间的情况,不支持减小的情况。
若减小,只能在减小后将逻辑分区重新通过 mkfs.xfs 命令重新格式化才能挂载上,这样的话这个逻辑分区上原来的数据就丢失了。
2.卸载/home分区
umount /home
3.查看分区情况
df -h
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 16G 0 16G 0% /dev
tmpfs tmpfs 16G 0 16G 0% /dev/shm
tmpfs tmpfs 16G 9.7M 16G 1% /run
tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 50G 6.4G 44G 13% /
/dev/vda2 xfs 1014M 157M 858M 16% /boot
/dev/vda1 vfat 200M 12M 189M 6% /boot/efi
tmpfs tmpfs 3.2G 8.0K 3.2G 1% /run/user/42
tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/0
由此可见,/home目录已经被umount掉。
4.将/home对应的/dev/mapper/centos-home分区减小
lvreduce -L -100G /dev/mapper/centos-home
WARNING: Reducing active logical volume to <33.05 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce centos/home? [y/n]: y
Size of logical volume centos/home changed from <133.05 GiB (34060 extents) to <33.05 GiB (8460 extents).
Logical volume centos/home successfully resized.
5.xfs文件系统减小空间需要进行格式化操作
mkfs.xfs /dev/mapper/centos-home -f
meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=2165760 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=8663040, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=4230, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
6.重新挂载/home分区
mount /dev/mapper/centos-home /home/
7.验证挂在是否成功
df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 9.7M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 6.4G 44G 13% /
/dev/vda2 1014M 157M 858M 16% /boot
/dev/vda1 200M 12M 189M 6% /boot/efi
tmpfs 3.2G 12K 3.2G 1% /run/user/42
tmpfs 3.2G 0 3.2G 0% /run/user/0
/dev/mapper/centos-home 34G 33M 33G 1% /home
8.将释放了100G空间加到根目录下
lvextend -L +100G /dev/mapper/centos-root
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 150.00 GiB (38400 extents).
Logical volume centos/root successfully resized.
9.添加完成对根目录分区进行格式化
xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13107200 to 39321600
10.验证添加是否成功
df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 9.7M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/centos-root 150G 6.4G 144G 5% /
/dev/vda2 1014M 157M 858M 16% /boot
/dev/vda1 200M 12M 189M 6% /boot/efi
tmpfs 3.2G 12K 3.2G 1% /run/user/42
tmpfs 3.2G 0 3.2G 0% /run/user/0
/dev/mapper/centos-home 34G 33M 33G 1% /home
由此可见,home减少了100G空间,根目录增加了100G空间。