You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在运行中的Linux服务器上通过缩减/home分区来扩容/分区

如何在运行中的Linux服务器上通过缩减/home分区来扩容/分区

Hey there, I see you're stuck with a nearly full root partition while /home has tons of unused space—let's work through this fix step by step. First, let's confirm your current disk setup from the output you shared:

[root@myserver ~]# df -h
Filesystem                  Size  Used Avail Use% Mounted on
devtmpfs                     63G     0   63G   0% /dev
tmpfs                        63G  5.2M   63G   1% /dev/shm
tmpfs                        63G  4.0G   59G   7% /run
tmpfs                        63G     0   63G   0% /sys/fs/cgroup
/dev/mapper/almalinux-root   70G   43G   28G  61% /
none                         63G  6.5M   63G   1% /var/lve/dbgovernor-shm
/dev/nvme0n1p2             1014M  352M  663M  35% /boot
/dev/nvme0n1p1              599M  5.8M  594M   1% /boot/efi
/dev/mapper/almalinux-home  1.8T  185G  1.6T  11% /home
[root@myserver ~]#

Perfect, your /home has 1.6T free space, so we can safely shrink it to give more breathing room to the root partition. Here's how to do it without breaking anything (promise, just follow along carefully):

  • Backup /home data first (this is non-negotiable!)
    Partition tweaks carry risk, so don't skip this. Create a compressed backup to a temporary location (or better, external storage if you have it):

    tar -czf /tmp/home_backup.tar.gz /home
    

    If you prefer rsync for incremental backups, use:

    rsync -av /home /path/to/external/drive/home_backup
    
  • Unmount the /home partition
    First, make sure no users or processes are using /home. Check for active processes with:

    lsof /home
    

    Ask users to log out or kill those processes gracefully. If you can't do that, force unmount (use this only as a last resort):

    fuser -km /home
    umount /home
    

    Run df -h again to confirm /home is no longer listed.

  • Shrink the /home logical volume
    First, check and repair the filesystem to avoid corruption:

    e2fsck -f /dev/mapper/almalinux-home
    

    Now shrink the filesystem itself. Let's leave 500G for /home (since you only use 185G, this gives you plenty of spare space and frees up ~1.3T for root):

    resize2fs /dev/mapper/almalinux-home 500G
    

    Then shrink the logical volume to match the filesystem size:

    lvreduce -L 500G /dev/mapper/almalinux-home
    

    You'll get a warning—type y to confirm if you're confident in your setup.

  • Expand the root logical volume
    Allocate all the freed-up space to your root partition with:

    lvextend -l +100%FREE /dev/mapper/almalinux-root
    

    If you want to add a specific amount instead (e.g., 400G), use:

    lvextend -L +400G /dev/mapper/almalinux-root
    
  • Resize the root filesystem to use the new space
    Finally, expand the filesystem to utilize the newly allocated space:

    resize2fs /dev/mapper/almalinux-root
    
  • Remount /home and verify changes
    Mount your /home partition back:

    mount /home
    

    Run df -h one last time—you should see your root partition has way more free space, and /home is at the size you set.

Quick heads-up for XFS users

If your filesystems are XFS instead of ext4, XFS doesn't support shrinking. In that case, you'll need to: backup /home → delete the /home logical volume → expand the root volume → create a new /home logical volume → format it → restore your data.

Also, to prevent this from happening again, set up automatic log rotation for Apache with logrotate—it'll archive old logs and keep your root partition from filling up unexpectedly.

备注:内容来源于stack exchange,提问作者MinHeap

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 08:33:03