[root@localhost /]# df -lh
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 50G 50G 7M 100% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 34M 7.7G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda5 1014M 137M 878M 14% /boot
/dev/sda1 256M 37M 220M 15% /boot/efi
overlay 50G 50G 377M 100% /var/lib/docker/overlay2/a480a7a27851ee77b881b36af1d3d9a2a19373f8846cbb76f9e48485e0b5ebdf/merged
overlay 50G 50G 377M 100% /var/lib/docker/overlay2/4aff621e30e3e11ddbf0c51d5bfa2a099251224f4cf65b6933b332599fb9c521/merged
overlay 50G 50G 377M 100% /var/lib/docker/overlay2/9c18a076eff51d30307a96f905ea2c388b4a6741fb15c2eee922202463daa5a4/merged
overlay 50G 50G 377M 100% /var/lib/docker/overlay2/bb02f7092db151657a158fb214037820a126e6065492f40d235fa8b559c06c85/merged
overlay 50G 50G 377M 100% /var/lib/docker/overlay2/6d0bd8b50b40182dc412b4c516863c816d9ae6a6290767cb98d9a3841ded347e/merged
overlay 50G 50G 377M 100% /var/lib/docker/overlay2/9d51bcda4ea05bc1f45aed7e79090b4f03256b94259fb2a91c46d2c7edf9e715/merged
shm 64M 0 64M 0% /var/lib/docker/containers/20f17047e1e9de4ad2dd29ab3485ff30da98088227e2a72c2a9b6135b8dc6875/shm
shm 64M 0 64M 0% /var/lib/docker/containers/9fcc3e5578984922e5061e18434e43559285f7fdd8ef183663d51cc5e9dd5876/shm
shm 64M 0 64M 0% /var/lib/docker/containers/e46c98bd2fa0d74fada9216fe2db2554f4d7f5193f58904be4b88c452a306d1b/shm
shm 64M 0 64M 0% /var/lib/docker/containers/ddb2e242a5fa2d2ab22c3466fbad6640b285501e429a117254fb871c318b7b4e/shm
shm 64M 0 64M 0% /var/lib/docker/containers/5e4ac1a75f1aa1432db3878085b3c8003631b064081e4f766bf70d6b353c370e/shm
shm 64M 0 64M 0% /var/lib/docker/containers/4b80905456a2245ca2272050858e5f2a1330e92fc5e6dc0a5100dec43fc2037c/shm
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/centos-home 771G 129G 643G 17% /home
发现 home目录 磁盘空间很多,而 根目录只有 50G容量。所以想把home目录的空间 调整一部分到 根目录下
主要的思路大体上面已经说了,再详细说一遍:
- First: 我们先把/home内容进行备份,我直接导出到其他硬盘里了
- Second:然后将/home文件系统所在的逻辑卷删除;
- Third:这边我们就可以进行扩大/root文件系统;
- Forth:删除了home,就要新建一个/home;
- Fiveth:最后恢复/home内容
1 卸载 home
[root@localhost /]# umount /home
[root@localhost /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 50G 50G 7M 100% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 34M 7.7G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda5 1014M 137M 878M 14% /boot
/dev/sda1 256M 37M 220M 15% /boot/efi
overlay 50G 50G 375M 100% /var/lib/docker/overlay2/a480a7a27851ee77b881b36af1d3d9a2a19373f8846cbb76f9e48485e0b5ebdf/merged
overlay 50G 50G 375M 100% /var/lib/docker/overlay2/4aff621e30e3e11ddbf0c51d5bfa2a099251224f4cf65b6933b332599fb9c521/merged
overlay 50G 50G 375M 100% /var/lib/docker/overlay2/9c18a076eff51d30307a96f905ea2c388b4a6741fb15c2eee922202463daa5a4/merged
overlay 50G 50G 375M 100% /var/lib/docker/overlay2/bb02f7092db151657a158fb214037820a126e6065492f40d235fa8b559c06c85/merged
overlay 50G 50G 375M 100% /var/lib/docker/overlay2/6d0bd8b50b40182dc412b4c516863c816d9ae6a6290767cb98d9a3841ded347e/merged
overlay 50G 50G 375M 100% /var/lib/docker/overlay2/9d51bcda4ea05bc1f45aed7e79090b4f03256b94259fb2a91c46d2c7edf9e715/merged
shm 64M 0 64M 0% /var/lib/docker/containers/20f17047e1e9de4ad2dd29ab3485ff30da98088227e2a72c2a9b6135b8dc6875/shm
shm 64M 0 64M 0% /var/lib/docker/containers/9fcc3e5578984922e5061e18434e43559285f7fdd8ef183663d51cc5e9dd5876/shm
shm 64M 0 64M 0% /var/lib/docker/containers/e46c98bd2fa0d74fada9216fe2db2554f4d7f5193f58904be4b88c452a306d1b/shm
shm 64M 0 64M 0% /var/lib/docker/containers/ddb2e242a5fa2d2ab22c3466fbad6640b285501e429a117254fb871c318b7b4e/shm
shm 64M 0 64M 0% /var/lib/docker/containers/5e4ac1a75f1aa1432db3878085b3c8003631b064081e4f766bf70d6b353c370e/shm
shm 64M 0 64M 0% /var/lib/docker/containers/4b80905456a2245ca2272050858e5f2a1330e92fc5e6dc0a5100dec43fc2037c/shm
tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@localhost /]# lvremove /dev/mapper/centos-home
Do you really want to remove active logical volume centos/home? [y/n]: y
Logical volume "home" successfully removed
注意: 取消挂载/home时出现umount: /home: device is busy, 原因是因为有程序在使用/home目录,我们可以使用lsof查看那些程序的进程,
lsof /home
然后逐步关掉 使用 home 的进程
2 扩容 root
[root@localhost /]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 829.15 GiB
PE Size 4.00 MiB
Total PE 212263
Alloc PE / Size 14800 / 57.81 GiB
Free PE / Size 197463 / <771.34 GiB
VG UUID 0dZpiE-dMnE-f2dJ-JGIT-94ER-5Rdr-7focNT
[root@localhost /]# lvextend -L 420G /dev/mapper/centos-root
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 420.00 GiB (107520 extents).
Logical volume centos/root successfully resized.
[root@localhost /]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3276800 blks
= sectsz=4096 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=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13107200 to 110100480
vgdisplay 命令可以查看 已经分类了的空间( Alloc PE / Size) 和还有 多少可分配(Free PE / Size)
上面 在扩容 root 时本来想 增加 420G空间的 ,但没有写成 ‘+420G’,所有总空间就变成 420G
重新 创建 home 分区,并挂载
[root@localhost /]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 829.15 GiB
PE Size 4.00 MiB
Total PE 212263
Alloc PE / Size 109520 / 427.81 GiB
Free PE / Size 102743 / <401.34 GiB
VG UUID 0dZpiE-dMnE-f2dJ-JGIT-94ER-5Rdr-7focNT
[root@localhost /]# lvcreate -L 400G -n /dev/mapper/centos-home
Logical volume "home" created.
[root@localhost /]# mkfs.xfs /dev/mapper/centos-home
meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=26214400 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=104857600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=51200, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost /]# mount /dev/mapper/centos-home
[root@localhost /]# df -h
æä»¶ç³»ç» å®¹é å·²ç¨ å¯ç¨ å·²ç¨% æè½½ç¹
/dev/mapper/centos-root 420G 50G 371G 12% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 34M 7.7G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda5 1014M 137M 878M 14% /boot
/dev/sda1 256M 37M 220M 15% /boot/efi
overlay 420G 50G 371G 12% /var/lib/docker/overlay2/a480a7a27851ee77b881b36af1d3d9a2a19373f8846cbb76f9e48485e0b5ebdf/merged
overlay 420G 50G 371G 12% /var/lib/docker/overlay2/4aff621e30e3e11ddbf0c51d5bfa2a099251224f4cf65b6933b332599fb9c521/merged
overlay 420G 50G 371G 12% /var/lib/docker/overlay2/9c18a076eff51d30307a96f905ea2c388b4a6741fb15c2eee922202463daa5a4/merged
overlay 420G 50G 371G 12% /var/lib/docker/overlay2/bb02f7092db151657a158fb214037820a126e6065492f40d235fa8b559c06c85/merged
overlay 420G 50G 371G 12% /var/lib/docker/overlay2/6d0bd8b50b40182dc412b4c516863c816d9ae6a6290767cb98d9a3841ded347e/merged
overlay 420G 50G 371G 12% /var/lib/docker/overlay2/9d51bcda4ea05bc1f45aed7e79090b4f03256b94259fb2a91c46d2c7edf9e715/merged
shm 64M 0 64M 0% /var/lib/docker/containers/20f17047e1e9de4ad2dd29ab3485ff30da98088227e2a72c2a9b6135b8dc6875/shm
shm 64M 0 64M 0% /var/lib/docker/containers/9fcc3e5578984922e5061e18434e43559285f7fdd8ef183663d51cc5e9dd5876/shm
shm 64M 0 64M 0% /var/lib/docker/containers/e46c98bd2fa0d74fada9216fe2db2554f4d7f5193f58904be4b88c452a306d1b/shm
shm 64M 0 64M 0% /var/lib/docker/containers/ddb2e242a5fa2d2ab22c3466fbad6640b285501e429a117254fb871c318b7b4e/shm
shm 64M 0 64M 0% /var/lib/docker/containers/5e4ac1a75f1aa1432db3878085b3c8003631b064081e4f766bf70d6b353c370e/shm
shm 64M 0 64M 0% /var/lib/docker/containers/4b80905456a2245ca2272050858e5f2a1330e92fc5e6dc0a5100dec43fc2037c/shm
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/centos-home 400G 33M 400G 1% /home
到这一步,其实就可以 恢复原来home 中的数据文件了。但我还想将空间在分配一下,其实是再玩一玩
[root@localhost /]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 829.15 GiB
PE Size 4.00 MiB
Total PE 212263
Alloc PE / Size 211920 / 827.81 GiB
Free PE / Size 343 / <1.34 GiB
VG UUID 0dZpiE-dMnE-f2dJ-JGIT-94ER-5Rdr-7focNT
[root@localhost /]# lsof /home
[root@localhost /]# umount /home
[root@localhost /]# lvremove /dev/mapper/centos-home
Do you really want to remove active logical volume centos/home? [y/n]: y
Logical volume "home" successfully removed
[root@localhost /]# lvextend -L +80G /dev/mapper/centos-root
Size of logical volume centos/root changed from 420.00 GiB (107520 extents) to 500.00 GiB (128000 extents).
Logical volume centos/root successfully resized.
[root@localhost /]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=34, agsize=3276800 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=110100480, 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=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 110100480 to 131072000
[root@localhost /]# lvcreate -L 40G -n /dev/mapper/centos-home
Logical volume "home" created.
[root@localhost /]# mkfs.xfs /dev/mapper/centos-home
meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=2621440 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=10485760, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=5120, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost /]# mount /dev/mapper/centos-home
[root@localhost /]# df -h
æä»¶ç³»ç» å®¹é å·²ç¨ å¯ç¨ å·²ç¨% æè½½ç¹
/dev/mapper/centos-root 500G 50G 451G 10% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 34M 7.7G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda5 1014M 137M 878M 14% /boot
/dev/sda1 256M 37M 220M 15% /boot/efi
overlay 500G 50G 451G 10% /var/lib/docker/overlay2/a480a7a27851ee77b881b36af1d3d9a2a19373f8846cbb76f9e48485e0b5ebdf/merged
overlay 500G 50G 451G 10% /var/lib/docker/overlay2/4aff621e30e3e11ddbf0c51d5bfa2a099251224f4cf65b6933b332599fb9c521/merged
overlay 500G 50G 451G 10% /var/lib/docker/overlay2/9c18a076eff51d30307a96f905ea2c388b4a6741fb15c2eee922202463daa5a4/merged
overlay 500G 50G 451G 10% /var/lib/docker/overlay2/bb02f7092db151657a158fb214037820a126e6065492f40d235fa8b559c06c85/merged
overlay 500G 50G 451G 10% /var/lib/docker/overlay2/6d0bd8b50b40182dc412b4c516863c816d9ae6a6290767cb98d9a3841ded347e/merged
overlay 500G 50G 451G 10% /var/lib/docker/overlay2/9d51bcda4ea05bc1f45aed7e79090b4f03256b94259fb2a91c46d2c7edf9e715/merged
shm 64M 0 64M 0% /var/lib/docker/containers/20f17047e1e9de4ad2dd29ab3485ff30da98088227e2a72c2a9b6135b8dc6875/shm
shm 64M 0 64M 0% /var/lib/docker/containers/9fcc3e5578984922e5061e18434e43559285f7fdd8ef183663d51cc5e9dd5876/shm
shm 64M 0 64M 0% /var/lib/docker/containers/e46c98bd2fa0d74fada9216fe2db2554f4d7f5193f58904be4b88c452a306d1b/shm
shm 64M 0 64M 0% /var/lib/docker/containers/ddb2e242a5fa2d2ab22c3466fbad6640b285501e429a117254fb871c318b7b4e/shm
shm 64M 0 64M 0% /var/lib/docker/containers/5e4ac1a75f1aa1432db3878085b3c8003631b064081e4f766bf70d6b353c370e/shm
shm 64M 0 64M 0% /var/lib/docker/containers/4b80905456a2245ca2272050858e5f2a1330e92fc5e6dc0a5100dec43fc2037c/shm
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/centos-home 40G 33M 40G 1% /home
[root@localhost /]# umount /home
[root@localhost /]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 10
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 829.15 GiB
PE Size 4.00 MiB
Total PE 212263
Alloc PE / Size 140240 / 547.81 GiB
Free PE / Size 72023 / <281.34 GiB
VG UUID 0dZpiE-dMnE-f2dJ-JGIT-94ER-5Rdr-7focNT
[root@localhost /]# lvextend -L +281G /dev/mapper/centos-home
Size of logical volume centos/home changed from 40.00 GiB (10240 extents) to 321.00 GiB (82176 extents).
Logical volume centos/home successfully resized.
[root@localhost /]# xfs_growfs /dev/mapper/centos-home
xfs_growfs: /dev/mapper/centos-home is not a mounted XFS filesystem
[root@localhost /]# mount /dev/mapper/centos-home
[root@localhost /]# xfs_growfs /dev/mapper/centos-home
meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=2621440 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=10485760, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=5120, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 10485760 to 84148224
[root@localhost /]# df -h
æä»¶ç³»ç» å®¹é å·²ç¨ å¯ç¨ å·²ç¨% æè½½ç¹
/dev/mapper/centos-root 500G 50G 451G 10% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 34M 7.7G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda5 1014M 137M 878M 14% /boot
/dev/sda1 256M 37M 220M 15% /boot/efi
overlay 500G 50G 451G 10% /var/lib/docker/overlay2/a480a7a27851ee77b881b36af1d3d9a2a19373f8846cbb76f9e48485e0b5ebdf/merged
overlay 500G 50G 451G 10% /var/lib/docker/overlay2/4aff621e30e3e11ddbf0c51d5bfa2a099251224f4cf65b6933b332599fb9c521/merged
overlay 500G 50G 451G 10% /var/lib/docker/overlay2/9c18a076eff51d30307a96f905ea2c388b4a6741fb15c2eee922202463daa5a4/merged
overlay 500G 50G 451G 10% /var/lib/docker/overlay2/bb02f7092db151657a158fb214037820a126e6065492f40d235fa8b559c06c85/merged
overlay 500G 50G 451G 10% /var/lib/docker/overlay2/6d0bd8b50b40182dc412b4c516863c816d9ae6a6290767cb98d9a3841ded347e/merged
overlay 500G 50G 451G 10% /var/lib/docker/overlay2/9d51bcda4ea05bc1f45aed7e79090b4f03256b94259fb2a91c46d2c7edf9e715/merged
shm 64M 0 64M 0% /var/lib/docker/containers/20f17047e1e9de4ad2dd29ab3485ff30da98088227e2a72c2a9b6135b8dc6875/shm
shm 64M 0 64M 0% /var/lib/docker/containers/9fcc3e5578984922e5061e18434e43559285f7fdd8ef183663d51cc5e9dd5876/shm
shm 64M 0 64M 0% /var/lib/docker/containers/e46c98bd2fa0d74fada9216fe2db2554f4d7f5193f58904be4b88c452a306d1b/shm
shm 64M 0 64M 0% /var/lib/docker/containers/ddb2e242a5fa2d2ab22c3466fbad6640b285501e429a117254fb871c318b7b4e/shm
shm 64M 0 64M 0% /var/lib/docker/containers/5e4ac1a75f1aa1432db3878085b3c8003631b064081e4f766bf70d6b353c370e/shm
shm 64M 0 64M 0% /var/lib/docker/containers/4b80905456a2245ca2272050858e5f2a1330e92fc5e6dc0a5100dec43fc2037c/shm
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/centos-home 321G 34M 321G 1% /home
[root@localhost /]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 11
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 829.15 GiB
PE Size 4.00 MiB
Total PE 212263
Alloc PE / Size 212176 / 828.81 GiB
Free PE / Size 87 / 348.00 MiB
VG UUID 0dZpiE-dMnE-f2dJ-JGIT-94ER-5Rdr-7focNT
以上先是 给 root 增加了 80G空间,再创建了一个 40G的home,然后挂载home,接着又卸载 home ,然后 扩展home 最后挂载home
https://www.cnblogs.com/zhe-hello/p/9241990.html