Bad Magic Number In Superblock

The Server will go down due to issues in disks attached. Sometimes fsck in disks ends up in an error “Bad magic number in Superblock while trying to open /dev/sdb”.

What do you mean by superblock?

The superblock means a file system metadata (data of a data) that describes the size, type, and status of the file system and information regarding other metadata structures. It is very significant to the file system. Hence, for each file system, the superblock is retained in multiple redundant copies. If the superblock of a partition is corrupt, we are not able to mount the file system of partition by operating system.

What is a magic number?

Magic numbers are the first few bytes of a file which are unique to a particular file type and they are also called file signature. Magic numbers/File signatures are t not visible to the user.

How can see information about superblock and magic number?

We can view superblock header of an existing file system using dumpe2fs

# dumpe2fs -h /dev/sdb
[root@sss ~]# dumpe2fs -h /dev/sdb
dumpe2fs 1.42.9 (28-Dec-2013)
Filesystem volume name:<none>
Last mounted on:<not available>
Filesystem UUID:d6cd4d1a-c69f-4e81-8e7a-ed6cf0be68db
Filesystem magic number:0xEF53
Filesystem revision #:1 (dynamic)
Filesystem features:has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:signed_directory_hash
Default mount options:user_xattr acl
Filesystem state:clean
Errors behavior:Continue
Filesystem OS type:Linux
Inode count:720896
Block count:2883584
Reserved block count:144179
Free blocks:2795308
Free inodes:720885
First block:0
Block size:4096
Fragment size:4096
Group descriptor size:64
Reserved GDT blocks:1024
Blocks per group:32768
Fragments per group:32768
Inodes per group:8192
Inode blocks per group:512
Flex block group size:16
Filesystem created:Wed Dec 20 02:33:43 2017
Last mount time:Wed Dec 20 02:34:40 2017
Last write time:Wed Dec 20 02:34:40 2017
Mount count:1
Maximum mount count:-1
Last checked:Wed Dec 20 02:33:43 2017
Check interval:0
Lifetime writes:132 MB
Reserved blocks uid:0 (user root)
Reserved blocks gid:0 (group root)
First inode:11
Inode size:256
Required extra isize:28
Desired extra isize:28
Journal inode:8
Default directory hash:half_md4
Directory Hash Seed: c577c1b0-aaa9-4d27-b5e6-54bd5b9540d1
Journal backup: inode blocks
Journal features: journal_64bit
Journal size: 128M
Journal length: 32768
Journal sequence: 0x00000002
Journal start: 1

In order to view the magic number of a file, we need to install xxd command Note that plain text files do not have the magic number.

#yum install vim-common -y

#xxd img-1500x1032-data.jpg |head
[root@sss ~]# xxd img-1500x1032-data.jpg |head
0000000: ffd8 ffe0 0010 4a46 4946 0001 0101 0048 ......JFIF.....H
0000010: 0048 0000 ffe1 17f2 4578 6966 0000 4d4d .H......Exif..MM
0000020: 002a 0000 0007 0008 0112 0003 0000 0001 .*..............
0000030: 0001 0000 011a 0005 0000 0001 0000 0063 ...............b
0000040: 011b 0005 0000 0001 0000 006a 0148 0003 ...........j.(..
0000050: 0000 0001 0002 0000 0121 0002 0000 001e .........1......
0000060: 0000 0072 0142 0002 0000 0014 0000 008f ...r.2..........
0000070: 8769 0004 0000 0001 0000 00a3 0000 00cd .i..............
0000080: 000a fc80 0000 2710 000a fc80 0000 2710 ......'.......'.
0000090: 4164 6f62 6520 5068 6f74 6f73 686f 7020 Adobe Photoshop

What is “Bad magic number in superblock”?

The magic number of the file system is stored in the Superblock. This magic number is used by OS to determine which is the file system related to disk /dev/sdb

[root@sss ~]# dumpe2fs -h /dev/sdb |grep -i magic
dumpe2fs 1.42.9 (28-Dec-2013)
Filesystem magic number: 0xEF53

A Bad magic number in superblock error is a clear indication that the operating system is not able to determine file system type of /dev/sdb using superblock data.

Solution
1) Find the backup of superblocks using dumpe2fs or mke2fs

dumpe2fs will work on mounted or unmounted disk but mke2fs require disk unmounted.

#dumpe2fs -h /dev/sdb

[root@sss ~]# dumpe2fs /dev/sdb |grep -i superblock
dumpe2fs 1.42.9 (28-Dec-2013)
Primary superblock at 0, Group descriptors at 1-2
Backup superblock at 32768, Group descriptors at 32769-32770
Backup superblock at 98304, Group descriptors at 98305-98306
Backup superblock at 163840, Group descriptors at 163841-163842
Backup superblock at 229376, Group descriptors at 229377-229378
Backup superblock at 294912, Group descriptors at 294913-294914
Backup superblock at 819200, Group descriptors at 819201-819202
Backup superblock at 884736, Group descriptors at 884737-884738
Backup superblock at 1605632, Group descriptors at 1605633-1605634
Backup superblock at 2654208, Group descriptors at 2654209-2654210

[root@sss ~]# #mke2fs -n /dev/sdb
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
720896 inodes, 2883584 blocks
144179 blocks (5.00%) reserved for the superuser
First data block=0
Maximum filesystem blocks=2952790016
88 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32769, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

2) Replace the superblock using the backup superblock

#fsck -b 32768 /dev/sdb
or
#mount sb=32768 /dev/sdb /mountpoint
or
#e2fsck -b 32768 /dev/sdb

If we are getting the same error with superblock located on 32768, repeat the step with another superblock location.