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

按照阿里云官网教程对云服务器进行磁盘扩容,使用fdisk从新分区,最后使用e2fsck和resize2fs来完成文件系统层面的扩容html

在执行“e2fsck -f /dev/vdb1”命令时报错,若是你的问题和下面的错误同样,能够接着往下看:node

[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 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,也就是分区起始位置有问题ide

由于已经从新建立分区表,因此往前查看了命令记录发现,分区的起始位置在103处,工具

[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: 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进行数据恢复,显然这个不是我要的方法,这个只是分区表损坏,数据并无丢,处理好分区表便可。阿里云

在网上找到的其余老铁的解决思路尝试能够解决,如今从新整理下供你们参考spa

须要使用到parted分区工具,如下操做注意数据备份!!!code

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

# 我在阿里云控制台扩展的分区大小为1024GBorm

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

======= 完毕,呵呵呵呵 ========

相关文章
相关标签/搜索