内容纲要
问题
centos默认安装时对root分区仅仅分配了50G的空间,剩下的都基本上在home分区,宝塔面板默认是在根目录下放置相关网站文件,导致root空间捉襟见肘
解决方法
此方法需要格式化home分区,请提前备份home分区资料
- 查看当前分区状态及分区名称
[root@home ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos_home-root 50G 36G 15G 71% / devtmpfs 16G 0 16G 0% /dev tmpfs 16G 8.0K 16G 1% /dev/shm tmpfs 16G 9.9M 16G 1% /run tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/sda2 1014M 160M 855M 16% /boot /dev/sda1 200M 12M 189M 6% /boot/efi /dev/mapper/centos_home-home 410G 36M 410G 1% /home tmpfs 3.2G 0 3.2G 0% /run/user/0
- 解除挂载
umount /home
- 执行lvreduce释放home分区多余的空间
[root@home ~]# lvreduce -L 200G /dev/mapper/centos_home-home WARNING: Reducing active and open logical volume to 200.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce centos_home/home? [y/n]: y Size of logical volume centos_home/home changed from 410.05 GiB (104973 extents) to 200.00 GiB (51200 extents). Logical volume centos_home/home successfully resized.
- 将释放出来的空间分配给root
[root@home ~]# lvextend -l +100%FREE /dev/mapper/centos_home-root Size of logical volume centos_home/root changed from 50.00 GiB (12800 extents) to 260.05 GiB (66574 extents). Logical volume centos_home/root successfully resized.
- 使用xfs命令使修改生效
[root@home ~]# xfs_growfs /dev/mapper/centos_home-root meta-data=/dev/mapper/centos_home-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 68171776
- 查看最终结果可见root分区容量已经增加
[root@home www]# fdisk -l WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. 磁盘 /dev/sda:512.1 GB, 512110190592 字节,1000215216 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:gpt Disk identifier: 63761B35-8ECB-411B-8DB1-E51648ECF46C \# Start End Size Type Name 1 2048 411647 200M EFI System EFI System Partition 2 411648 2508799 1G Microsoft basic 3 2508800 1000214527 475.8G Linux LVM 磁盘 /dev/mapper/centos_home-root:279.2 GB, 279231594496 字节,545374208 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘 /dev/mapper/centos_home-swap:16.8 GB, 16844324864 字节,32899072 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘 /dev/mapper/centos_home-home:214.7 GB, 214748364800 字节,419430400 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节
格式化home分区
mkfs.xfs /dev/mapper/centos_home-home -f
重新挂载
mount /dev/mapper/centos_home-home /home
参考文档
https://blog.csdn.net/qq_28808697/article/details/103988967
https://www.cnblogs.com/kevingrace/p/5825963.html
centos_home-home空闲空间重新分配到centos_home-root