Can read superblock linux

How to Fix “can’t read superblock” Error on Linux (ext4 & Btrfs)

Recently my Linux desktop computer can’t mount my 5TB external hard disk drive (HDD), and the file manager displays the “can’t read superblock” error on the screen. I’m going to share with you what I did to fix the error, so if you are in the same situation, this article may help you.

can

But before doing that, I want to explain some basic knowledge about hard disk drives and filesystems on Linux, so you will really know what you are doing. If you don’t care about those details, you can jump directly to the solution. A hard disk drive (HDD) is magnetic disk. A solid-state drive (SSD) is electronic disk.

The Structure of Hard Disk Drive

A hard disk drive usually has several circular platters stacked vertically with a spindle that rotates the disk in the center. Each platter is coated with a magnetizable material 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 be easily damaged if you drop them to the ground.

Each track is divided into sectors. There are typically hundreds of sectors per track and each sector usually has the same length. A sector is the smallest unit for reading data from the disk. That is to say, even if you just need a portion of the data from a sector, the read-write head will read the entire sector to retrieve the data. Traditionally one sector stores 512 bytes of data. In 2009 the industry devised the 4K sector size format known as the advanced 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 use the 4K advanced format, operating systems still expect 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 can check the physical sector size and logical sector size of an HDD with the fdisk command.

You can see from the screenshot that the physical sector size of my hard disk is 4096 bytes and the logical sector size is 512 bytes. I/O size is the minimal chunks of data the operating system reads from a disk.

fdisk physical sector size logical sector size

Partition Alignment

Using firmware to produce a logical sector can degrade performance, especially when file system partitions are not aligned with physical sectors. There are two requirements for partition alignment:

  • The number of sectors on each partition must be in multiples of 8 because a physical sector contains 8 logical sectors.
  • The start sector of each partition must be the first logical sector in a physical sector. Since sector 0 is the first sector of the entire disk, this means the start sector of each partition should be a multiple of 8, sector 0, sector 8, sector 16, etc.
Читайте также:  Sharing folder in vmware with linux

When you create partitions on a hard disk drive, you should be aware of the following two partition tables.

If you buy a new hard disk, it’s recommended to use the newer GPT format to partition your hard disk. Both MBR and GPT will use some sectors at the beginning of the disk, so you should leave some empty space (like 1MiB) before the first partition. To create partitions that will be aligned with the physical sector, use sector as the unit when you partition your disk.

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

First, tell parted to use your disk. I use my /dev/sdb as an example.

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

align-check opt partition-number

As you can see from the screenshot below, the first two partitions are not properly aligned. The third partition is aligned.

parted alignment check

SSD Partition Alignment

Note that the structure of SSD is very different than that of an HDD. The smallest unit of an SSD module is called a cell. Consecutive cells form a page, 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’s no straightforward way to check page size using the Linux command line, because the flash translation layer makes the OS think the SSD is a traditional hard disk. The OS doesn’t understand SSD pages and still uses sectors to describe locations on SSD.

Common page sizes are 8KiB, 16KiB, 32KiB. It’s also very important to have aligned partitions on SSD. If partitions are misaligned, then there will always be one extra page to read or write. Not only will it degrade performance, but also decreases the life span of SSD. To properly align partitions on SSD, all you need to do is to leave one empty page (e.g. 32KiB) at the start of SSD and make sure the size of every partition on SSD is multiples of the page size.

When you use GParted to create the first partition on SSD, it automatically leaves 1MiB empty space before the first partition, which is 32 empty pages (32 KiB * 32 = 1024 KiB). This is fine. The following screenshot shows creating an EFI system partition (ESP) for a UEFI computer. The partition size is 512MiB with a FAT32 file system.

ssd partition alignment in gparted

Blocks in Filesystem

There’s a concept in filesystem called block, which is similar to a sector on disk drives. Many folks are confused by these two concepts. It’s not really that hard to understand the difference. When you create a partition on a disk, you can use sectors to define its size. If you format a partition with a file system, blocks will be created.

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

Читайте также:  Window manager для линукс

Superblock

The first block of a disk or of a partition is called the superblock, and it’s the primary superblock. Superblock can be damaged like in a sudden power outage, so there are backup copies of the superblock in a block group.

Can’t read superblock

There can 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.
  • There’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

