Recently my Linux desktop computer can't mountain my 5TB external hard disk bulldoze (HDD), and the file manager displays the "can't read superblock" fault on the screen. I'one thousand going to share with you what I did to fix the fault, then if y'all are in the same state of affairs, this article may assist you.

can't read superblock

Merely earlier doing that, I desire to explicate some basic knowledge about hard disk drives and filesystems on Linux, and so yous will really know what you lot are doing. If you don't care about those details, you can jump direct to the solution. A hard disk drive (HDD) is magnetic deejay. A solid-state bulldoze (SSD) is electronic disk.

The Structure of Hard disk Drive

A hard disk bulldoze unremarkably has several circular platters stacked vertically with a spindle that rotates the deejay in the center. Each platter is coated with a magnetizable textile to record data. Each platter surface is divided into tens of thousands of tracks. It's like running tracks in sports.

can't read superblock linux

Hint: Hard disk drives are very complex devices and can exist easily damaged if you drop them to the ground.

Each track is divided into sectors. There are typically hundreds of sectors per rail and each sector usually has the aforementioned length. A sector is the smallest unit for reading data from the disk. That is to say, even if you simply need a portion of the data from a sector, the read-write head will read the entire sector to retrieve the information. Traditionally ane sector stores 512 bytes of data. In 2009 the manufacture devised the 4K sector size format known as the avant-garde format to improve disk reliability and increase capacity. After January 2011, most new hard drives store 4096 bytes of data in one sector.

Physical Sector Size vs Logical Sector Size

Although new hard drives utilise the 4K advanced format, operating systems yet look a 512 bytes sector size, so the firmware on the HDD divides a 4K physical sector into several logical sectors, typically 512 bytes. On Linux, you lot can cheque the physical sector size and logical sector size of an HDD with the fdisk command.

fdisk -fifty /dev/sda

You lot can run across from the screenshot that the physical sector size of my hard deejay is 4096 bytes and the logical sector size is 512 bytes. I/O size is the minimal chunks of data the operating organisation reads from a deejay.

fdisk physical sector size logical sector size

Division Alignment

Using firmware to produce a logical sector can dethrone operation, specially when file system partitions are not aligned with physical sectors. There are 2 requirements for sectionalisation alignment:

  • The number of sectors on each partition must be in multiples of eight because a physical sector contains 8 logical sectors.
  • The start sector of each partition must exist the first logical sector in a physical sector. Since sector 0 is the start sector of the entire disk, this means the start sector of each partition should be a multiple of viii, sector 0, sector 8, sector 16, etc.

When y'all create partitions on a hd, yous should be aware of the following two partition tables.

  • MBR: Master Kick Record.
  • GPT: GUID Partition Table.

If you buy a new hard deejay, it'southward recommended to utilise the newer GPT format to segmentation your hard disk drive. Both MBR and GPT will use some sectors at the commencement of the disk, so you should leave some empty space (similar 1MiB) before the first partition.  To create partitions that will exist aligned with the concrete sector, use sector as the unit when you partition your deejay.

You can quickly check if your deejay partitions are aligned with physical sectors with the parted (partition editor) utility. parted is a deejay sectionalization editor that supports multiple sectionalization tabular array formats, including MBR and GPT.

Beginning, tell parted to use your disk. I use my/dev/sdb every bit an example.

parted /dev/sdb

Then type p to print the partition table on the disk. And run the following command to bank check partition alignment.

align-check opt                division-number              

Type q to quit.

Every bit you lot can meet from the screenshot below, the first two partitions are not properly aligned. The 3rd partition is aligned.

parted alignment check

SSD Partition Alignment

Note that the construction of SSD is very different than that of an HDD. The smallest unit of measurement of an SSD module is chosen a cell. Consecutive cells form a folio, many of which are organized into a block. Read and write operations are executed at the page level. The page size of an SSD varies from manufacturer to manufacturer and from model to model. There'due south no straightforward fashion to bank check page size using the Linux control line, considering the flash translation layer makes the Os think the SSD is a traditional hard disk. The OS doesn't understand SSD pages and nevertheless uses sectors to describe locations on SSD.

Common page sizes are 8KiB, 16KiB, 32KiB. Information technology's also very important to have aligned partitions on SSD. If partitions are misaligned, then there volition always be one extra page to read or write. Not only will it degrade functioning, but also decreases the life span of SSD. To properly align partitions on SSD, all you need to do is to go out one empty page at the offset of SSD and make sure the size of every partitioning on SSD is multiples of the page size.

