Je bent niet ingelogd.

  • |

#1 05-Sep-2011 23:31:39

warp
Administrator

HOWTO: Repair a broken Ext4 Superblock in Ubuntu

Bron: Linuxexpresso

All your filesystem checks tell you you’ve a bad superblock, but you cant seem to find how to fix it?
Well, here goes smile

This guide is for ext4 , though I’ll explain how other filesystems can be cured along the way. The easiest way to carry all this out, seeing as your computer probably won’t boot at this stage, is to download and burn a copy of Parted Magic. Boot from that, and you’ll access to a number of useful tools.

First, figure out what partition we’re dealing with.

    1    sudo fdisk -l

The above will list all the partitions on all the drives in your computer. To recover a lost partition, your going to need Testdisk. Testdisk is included in Parted Magic, and there’s a great guide on their site. For this though, we just need the partition number, such as /dev/sda3 or /dev/hdb1.

Now, make sure your superblock is the problem, by starting a filesystem check, replacing xxx with your partition name. Here, you can change ext4 to ext3, or ext2 to suit the filesystem.

    1    sudo fsck.ext4 -v /dev/xxx

If your superblock is corrupt, the output will look like this

    01    fsck /dev/sda5
    02    fsck 1.41.4 (27-Jan-2009)
    03    e2fsck 1.41.4 (27-Jan-2009)
    04    fsck.ext4: Group descriptors look bad... trying backup blocks...
    05    fsck.ext4: Bad magic number in super-block while trying to open /dev/sda5
    06    
    07    The superblock could not be read or does not describe a correct ext4
    08    filesystem.  If the device is valid and it really contains an ext4
    09    filesystem (and not swap or ufs or something else), then the superblock
    10    is corrupt, and you might try running e2fsck with an alternate superblock:
    11    e2fsck -b 8193 <device>

Now lets find where your superblock backups are kept.

    1    sudo mke2fs -n /dev/xxx

Down at the bottom of this output, should be a list of the backups

     
    1    Superblock backups stored on blocks:
    2    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Your almost there. Finally, restore the superblock from the backup, again replacing the x’s with your partition name, and block_number with the first backup superblock.

     
    1    sudo e2fsck -b block_number /dev/xxx

Now reboot, and your superblock should be fixed. If it’s not, repeat the steps, but restore a different backup superblock

Mind You: the filesystem check will force to pass several stages and that may take a while!

Offline

#2 23-Sep-2020 23:35:14

warp
Administrator

HOWTO: Repair a broken Ext4 Superblock in Ubuntu

FSCK Cheat-Sheet:

e2fsck has softlinks in /sbin that one can use to keep the names of fsck tools more uniform. i.e. fsck.ext2, fsck.ext3 and fsck.ext4 (similarly, other filesystem types have e.g.: fsck.ntfs) This cheatsheet will make use of these softlinks and will use ext4 and /dev/sda1 as an example.

    fsck.ext4 -p /dev/sda1 - will check filesystem on /dev/sda1 partition. It will also automatically fix all problems that can be fixed without human intervention. It will do nothing, if the partition is deemed clean (no dirty bit set).

    fsck.ext4 -p -f /dev/sda1 - same as before, but fsck will ignore the fact that the filesystem is clean and check+fix it nevertheless.

    fsck.ext4 -p -f -C0 /dev/sda1 - same as before, but with a progress bar.

    fsck.ext4 -f -y /dev/sda1 - whereas previously fsck would ask for user input before fixing any nontrivial problems, -y means that it will simply assume you want to answer "YES" to all its suggestions, thus making the check completely non-interactive. This is potentially dangerous but sometimes unavoidable; especially when one has to go through thousands of errors. It is recommended that (if you can) you back up your partition before you have to run this kind of check. (see dd command for backing up filesystems/partitions/volumes)

    fsck.ext4 -f -c -C0 /dev/sda1 - will attempt to find bad blocks on the device and make those blocks unusable by new files and directories.

    fsck.ext4 -f -cc -C0 /dev/sda1 - a more thorough version of the bad blocks check.

    fsck.ext4 -n -f -C0 /dev/sda1 - the -n option allows you to run fsck against a mounted filesystem in a read-only mode. This is almost completely pointless and will often result in false alarms. Do not use.

Example: fsck -y -C0 -b 98304 -B 4096 /dev/sdxX

Offline

#3 23-Sep-2020 23:37:55

warp
Administrator

HOWTO: Repair a broken Ext4 Superblock in Ubuntu

LAST RESORT

mkfs.ext4 -S /dev/sdxX -b 4096

-S
    Write superblock and group descriptors only.
This is useful if all of the superblock and backup superblocks are corrupted, and a last-ditch recovery method is desired.
It causes mke2fs to reinitialize the superblock and group descriptors, while not touching the inode table and the block and inode bitmaps.
The e2fsck program should be run immediately after this option is used, and there is no guarantee that any data will be salvageable.
It is critical to specify the correct filesystem blocksize  (like 4096 or 1024) when using this option, or there is no chance of recovery.

mke2fs -O journal_dev [ -b block-size ] [ -L volume-label ] [ -n ] [ -q ] [ -v ] external-journal [ blocks-count ]

Offline

Bulletin Board voettekst