在线扩展根分区 red hat 4.8.3-9

 跑程序的时候发现报错,提示空间不足,仔细查看后发现是根分区已满

27G的空间只有20k剩余

考虑从/data分区压缩一点空间到/分区

切换到root用户

执行下面的命令

1. umount /data

$ umount /data

2. shrink the /data filesystem

$ fsck -f /dev/mapper/centos-data
$ resize2fs /dev/mapper/centos-data 300G

3. shrink the /data logical volume

$ lvreduce -L -160G /dev/mapper/centos-data

这一步报了

Couldn't create temporary archive name.
Volume group "centos" metadata archive failed.

这样的错误,原因是根目录已满,删除一些文件后,即可正常执行


4. resize the /data partition to the size of the LV

$ resize2fs /dev/mapper/centos-data


5. extend the /root logical volume

$ lvextend -L +160G /dev/mapper/centos-root


6. extend the /root filesystem

$ fsck -f /dev/mapper/centos-root

$ resize2fs /dev/mapper/centos-root  (这一步会报bad magic number in super-block之类的错,因为我这里使用的文件系统是xfs而不是ext4,故使用下一条命令代替)
$ xfs_growfs /dev/mapper/centos-root


7. mount /data

$ mount /data

最终结果如下,成功在线扩展根分区

参考资料

http://unix.stackexchange.com/questions/213245/increase-root-partition-by-reducing-home

http://blog.itpub.net/24486203/viewspace-1790666

原文地址:https://www.cnblogs.com/stevenczp/p/5948358.html