disk-故障处理:磁盘扩容出错:e2fsck: Bad magic number in super-block while trying to open /dev/vdb1

磁盘扩容出错:e2fsck: Bad magic number in super-block while trying to open /dev/vdb1

1.故障现象及分析

  • 按照阿里云官网教程对云服务器进行磁盘扩容,使用 fdisk 重新分区,最后使用 e2fsck 和 resize2fs 来完成文件系统层面的扩容,在执行“e2fsck -f /dev/vdb1”命令时报错,
  • 如果你的问题和下面的错误一样,可以接着往下看
[root@zuiyoujie ~]# 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 something else), 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,也就是分区起始位置有问题

1.1.故障分析

  • 查看当前磁盘分区信息
[root@zuiyoujie ~]# 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: 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,很重要,需要记录
  • 确认当前磁盘分区 /dev/vdb1 的起始位置(起始柱面)在 103 处
  • 默认起始柱面应该是像上面 /dev/vda1 分区以 1 开始,或者是常见的 2048,大多数人不会随意指定类似这样的起始柱面
  • 之前分区我创建分区必定是 1,但是扩容后就变了,这个应该是导致故障的原因,推测可能阿里云的磁盘扩容可能出问题了,不过这个不重要

1.2.解决思路

  • 提阿里云工单得到的结果是,用 testdisk 进行数据恢复,显然这个不是我要的方法

  • 这个只是分区表损坏,数据并没有丢,处理好分区表即可

  • 参考 网络大神 的思路进行解决,并重新重新整理下供大家参考


2.故障处理

  • 以下操作注意数据备份!!!
  • 在 parted 交互式分区工具中执行

2.1.使用 parted 工具读取磁盘分区表信息

# 我在阿里云控制台扩展的分区大小为 1024 GB
parted /dev/vdb
---------------------------
[root@zuiyoujie ~]# parted /dev/vdb
GNU Parted 2.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) help                             # 获取帮助信息
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted

(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      # 当前的分区表信息,是不可用的,实际可用的分区容量为 1099GB
-----------------

2.2.使用 parted 工具删除错误分区表并重建

  • parted 工具默认启动、结束位置,单位都是用容量 kB/MB/GB 单位进行处理
  • 通过 unit s 命令定义,默认使用 sectors 定义起始扇区
  • 根据之前获取的信息分区起始位置确认是 103 扇区
(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.
  • 注意:分区表用 parted 工具删除后无法直接使用 fdisk 进行分区,也请不要尝试这样操作

2.3.使用 parted 工具重新创建新的分区表

  • 这里需要注意的是 parted 工具里 END 的值,由于磁盘的扇区数量不方便确定,可以使用容量来替代
[root@zuiyoujie ~]# 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 工具创建的分区表!!!

2.4.使用 fdisk 工具进行分区

  • 如果想使用 fdisk 进行分区,可以在 fdisk 中使用 2048 起始扇区进行操作,注意数据备份!!!

  • 重新检查磁盘分区,确认可以正常执行检查文件系统的操作

[root@zuiyoujie ~]# 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

2.5.继续扩容操作

  • 可以正常执行确认变更文件系统大小的操作,执行完即可挂载使用
[root@zuiyoujie ~]# 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.

2.6.使用工具检查分区表状态

  • parted 工具检查分区表信息
[root@zuiyoujie ~]# 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@zuiyoujie ~]# 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

10.参考地址:

https://bbs.aliyun.com/read/272957.html?pos=4
  • END
posted @ 2018-06-12 21:18  天生帅才  阅读(28443)  评论(0编辑  收藏  举报
// 百度统计