/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 /mnt/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
結束。
