/dev/mapper/centos-home空间过大问题
[centos@localhost ~]$ df -h #查看磁盘使用情况,根分区只有31G的空间,但/home目录有3.6T。
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 0 63G 0% /dev/shm
tmpfs 63G 19M 63G 1% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 20G 31G 39% /
/dev/sda2 1014M 216M 799M 22% /boot
/dev/mapper/centos-home 3.6T 142M 3.6T 1% /home
tmpfs 13G 8.0K 13G 1% /run/user/42
tmpfs 13G 0 13G 0% /run/user/1000
[centos@localhost ~]$ sudo vgdisplay #查看逻辑卷组情况
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
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 <3.64 TiB
PE Size 4.00 MiB
Total PE 953343
Alloc PE / Size 953343 / <3.64 TiB
Free PE / Size 0 / 0
VG UUID 5BRTG6-pRGo-KjkT-OhEC-A0iP-kB9u-ifKfW9
[centos@localhost ~]$ sudo lvdisplay #查看逻辑卷情况,默认三个,root、home和交换空间swap
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID 6rUQVd-fA8P-7SIe-frf0-F1Bj-UFSG-uZ3aLD
LV Write Access read/write
LV Creation host, time localhost, 2020-05-13 03:33:02 -0400
LV Status available
# open 2
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/home
LV Name home
VG Name centos
LV UUID 16a1d0-2Qb5-E7pL-aQLx-rNYr-wyQK-GJ6j93
LV Write Access read/write
LV Creation host, time localhost, 2020-05-13 03:33:03 -0400
LV Status available
# open 1
LV Size 3.58 TiB
Current LE 939519
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID ENPzwO-Q3oq-gkj1-hdNj-eVfq-SH3S-TdxNa2
LV Write Access read/write
LV Creation host, time localhost, 2020-05-13 03:34:29 -0400
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
操作步骤:
1.备份/home (不要在/home目录执行该命令)
$sudo tar -cvf /mnt/home.tar /home
2.终止/home目录所有进程 (不要在/home目录执行该命令)
$sudo fuser -km /home
3.卸载/home目录 (不要在/home目录执行该命令)
$sudo umount /home
4.删除逻辑卷/home (不要在/home目录执行该命令)
$ sudo lvremove /dev/centos/home
Do you really want to remove active logical volume centos/home? [y/n]: y
Logical volume "home" successfully removed
5.查看卷组可用空间
[centos@localhost opt]$ sudo 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 <3.64 TiB
PE Size 4.00 MiB
Total PE 953343
Alloc PE / Size 13824 / 54.00 GiB
Free PE / Size 939519 / 3.58 TiB
VG UUID 5BRTG6-pRGo-KjkT-OhEC-A0iP-kB9u-ifKfW9
注意:Free PE / Size 中显示的空间为卷组的空闲空间3.58TB,之前为0M,也就是刚才删除的逻辑卷home所占用的空间,
我们就从这个当中拿出一部分比如80G作为/home空间,剩余3.5TiB。
6.新建一个卷home,fdisk格式化为8e格式,文件系统还是搞为xfs(同样挂载到/home)
[centos@localhost opt]$ sudo lvcreate -L 80G -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.
7.lvdisplay查看逻辑卷/home, 有分配到80G空间
--- Logical volume ---
LV Path /dev/centos/home
LV Name home
VG Name centos
LV UUID RfSRc8-tjJW-o1e4-389O-bkLC-6OQ1-30XrLy
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2020-05-19 10:09:34 -0400
LV Status available
# open 0
LV Size 80.00 GiB
Current LE 20480
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
8.激活新建的卷组/home
[centos@localhost opt]$ sudo vgchange -ay centos
3 logical volume(s) in volume group "centos" now active
9.在新建的逻辑卷home上建立xfs文件系统
[centos@localhost opt]$ sudo mkfs -t xfs /dev/centos/home
meta-data=/dev/centos/home isize=512 agcount=16, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=20971520, imaxpct=25
= sunit=64 swidth=64 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=10240, version=2
= sectsz=512 sunit=64 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
10.把这个新逻辑卷home挂载到之前的文件夹/home中
[centos@localhost opt]$ sudo mount /dev/centos/home /home/
11.查看磁盘使用情况,/home目录分配到80G空间。
[centos@localhost opt]$ df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 0 63G 0% /dev/shm
tmpfs 63G 19M 63G 1% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 20G 31G 39% /
/dev/sda2 1014M 216M 799M 22% /boot
tmpfs 13G 8.0K 13G 1% /run/user/42
tmpfs 13G 0 13G 0% /run/user/1000
/dev/mapper/centos-home 80G 33M 80G 1% /home
12.恢复/home目录的内容
$sudo tar -xvf /opt/home.tar -C /
13.把释放出来的空间3.5TB分配给root卷
[centos@localhost ~]$ sudo lvextend -L +3.5TiG /dev/centos/root
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to <3.55 TiB (930304 extents).
Logical volume centos/root successfully resized.
14.使用xfs_growfs扩展文件系统,以确保磁盘认识新扩展的空间
[centos@localhost ~]$ sudo xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=16, agsize=819200 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=64 swidth=64 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=64 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
15.使用df -h查看磁盘扩展情况,/root空间已经扩展到3.6T
[centos@localhost ~]$ df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 0 63G 0% /dev/shm
tmpfs 63G 19M 63G 1% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/mapper/centos-root 3.6T 20G 3.6T 1% /
/dev/sda2 1014M 216M 799M 22% /boot
tmpfs 13G 8.0K 13G 1% /run/user/42
tmpfs 13G 0 13G 0% /run/user/1000
/dev/mapper/centos-home 80G 5.1G 75G 7% /home
结束。
原文:https://www.cnblogs.com/liusingbon/p/12896370.html