1、现象:日志服务器当初考虑不周,分区划分不太合理:
2、目标:将/home磁盘空间缩减 并将新的磁盘分区扩充到/根目录
卸载/home分区并压缩分区
卸载/home时 提示目标忙,fuser -m /home查看谁用/home时提示没有fuser命令
[root@localhost zabbix]# umount /homeumount: /home:目标忙。
(有些情况下通过 lsof(8) 或 fuser(1) 可以
找到有关使用该设备的进程的有用信息)
[root@localhost zabbix]#fuser -m /home-bash: fuser: 未找到命令
解决没有fuser命令的问题:
在CentOS/RHEL 7上找不到fuser命令-bash: fuser: command not foundyum install psmisc
fuser -m /home //继续查找谁在用/home
kill -9 11757 //停止进程
umount /home //卸载/home文件系统
压缩分区:resize2fs -p /dev/mapper/centos-home 100G
确认是xfs格式系统
cat /etc/fstab|grep centos-home
xfs文件系统扩容必须安装 xfsdump工具yum install xfsdump -y
减少/home空间到100GB:
lvreduce-L 100G /dev/mapper/centos-home
[root@localhost~]# lvreduce -L 100G /dev/mapper/centos-home
WARNING: Reducing active logical volume to100.00GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce home? [y/n]: y
Reducing logical volume home to100.00GiB
Logical volume home successfully resized
[root@localhost~]#
增大根目录
lvextend -l +100%FREE /dev/mapper/centos-root
[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/centos-root
Extending logical volume root to 167.37 GiB
Logical volume root successfully resized
延伸/目录空间
xfs_growfs /dev/mapper/centos-root
[root@localhost~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=3276800blks= sectsz=512 attr=2, projid32bit=1
= crc=0data= bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 swidth=0blks
naming=version 2 bsize=4096 ascii-ci=0 ftype=0log=internal bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1realtime=none extsz=4096 blocks=0, rtextents=0data blocks changed from13107200 to 43874304[root@localhost~]#
重新挂载/home
[root@localhost ~]# mount /home
mount: /dev/mapper/centos-home:不能读超级块
必须格式化/home分区,才能挂载----所以缩减/home分区之前必须备份/home的内容(切记!!!)
mkfs.xfs -f /dev/mapper/centos-home
[root@localhost~]# mkfs.xfs -f /dev/mapper/centos-home
meta-data=/dev/mapper/centos-home isize=256 agcount=4, agsize=6553600blks= sectsz=512 attr=2, projid32bit=1
= crc=0data= bsize=4096 blocks=26214400, imaxpct=25
= sunit=0 swidth=0blks
naming=version 2 bsize=4096 ascii-ci=0 ftype=0log=internal log bsize=4096 blocks=12800, version=2
= sectsz=512 sunit=0 blks, lazy-count=1realtime=none extsz=4096 blocks=0, rtextents=0
重新挂载mount /home