CentOS7上lvm分割槽調整(resize2fs: Bad magic number in super-block while trying to open ...)
問題描述:根目錄空間佔用率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備份還原