If the primary superblock is damaged, you can’t mount the filesystem, and the operating system will probably tell you that it “can’t read superblock” if you try to mount the filesystem. We need to recover the bad superblock from backup copies. The following instructions show how to recover superblock for ext4 and Btrfs file system. My HDD is an external hard disk. If the damaged filesystem is your root file system, you need to boot your computer from a Linux Live USB stick.

Recover superblock on ext4 filesystem

Find out the device name of the damaged partition.

Determine the location of the backup superblocks.

For example, the device name of my HDD partition is /dev/sdb1, so I run

It will tell you that the partition contains an ext4 file system, press y to continue. Don’t worry the -n option 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 can see the location of backup superblocks. Next, restore the superblock from the first backup copy.

sudo e2fsck -b 32768 /dev/xxx

Now you should be able to mount your ext4 partition.

Recover superblock on btrfs filesystem

Find out the device name of the damaged partition.

sudo apt install btrfs-progs

Then run the following command to recover superblock.

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

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

You might find 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=-5 IO failure BTRFS: error (device sdb1) in btrfs_replay_log:2287: errno=-5 IO failure (Failed to recover log tree)

Then you need to run the following command to clear the filesystem log tree.

sudo btrfs rescue zero-log /dev/xxx

btrfs rescue clear the filesystem log tree

Now you should be able to mount your Btrfs file system.

Читайте также:  Linux отправить на печать

If there’s periodic IO failure for your Btrfs file system, you can add a crontab job to automatically clear the file system log tree once a day.

Add the following line at the end of the crontab file.

@daily umount /dev/xxx && btrfs rescue zero-log /dev/xxx && mount -a

Backing Up Files on your Disk

To prevent data loss, it’s recommended to use a tool like Duplicati to automatically back up your files to cloud storage. Duplicati will encrypt your files to prevent prying eyes.

External HDD becomes Read-only?

Sometimes there can be error in the file system so Linux can only mount the external HDD in read-only mode. To fix it, you need to unmount the external HDD, then use the e2fsck command-line utility to fix the file system errors.

then answer y to optimize or fix the file system, and you will be able to mount the external HDD in writable mode.

Tip

  • Some motherboards can still charge USB devices when you shut down the operating system. If you have an external HDD, it’s recommended to turn off electricity for USB devices when shut down, so your external HDD can stop spinning. This is good for its life span. For example, I have an ASUS PRIME z270 motherboard. I go to the UEFI advanced settings section and disable “charging USB devices in power state s5”.

Wrapping Up

I hope this tutorial helped you fix the “can not read superblock” error on Linux. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂

Источник

How to fix if I received mount: /dev/vgname/lvname: can’t read superblock for the local filesystem?

In my case I received this error due to an read-only abstraction mount below it. I was using vmfs6-fuse in combination with an qemu-nbd read-only mount for a VMWARE recovery.

In this case, mounting the LVM with the option ro,noload solved the issue:

mount -o ro,noload /dev/vg/lv /mnt 

If the logical volume exists and is active, it may be that the superblock is somehow corrupted. If the filesystem is an ext2, ext3 or ext4, there are backup superblocks available. To find them:

dumpe2fs /dev/vgname/lvname | grep superblock 

You will get some output like:

$ sudo dumpe2fs /dev/sdb1 | grep uperb | more dumpe2fs 1.45.4 (23-Sep-2019) Primary superblock at 0, Group descriptors at 1-25 Backup superblock at 32768, Group descriptors at 32769-32793 Backup superblock at 98304, Group descriptors at 98305-98329 Backup superblock at 163840, Group descriptors at 163841-163865 Backup superblock at 229376, Group descriptors at 229377-229401 Backup superblock at 294912, Group descriptors at 294913-294937 Backup superblock at 819200, Group descriptors at 819201-819225 Backup superblock at 884736, Group descripmount sb=32768 /dev/sda2 /mnttors at 884737-884761 

You can probably mount the filesystem with:

mount sb=32768 /dev/vgname/lvname /mnt 

(the 32768 being the first backup superblock from the previous output)

If that works, you can backup some important files and/or start a repair:

fsck -b 32768 /dev/vgname/lvname 

You could try fsck -y if you don’t want to acknowledge all repair.

If none of the backup superblocks work, you must hope that your last backup is valid, or try recovery tools like ext4magic , PhotoRec or scalpel .

If everything fails, re-initialise with mkfs.ext4 . Make sure that you do bad block checking.

Источник

Оцените статью
Adblock
detector