如何将磁盘空间从 centos-home 移动到 centos-root

God*_*tum 12 centos7

我有一个带有 1 280GB 磁盘的 VM。出于某种原因,我的布局是:

$ df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   50G   21G   30G  41% /
devtmpfs                 5.8G     0  5.8G   0% /dev
tmpfs                    5.8G     0  5.8G   0% /dev/shm
tmpfs                    5.8G  8.5M  5.8G   1% /run
tmpfs                    5.8G     0  5.8G   0% /sys/fs/cgroup
/dev/mapper/centos-home  224G   13G  212G   6% /home
/dev/sda1                497M  145M  352M  30% /boot
tmpfs                    1.2G     0  1.2G   0% /run/user/1000
Run Code Online (Sandbox Code Playgroud)

运行 fdisk -l:

$ sudo fdisk -l
[sudo] password for admin:

Disk /dev/sda: 300.6 GB, 300647710720 bytes, 587202560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0006c283

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   587202559   293088256   8e  Linux LVM

Disk /dev/mapper/centos-swap: 6316 MB, 6316621824 bytes, 12337152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 240.1 GB, 240115515392 bytes, 468975616 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Run Code Online (Sandbox Code Playgroud)

和:

$ sudo lsblk -io NAME,TYPE,SIZE,MOUNTPOINT,FSTYPE,MODEL
NAME            TYPE   SIZE MOUNTPOINT FSTYPE      MODEL
fd0             disk     4K
sda             disk   280G                        Virtual disk
|-sda1          part   500M /boot      xfs
`-sda2          part 279.5G            LVM2_member
  |-centos-swap lvm    5.9G [SWAP]     swap
  |-centos-root lvm     50G /          xfs
  `-centos-home lvm  223.6G /home      xfs
sr0             rom   1024M                        VMware IDE CDR10
Run Code Online (Sandbox Code Playgroud)

如何将用于 /dev/mapper/centos-home 的磁盘空间移动到 /dev/mapper/centos-root?我必须缩小 centos-home 并重新分配到 centos-root 吗?

小智 10

只要未安装,您就可以降低您的家庭 LV。(请记住,收缩有一些风险)

像这样:

umount /dev/mapper/centos-home
lvreduce -L 200G /dev/mapper/centos-home
Run Code Online (Sandbox Code Playgroud)

完成后重新安装您的主分区。

然后只需扩展您的根卷。

lvextend -t -r -l+100%FREE /dev/mapper/centos-root
Run Code Online (Sandbox Code Playgroud)

-t 是测试,如果没问题就第二次运行命令而不 -t

  • 接受的答案是不完整的:虽然您可以减少底层逻辑卷,但您**不能**缩小 XFS 文件系统。减少`/dev/mapper/centos-home` **会导致**home分区的数据丢失。如果您遵循此路线,请在减少此卷之前备份您在此卷上的任何重要内容。 (3认同)