hufeng719
作者hufeng7192019-07-16 16:59
系统工程师, 山东莱钢永锋钢铁

linux系统下对目录扩容

字数 2771阅读 1768评论 0赞 4

1、现象:日志服务器当初考虑不周,分区划分不太合理:

2、目标:将/home磁盘空间缩减  并将新的磁盘分区扩充到/根目录
 
卸载/home分区并压缩分区

卸载/home时 提示目标忙,fuser -m /home查看谁用/home时提示没有fuser命令
[root@localhost zabbix]# umount /home
umount: /home:目标忙。
        (有些情况下通过 lsof(8) 或 fuser(1) 可以
         找到有关使用该设备的进程的有用信息)
[root@localhost zabbix]# fuser -m /home
-bash: fuser: 未找到命令
解决没有fuser命令的问题:
在CentOS / RHEL 7上找不到fuser命令

-bash: fuser: command not found 
yum 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 to 100.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce home? [y/n]: y
  Reducing logical volume home to 100.00 GiB
  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=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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 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=6553600 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=26214400, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=12800, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
 
重新挂载mount /home

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

4

添加新评论0 条评论

Ctrl+Enter 发表

关于TWT  使用指南  社区专家合作  厂商入驻社区  企业招聘  投诉建议  版权与免责声明  联系我们
© 2019  talkwithtrend — talk with trend,talk with technologist 京ICP备09031017号-30