问题描述:根目录空间占用率100%
首先用传统resize2fs方式调整分区:
resize2fs -p /dev/mapper/centos-home 50G
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-home
Couldn't find valid filesystem superblock.
报错原因是因为文件系统是xfs(fdisk -l查看),不再支持resize2fs
解决思路:
①确认分区类型为lvm
②查看到home分区有大量闲置空间,决定将home的空间分配给 /
卸载home >> 删除home >> 将home的空间添加到 " / " >> 重新分配home >> 格式化home >> 完成
会用到的命令:
df -h # 查看磁盘空间
lsblk # 查看块设备详情
fdisk -l # 查看分区详情
lvremove\lvcreate # 逻辑卷删除/创建
lvdisplay\vgdisplay\pvdisplay #查看逻辑卷/卷组/物理卷
xfs_growfs # 加载xfs_growfs
操作过程:
1、分析:查看分区详情,看到sda2为lvm逻辑卷,所以可以通过将home的空间转移到根分区
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8:0 0 300G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 299.5G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 9.8G 0 lvm [SWAP] └─centos-home 253:2 0 239.6G 0 lvm /home sr0 11:0 1 1024M 0 rom
2、/home备份
# mkdir /tmp/home # cp -r /home/* /tmp/home
3、umount卸载
# umount /home umount: /home: target is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1)) # 如果提示busy,则使用fuser解除占用 # fuser -m -v -i -k /home
4、删除home逻辑卷(lv),将home的空间腾出来到卷组(vg)
# lvremove /dev/mapper/centos-home Do you really want to remove active logical volume home? [y/n]: y Logical volume "home" successfully removed
5、重新调整 / 的大小
# lvextend -L 250G /dev/mapper/centos-root # 调整到250G Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 250.00 GiB (64000 extents). Logical volume root successfully resized.
xfs_growfs刷新
# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=3276800 blks = sectsz=4096 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=13107200, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 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 65536000
6、将剩下的空间重新划分到home中
# lvcreate -l +100%free -n home centos # -n 指定lv的名字,centos是vg的名字 Logical volume "home" created.
创建完成别忘了格式化
# mkfs.xfs /dev/centos/home meta-data=/dev/centos/home isize=256 agcount=4, agsize=2601472 blks = sectsz=4096 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=10405888, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=5081, version=2 = sectsz=4096 sunit=1 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
7、重新mount并查看
# mount /dev/mapper/centos-home /home
8、完成
9、别忘了把home备份还原
文章来源:https://www.cnblogs.com/-abm/p/11349240.html