- 在安装centos系统的时候,如果在安装时没有分配磁盘空间,选择的是默认分配的,在安装完成后,可以发现大容量磁盘往往分配在了home下面。
- 在没有大量自定义用户使用的情况下,home的空间基本不用时,可以将空间转移至root下面。
查看目录结构
代码语言:javascript复制[root@mrf-server opt]# df -hl
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs 7.7G 0 7.7G 0% /dev/shm
tmpfs 7.7G 18M 7.7G 1% /run
tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 39G 12G 78% /
/dev/sda2 1014M 176M 839M 18% /boot
/dev/sda1 200M 12M 189M 6% /boot/efi
/dev/mapper/centos-home 180G 33M 180G 1% /home
tmpfs 1.6G 0 1.6G 0% /run/user/0
overlay 50G 39G 12G 78% /var/lib/docker/overlay2/b13ed87897fe1cabe547341e9a855c43bf04fcf7f3ef44e41138b08e62fb6191/merged
overlay 50G 39G 12G 78% /var/lib/docker/overlay2/502140d31ceae249f65f90e2fc096af6d8cece5f086ab9ce7e01ff80ec82576d/merged
overlay 50G 39G 12G 78% /var/lib/docker/overlay2/b8bfb2a4f4360f9b3915452fb4303d5ebf02299bee754de9d7245b5efc0d8149/merged
overlay 50G 39G 12G 78% /var/lib/docker/overlay2/59d0f795fa7c6d89467ada62d8e9e1cd8b9ad5628ca251bb5c9011fbed513af1/merged
overlay 50G 39G 12G 78% /var/lib/docker/overlay2/b7ed9b03a812579f993ac7dbe086afb15401ec5109af9467a5efbbc524f74b79/merged
备份/home数据
代码语言:javascript复制[root@mrf-server opt]# mkdir /home-backup
[root@mrf-server opt]#
[root@mrf-server opt]# mv /home/* /home-backup
删除/home逻辑卷
代码语言:javascript复制[root@mrf-server /]# umount /home
[root@mrf-server /]#
[root@mrf-server /]# lvremove /dev/centos/home
Do you really want to remove active logical volume centos/home? [y/n]: y
Logical volume "home" successfully removed
查看可用大小
代码语言:javascript复制[root@mrf-server /]# 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 <237.28 GiB
PE Size 4.00 MiB
Total PE 60743
Alloc PE / Size 14784 / 57.75 GiB
Free PE / Size 45959 / <179.53 GiB
VG UUID 6zqmne-yIRi-DzR0-pOc7-pwHI-O1hM-Vh7T5c
根据:Free PE / Size 45959 / <179.53 GiB判断 可用空间为:179.53 GiB
新建/home卷
代码语言:javascript复制[root@mrf-server /]# lvcreate -L 50G -n home centos
WARNING: xfs signature detected on /dev/centos/home at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/centos/home.
Logical volume "home" created.
查看/home卷
代码语言:javascript复制[root@mrf-server /]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID PkUzOD-edvq-AYZH-RZte-nOOF-h27l-UDywl5
LV Write Access read/write
LV Creation host, time localhost, 2024-05-07 16:07:38 0800
LV Status available
# open 2
LV Size 7.75 GiB
Current LE 1984
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID jpAxQq-GFzU-AfaT-Hotn-k6bG-FwII-a6EzIq
LV Write Access read/write
LV Creation host, time localhost, 2024-05-07 16:07:43 0800
LV Status available
# open 1
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/centos/home
LV Name home
VG Name centos
LV UUID jMNrQ0-VpnG-FBry-wmrb-9oue-ALSZ-fuXYrd
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-05-08 09:38:46 0800
LV Status available
# open 0
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
分配50G空间成功
查看可用空间大小
代码语言:javascript复制[root@mrf-server /]# 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 3
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <237.28 GiB
PE Size 4.00 MiB
Total PE 60743
Alloc PE / Size 27584 / 107.75 GiB
Free PE / Size 33159 / <129.53 GiB
VG UUID 6zqmne-yIRi-DzR0-pOc7-pwHI-O1hM-Vh7T5c
根据:Free PE / Size 33159 / <129.53 GiB判断 可用空间为129.53 GiB
/home上建立xfs文件系统
代码语言:javascript复制[root@mrf-server /]# mkfs -t xfs /dev/centos/home
Discarding blocks...Done.
meta-data=/dev/centos/home isize=512 agcount=4, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=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 log bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
挂载/home
代码语言:javascript复制[root@mrf-server /]# mount /dev/centos/home /home
[root@mrf-server /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs 7.7G 0 7.7G 0% /dev/shm
tmpfs 7.7G 18M 7.7G 1% /run
tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 39G 12G 78% /
/dev/sda2 1014M 176M 839M 18% /boot
/dev/sda1 200M 12M 189M 6% /boot/efi
tmpfs 1.6G 0 1.6G 0% /run/user/0
overlay 50G 39G 12G 78% /var/lib/docker/overlay2/b13ed87897fe1cabe547341e9a855c43bf04fcf7f3ef44e41138b08e62fb6191/merged
overlay 50G 39G 12G 78% /var/lib/docker/overlay2/502140d31ceae249f65f90e2fc096af6d8cece5f086ab9ce7e01ff80ec82576d/merged
overlay 50G 39G 12G 78% /var/lib/docker/overlay2/b8bfb2a4f4360f9b3915452fb4303d5ebf02299bee754de9d7245b5efc0d8149/merged
overlay 50G 39G 12G 78% /var/lib/docker/overlay2/59d0f795fa7c6d89467ada62d8e9e1cd8b9ad5628ca251bb5c9011fbed513af1/merged
overlay 50G 39G 12G 78% /var/lib/docker/overlay2/b7ed9b03a812579f993ac7dbe086afb15401ec5109af9467a5efbbc524f74b79/merged
/dev/mapper/centos-home 50G 33M 50G 1% /home
迁移home目录的备份数据
代码语言:javascript复制[root@mrf-server /]# mv /home-backup/* /home
[root@mrf-server /]# rm -rf /home-backup
将剩余的空间分配给根目录
代码语言:javascript复制[root@mrf-server /]# lvextend -L 129G /dev/centos/root
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 179.00 GiB (45824 extents).
Logical volume centos/root successfully resized.
[root@mrf-server /]#
[root@mrf-server /]#
[root@mrf-server /]#
[root@mrf-server /]#
[root@mrf-server /]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID PkUzOD-edvq-AYZH-RZte-nOOF-h27l-UDywl5
LV Write Access read/write
LV Creation host, time localhost, 2024-05-07 16:07:38 0800
LV Status available
# open 2
LV Size 7.75 GiB
Current LE 1984
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID jpAxQq-GFzU-AfaT-Hotn-k6bG-FwII-a6EzIq
LV Write Access read/write
LV Creation host, time localhost, 2024-05-07 16:07:43 0800
LV Status available
# open 1
LV Size 179.00 GiB
Current LE 45824
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/centos/home
LV Name home
VG Name centos
LV UUID jMNrQ0-VpnG-FBry-wmrb-9oue-ALSZ-fuXYrd
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-05-08 09:38:46 0800
LV Status available
# open 1
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
扩展根目录
代码语言:javascript复制[root@mrf-server /]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-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 46923776
[root@mrf-server /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs 7.7G 0 7.7G 0% /dev/shm
tmpfs 7.7G 18M 7.7G 1% /run
tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/mapper/centos-root 179G 39G 141G 22% /
/dev/sda2 1014M 176M 839M 18% /boot
/dev/sda1 200M 12M 189M 6% /boot/efi
tmpfs 1.6G 0 1.6G 0% /run/user/0
overlay 179G 39G 141G 22% /var/lib/docker/overlay2/b13ed87897fe1cabe547341e9a855c43bf04fcf7f3ef44e41138b08e62fb6191/merged
overlay 179G 39G 141G 22% /var/lib/docker/overlay2/502140d31ceae249f65f90e2fc096af6d8cece5f086ab9ce7e01ff80ec82576d/merged
overlay 179G 39G 141G 22% /var/lib/docker/overlay2/b8bfb2a4f4360f9b3915452fb4303d5ebf02299bee754de9d7245b5efc0d8149/merged
overlay 179G 39G 141G 22% /var/lib/docker/overlay2/59d0f795fa7c6d89467ada62d8e9e1cd8b9ad5628ca251bb5c9011fbed513af1/merged
overlay 179G 39G 141G 22% /var/lib/docker/overlay2/b7ed9b03a812579f993ac7dbe086afb15401ec5109af9467a5efbbc524f74b79/merged
/dev/mapper/centos-home 50G 33M 50G 1% /home
本文由 小马哥 创作,采用 知识共享署名4.0 国际许可协议进行许可 本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名