Blocks in Filesystem

At that place'south a concept in filesystem called block, which is similar to a sector on disk drives. Many folks are confused past these two concepts. It'south not really that hard to sympathize the difference. When you create a partition on a disk, you tin can use sectors to ascertain its size. If you format a partition with a file system, blocks will be created.

Operating system and file system admission information on the disk in blocks rather than in sectors. A block is normally a multiple of sector. So why don't we merely access data in sectors? Well, the block can abstract away the physical details of the disk. If you address a sector (find out the accost of a sector), you need to utilize the CHS scheme (cylinder-head-sector). This is because a hard disk drive has multiple platters. You need to know which platter and rail the sector is located at. If you lot address a block, you just use block 0, block 1, cake 2, etc, without having to know the physical details of the deejay. Each block is mapped to a sector (or several sectors) with the logical block addressing (LBA) scheme.

Superblock

The offset block of a deejay or of a partition is chosen the superblock, and it's the main superblock. Superblock can be damaged like in a sudden power outage, so there are backup copies of the superblock in a block group.

  • primary superblock
  • fill-in superblock

Can't read superblock

In that location tin be several reasons why your Os can't read the superblock on your HDD.

  • The HDD is dropped to the ground and the superblock is damaged. This is usually physical damage to the corresponding sectors on the disk.
  • At that place's a sudden power outage. Because the superblock is cached in RAM, if a power outage happens, there might be important changes to the superblock that hasn't been written to the disk.

can't read superblock

If the master superblock is damaged, you can't mount the filesystem, and the operating organisation will probably tell you that it "can't read superblock" if you try to mountain the filesystem. We need to recover the bad superblock from backup copies. The following instructions prove how to recover superblock for ext4 and Btrfs file organisation. My HDD is an external hard disk. If the damaged filesystem is your root file system, you need to kicking your estimator from a Linux Live USB stick.

Recover superblock on ext4 filesystem

Find out the device name of the damaged partition.

sudo parted -fifty

Decide the location of the backup superblocks.

sudo mke2fs -northward /dev/thirty              

It will tell you that the partition contains an ext4 file system, press y to proceed. Don't worry the -n selection tells mke2fs not to create a file system.

mke2fs 1.45.5 (07-Jan-2020)   /dev/sdb1 contains a ext4 file system labelled 'Stretch'   	last mounted on /media/linuxbabe/b43e4eea-9796-4ac6-9c48-2bcaa46353732 on Thu Jan 28 02:43:43 2021   Proceed anyway? (y,N)                y                Creating filesystem with 7864320 4k blocks and 1966080 inodes   Filesystem UUID: fcae3dc8-ee11-412c-97f0-27106601314e   Superblock backups stored on blocks:    	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,    	4096000              

At the bottom, you lot can see the location of backup superblocks. Next, restore the superblock from the showtime fill-in re-create.

sudo e2fsck -b 32768 /dev/xxx              

Now you should exist able to mountain your ext4 partition.

Recover superblock on btrfs filesystem

Find out the device name of the damaged partition.

sudo parted -l

So run the post-obit control to recover superblock.

sudo btrfs rescue super-recover -5 /dev/xxx              

If it tells you "All supers are valid, no need to recover", then check the syslog.

sudo dmesg

You might detect the following message, which indicates the log tree is corrupted, so it can't replay the log.

BTRFS: error (device sdb1) in btrfs_run_delayed_refs:2227: errno=-v IO failure   BTRFS: fault (device sdb1) in btrfs_replay_log:2287: errno=-5 IO failure (Failed to recover log tree)

Then yous need to run the post-obit command to articulate the filesystem log tree.

sudo btrfs rescue zero-log /dev/30              

btrfs rescue clear the filesystem log tree

Now yous should exist able to mount your Btrfs file arrangement.

Backing Upwardly Files on your Disk

To prevent data loss, it's recommended to use a tool similar Duplicati to automatically back up your files to cloud storage. Duplicati volition encrypt your files to forestall prying optics.

Wrapping Upwardly

I hope this tutorial helped yous fix the "tin can not read superblock" fault on Linux. As always, if you constitute this mail service useful, then [Total: 0 Average: 0]