共计 3875 个字符,预计需要花费 10 分钟才能阅读完成。
/home目录过大,根目录/空间却很小,根目录扩容
由于当时分配时,没有选好,导致/home目录过大,根目录/空间却很小:
[root@localhost ~]# df -h
df: /run/user/0/gvfs: Transport endpoint is not connected
df: /run/user/0/gvfs: Transport endpoint is not connected
Filesystem Size Used Avail Use% Mounted on
devtmpfs 126G 0 126G 0% /dev
tmpfs 126G 144K 126G 1% /dev/shm
tmpfs 126G 692M 126G 1% /run
tmpfs 126G 0 126G 0% /sys/fs/cgroup
/dev/mapper/cl-root 50G 50G 419M 100% /
/dev/mapper/cl-home 14T 134G 14T 1% /home
/dev/sda2 976M 268M 641M 30% /boot
/dev/sda1 599M 7.3M 592M 2% /boot/efi
tmpfs 26G 16K 26G 1% /run/user/42
tmpfs 26G 36K 26G 1% /run/user/0
可以看到我们只给根目录目录下面挂载了,50G的空间,显然不够使用。
接下来我们查看一下逻辑卷组的信息
[root@localhost ~]# vgdisplay #查看逻辑卷组
--- Volume group ---
VG Name cl
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 13.97 TiB
PE Size 4.00 MiB
Total PE 3662153
Alloc PE / Size 3662153 / 13.97 TiB
Free PE / Size 0 / 0
[root@localhost ~]# lvdisplay ##查看逻辑卷情况,默认三个,root、home和交换空间swap
--- Logical volume ---
LV Path /dev/cl/swap
LV Name swap
VG Name cl
LV Write Access read/write
LV Creation host, time localhost, 2023-04-05 22:52:59 +0800
LV Status available
# open 2
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/cl/home
LV Name home
VG Name cl
LV Write Access read/write
LV Creation host, time localhost, 2023-04-05 22:53:00 +0800
LV Status available
# open 1
LV Size <13.92 TiB
Current LE 3648329
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/cl/root
LV Name root
VG Name cl
LV Write Access read/write
LV Creation host, time localhost, 2023-04-05 22:53:21 +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 8192
Block device 253:0
操作步骤:
1、备份/home (不要在/home目录执行该命令)
mkdir /mnt
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/cl/home
5、查看逻辑卷组可用空间
[root@localhost ~]# vgdisplay #可以看到现在又13.92TB的空余空间未分配
--- Volume group ---
VG Name cl
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 13.97 TiB
PE Size 4.00 MiB
Total PE 3662153
Alloc PE / Size 13824 / 54.00 GiB
Free PE / Size 3648329 / <13.92 TiB
6、新建一个卷home,fdisk格式化,文件系统还是搞为xfs(同样挂载到/home)
lvcreate -L 5120G -n home cl #大小5T
mkfs -t xfs /dev/cl/home
7、激活卷组(cl是卷组名)
[root@localhost ~]# vgchange -ay cl
3 logical volume(s) in volume group "cl" now activevgchange -ay cl
8、把这个新逻辑卷home挂载到之前的文件夹/home中
mount /dev/cl/home /home/
9、查看是否挂载成功
[root@localhost ~]# df -h #可以看到/home已经变大了
Filesystem Size Used Avail Use% Mounted on
devtmpfs 126G 0 126G 0% /dev
tmpfs 126G 144K 126G 1% /dev/shm
tmpfs 126G 692M 126G 1% /run
tmpfs 126G 0 126G 0% /sys/fs/cgroup
/dev/mapper/cl-root 50G 48G 2.5G 96% /
/dev/sda2 976M 268M 641M 30% /boot
/dev/sda1 599M 7.3M 592M 2% /boot/efi
tmpfs 26G 16K 26G 1% /run/user/42
tmpfs 26G 32K 26G 1% /run/user/0
/dev/mapper/cl-home 5.0T 36G 5.0T 1% /home
10、恢复/home数据
tar -xvf /mnt/home.tar -C /
rm -rf /mnt/
11、将剩余的空间分配给根目录/即可
[root@localhost /]# vgdisplay #可以看到还有8.92 TiB的空间
--- Volume group ---
VG Name cl
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 8
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 13.97 TiB
PE Size 4.00 MiB
Total PE 3662153
Alloc PE / Size 1324544 / 5.05 TiB
Free PE / Size 2337609 / <8.92 TiB
[root@localhost ~]# lvextend -L +8.9TiB /dev/cl/root #注意这里添加的空间不要写8.92,因为不可能全部的空间都可用,还有一些索引的信息,所以要小一点
Rounding size to boundary between physical extents: 8.90 TiB.
Size of logical volume cl/root changed from 50.00 GiB (12800 extents) to <8.95 TiB (2345882 extents).
Logical volume cl/root successfully resized.
[root@localhost ~]# xfs_growfs /dev/cl/root #使用xfs_growfs扩展文件系统,以确保磁盘认识新扩展的空间
12、使用df -h查看磁盘情况,已经扩展了/目录
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 126G 0 126G 0% /dev
tmpfs 126G 144K 126G 1% /dev/shm
tmpfs 126G 692M 126G 1% /run
tmpfs 126G 0 126G 0% /sys/fs/cgroup
/dev/mapper/cl-root 9.0T 82G 8.9T 1% /
/dev/sda2 976M 268M 641M 30% /boot
/dev/sda1 599M 7.3M 592M 2% /boot/efi
tmpfs 26G 16K 26G 1% /run/user/42
tmpfs 26G 32K 26G 1% /run/user/0
/dev/mapper/cl-home 5.0T 66G 5.0T 2% /home
正文完