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

CentOS系统下从/home分区扩容/root分区的方法

Resizing /root Partition Using Space from /home on CentOS

Alright, let's walk through this step by step—this method assumes both /root and /home are part of an LVM volume group (the default setup for most CentOS installations). If they're on separate physical disks, this won't work, but let's stick to the typical scenario.

Critical Pre-Requisite: Backup Your /home Data

Before we touch anything, backup all data in /home—this is non-negotiable. You can use tar to create a compressed backup:

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

Or, if you have external storage, use rsync to copy files over:

rsync -av /home/ /mnt/external_drive/home_backup/

Step 1: Unmount the /home Partition

First, switch to the root user if you aren't already:

su - root

Then unmount /home. If you get a "device is busy" error, it means a user is logged into their home directory. You can force terminate processes using /home with:

fuser -km /home

Or reboot into single-user mode (safer for busy systems) and then run:

umount /home

Step 2: Shrink the /home Logical Volume

First, check the file system for errors (this is mandatory before resizing):

e2fsck -f /dev/mapper/centos-home

(Note: Replace centos-home with your actual logical volume name—find it with lvdisplay)

Next, shrink the file system itself. Let's say we want to leave 20GB for /home—adjust the size to fit your needs:

resize2fs /dev/mapper/centos-home 20G

(If your /home uses XFS (common on CentOS 7+), you can't shrink XFS. Skip to the alternative note at the bottom.)

Now shrink the logical volume to match the resized file system:

lvreduce -L 20G /dev/mapper/centos-home

Step 3: Expand the /root Partition

Now we have free space in the volume group. Let's allocate all of it to /root:
First, expand the logical volume:

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

(Again, replace centos-root with your actual logical volume name if needed)

Then expand the file system to fill the new logical volume space:

  • For ext4 file systems:
resize2fs /dev/mapper/centos-root
  • For XFS file systems (CentOS 7+ default):
xfs_growfs /dev/mapper/centos-root

Step 4: Remount /home and Restore Data

Remount the /home partition:

mount /home

Then restore your backup data. If you used tar:

tar -xzf /tmp/home_backup.tar.gz -C /

If you used rsync:

rsync -av /mnt/external_drive/home_backup/ /home/

Step 5: Verify the Changes

Check the new partition sizes with:

df -h

You should see /root has more space, and /home is now the size you specified.


Alternative for XFS /home Partitions

Since XFS doesn't support shrinking, you'll need to delete the /home logical volume entirely:

  1. Backup /home data as before.
  2. Unmount /home.
  3. Delete the logical volume:
lvremove /dev/mapper/centos-home
  1. Expand /root using all free space (follow Step 3 above).
  2. Create a new /home logical volume (e.g., 20GB):
lvcreate -L 20G -n home centos
  1. Format it with XFS:
mkfs.xfs /dev/mapper/centos-home
  1. Mount /home and restore your data.

内容的提问来源于stack exchange,提问作者krishna

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:06:32