故障處理:磁盤擴容出錯:e2fsck: Bad magic number in super-block while trying to open /dev/vdb1
按照阿裏雲官網教程對雲服務器進行磁盤擴容,使用fdisk重新分區,最後使用e2fsck和resize2fs來完成文件系統層面的擴容
在執行“e2fsck -f /dev/vdb1”命令時報錯,如果你的問題和下面的錯誤一樣,可以接著往下看:
[root@aliyunsrv ~]# e2fsck -f /dev/vdb1 e2fsck 1.41.12 (17-May-2010) e2fsck: Superblock invalid, trying backup blocks... e2fsck: Bad magic number in super-block while trying to open /dev/vdb1 The superblock could not be read or does not describe a correct ext2 filesystem. If the device is valid and it really contains an ext2 filesystem (and not swap or ufs or somethingelse), then the superblock is corrupt, and you might try running e2fsck with an alternate superblock: e2fsck -b 8193 <device>
按照提示執行“e2fsck -b 8193 /dev/vdb1”,並沒有什麽用
根據報錯信息推測是該工具並沒有找到super-block,也就是分區起始位置有問題
因為已經重新創建分區表,所以往前查看了命令記錄發現,分區的起始位置在103處,
[root@aliyunsrv ~]# fdisk -l Disk /dev/vda: 53.7GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00078f9c Device Boot Start End Blocks Id System /dev/vda1 * 16527 52426752 83 Linux Disk /dev/vdb: 536.9 GB, 536870912000 bytes 2 heads, 10 sectors/track, 52428800 cylinders Units = cylinders of 20 * 512 = 10240 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x63c3e6e0 Device Boot Start End Blocks Id System /dev/vdb1 103 52428800 524286976 83 Linux # 分區起始位置在103,很重要,需要確定
由此其實可以推測出阿裏雲的磁盤擴容最近可能出問題了,之前分區我寫的必定是1,但是擴容後就變了,這個應該是導致這個問題的原因
提阿裏雲工單得到的結果是用testdisk進行數據恢復,顯然這個不是我要的方法,這個只是分區表損壞,數據並沒有丟,處理好分區表即可。
在網上找到的其他老鐵的解決思路嘗試可以解決,現在重新整理下供大家參考
需要使用到parted分區工具,以下操作註意數據備份!!!
1.使用parted工具讀取磁盤分區表信息
# 我在阿裏雲控制臺擴展的分區大小為1024GB
parted /dev/vdb
2.刪除舊的錯誤分區表
# 在parted交互式分區工具中執行
(parted) rm 1
註意:分區表用parted工具刪除後無法直接使用fdisk進行分區
3.使用parted工具恢復之前正常的分區表
# 在parted交互式分區工具中執行
(parted) unit s (parted) rescue 103 1099GB
這裏根據之前的分區起始位置確認是103扇區,由於parted工具默認啟動、結束位置單位都是用容量單位即kB/MB/GB,所以需要通過unit s命令定義默認使用sectors定義起始扇區。
完整的操作如下:
[root@aliyunsrv ~]# parted /dev/vdb GNU Parted 2.1 Using /dev/vdb Welcome to GNU Parted! Type ‘help‘ to view a list of commands. (parted) p # 打印分區表 Model: Virtio Block Device (virtblk) Disk /dev/vdb: 1100GB # 分區容量 Sector size (logical/physical): 512B/512B Partition Table: msdos # 分區表類型 Number Start End Size Type File system Flags 1 5120B 1100GB 1099GB primary # 當前的分區表信息,是不可用的 (parted) rm 1 # 刪除1號分區 (parted) unit s # 使用扇區號 (parted) rescue 103 1099GB # 恢復分區表 Information: A ext4 primary partition was found at 2048s -> 1048575999s. Do you want to add it to the partition table? # 找到了ext4格式的分區,起始扇區定位到2048,結束扇區是1048575999(推測的,如有問題歡迎指正) Yes/No/Cancel? y # 是否要創建該分區表,也就是恢復舊的分區表 (parted) p Model: Virtio Block Device (virtblk) Disk /dev/vdb: 2147483648s Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 2048s 1048575999s 1048573952s primary ext4 # 可以看到這個是正確的磁盤分區表 (parted) q Information: You may need to update /etc/fstab.
4.重新創建新的分區表
這裏需要註意的是parted工具裏END的值,由於磁盤的扇區數量不容易確定,可以使用容量來替代
[root@aliyunsrv ~]# parted /dev/vdb GNU Parted 2.1 Using /dev/vdb Welcome to GNU Parted! Type ‘help‘ to view a list of commands. (parted) p Model: Virtio Block Device (virtblk) Disk /dev/vdb: 1100GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 537GB 537GB primary ext4 # 重新打開後發現分區表的顯示格式有變化,但並不影響,同時也可以看出來是以前的分區表(未擴容前) (parted) rm 1 # 刪除舊的分區表 (parted) p Model: Virtio Block Device (virtblk) Disk /dev/vdb: 1100GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags (parted) unit s (parted) mkpart primary ext4 2048 1099GB # 創建新的分區表,註意要使用前文獲取的扇區起始位置2048 (parted) p Model: Virtio Block Device (virtblk) Disk /dev/vdb: 2147483648s Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 2048s 2146484223s 2146482176s primary ext4 # 新的分區表 (parted) q Information: You may need to update /etc/fstab.
此時新的分區表就創建成功了,需要註意:是使用的parted工具創建的分區表!!!
如果想使用fdisk進行分區,可以在fdisk中使用2048起始扇區進行測試,註意數據備份!!!
[root@aliyunsrv ~]# e2fsck -f /dev/vdb1 e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vdb1: 237246/32768000 files (75.3% non-contiguous), 112383325/131071744 blocks
可以正常執行檢查文件系統的操作
[root@aliyunsrv ~]# resize2fs /dev/vdb1 resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/vdb1 to 268310272 (4k) blocks. The filesystem on /dev/vdb1 is now 268310272 blocks long.
可以正常執行確認變更文件系統大小的操作,執行完即可掛在使用
最後使用工具檢查分區表狀態,供參考
[root@aliyunsrv ~]# parted /dev/vdb GNU Parted 2.1 Using /dev/vdb Welcome to GNU Parted! Type ‘help‘ to view a list of commands. (parted) p Model: Virtio Block Device (virtblk) Disk /dev/vdb: 1100GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 1099GB 1099GB primary ext4
fdisk工具查看的信息
[root@aliyunsrv ~]# fdisk -l Disk /dev/vda: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00078f9c Device Boot Start End Blocks Id System /dev/vda1 * 1 6527 52426752 83 Linux Disk /dev/vdb: 1099.5 GB, 1099511627776 bytes 255 heads, 63 sectors/track, 133674 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000ead8a Device Boot Start End Blocks Id System /dev/vdb1 1 133613 1073241088 83 Linux
附上提供幫助老鐵的文章鏈接:
https://bbs.aliyun.com/read/272957.html?pos=4
完畢,呵呵呵呵
故障處理:磁盤擴容出錯:e2fsck: Bad magic number in super-block while trying to open /dev/vdb1