{"id":58,"date":"2017-10-30T00:13:43","date_gmt":"2017-10-30T00:13:43","guid":{"rendered":"http:\/\/tajdini.net\/blog\/?p=58"},"modified":"2020-12-20T11:17:55","modified_gmt":"2020-12-20T09:17:55","slug":"howto-repair-a-broken-ext4-superblock-in-ubuntu","status":"publish","type":"post","link":"https:\/\/tajdini.net\/blog\/cloud-and-devsecops\/howto-repair-a-broken-ext4-superblock-in-ubuntu\/","title":{"rendered":"HOWTO: Repair a broken Ext4 Superblock in Ubuntu"},"content":{"rendered":"<p>This has happened to me a few times, and it\u2019s not a nice problem to find yourself in. You computer won\u2019t boot, all your filesystem checks tell you you\u2019ve a bad superblock, but you cant seem to find how to fix it. Well, here goes \ud83d\ude42<\/p>\n<p>This guide is for ext4 , though I\u2019ll explain how other filesystems can be cured along the way. The easiest way to carry all this out, seeing as your computer probably won\u2019t boot at this stage, is to download and burn a copy of Parted Magic. Boot from that, and you\u2019ll access to a number of useful tools.<\/p>\n<p>First, figure out what partition we\u2019re dealing with.<\/p>\n<blockquote>\n<div>\n<div id=\"highlighter_592736\" class=\"syntaxhighlighter bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash functions\">sudo<\/code> <code class=\"bash functions\">fdisk<\/code> <code class=\"bash plain\">-l<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/blockquote>\n<p>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\u2019s a great guide on their site. For this though, we just need the partition number, such as \/dev\/sda3 or \/dev\/hdb1.<\/p>\n<p>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.<\/p>\n<blockquote>\n<div>\n<div id=\"highlighter_212804\" class=\"syntaxhighlighter bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash functions\">sudo<\/code> <code class=\"bash functions\">fsck<\/code><code class=\"bash plain\">.ext4 -<\/code><code class=\"bash functions\">v<\/code> <code class=\"bash plain\">\/dev\/xxx<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/blockquote>\n<p>If your superblock is corrupt, the output will look like this<\/p>\n<blockquote>\n<div>\n<div id=\"highlighter_216630\" class=\"syntaxhighlighter bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash functions\">fsck<\/code> <code class=\"bash plain\">\/dev\/sda5<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"bash functions\">fsck<\/code> <code class=\"bash plain\">1.41.4 (27-Jan-2009)<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"bash plain\">e2fsck 1.41.4 (27-Jan-2009)<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"bash functions\">fsck<\/code><code class=\"bash plain\">.ext4: Group descriptors <\/code><code class=\"bash functions\">look<\/code> <code class=\"bash plain\">bad... trying backup blocks...<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"bash functions\">fsck<\/code><code class=\"bash plain\">.ext4: Bad magic number <\/code><code class=\"bash keyword\">in<\/code> <code class=\"bash plain\">super-block <\/code><code class=\"bash keyword\">while<\/code> <code class=\"bash plain\">trying to <\/code><code class=\"bash functions\">open<\/code> <code class=\"bash plain\">\/dev\/sda5<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"bash plain\">The superblock could not be <\/code><code class=\"bash functions\">read<\/code> <code class=\"bash plain\">or does not describe a correct ext4<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"bash plain\">filesystem.\u00a0 If the device is valid and it really contains an ext4<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"bash plain\">filesystem (and not swap or ufs or something <\/code><code class=\"bash keyword\">else<\/code><code class=\"bash plain\">), <\/code><code class=\"bash keyword\">then<\/code> <code class=\"bash plain\">the superblock<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><code class=\"bash plain\">is corrupt, and you might try running e2fsck with an alternate superblock:<\/code><\/div>\n<div class=\"line number11 index10 alt2\"><code class=\"bash plain\">e2fsck -b 8193 &amp;lt;device&amp;gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/blockquote>\n<p>Now lets find where your superblock backups are kept.<\/p>\n<blockquote>\n<div>\n<div id=\"highlighter_951790\" class=\"syntaxhighlighter bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash functions\">sudo<\/code> <code class=\"bash plain\">mke2fs -n <\/code><code class=\"bash plain\">\/dev\/xxx<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/blockquote>\n<p>Down at the bottom of this output, should be a list of the backups<\/p>\n<blockquote>\n<div>\n<div id=\"highlighter_792830\" class=\"syntaxhighlighter bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash plain\">Superblock backups stored on blocks:<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"bash plain\">32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/blockquote>\n<p dir=\"ltr\">Your almost there. Finally, restore the superblock from the backup, again replacing the x\u2019s with your partition name, and block_number with the first backup superblock.<\/p>\n<blockquote>\n<div>\n<div id=\"highlighter_405342\" class=\"syntaxhighlighter bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash functions\">sudo<\/code> <code class=\"bash plain\">e2fsck -b block_number <\/code><code class=\"bash plain\">\/dev\/xxx<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/blockquote>\n<p dir=\"ltr\">Now reboot, and your superblock should be fixed. If it\u2019s not, repeat the steps, but restore a different backup superblock \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This has happened to me a few times, and it\u2019s not a nice problem to find yourself in. You computer won\u2019t boot, all your filesystem checks [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[222,227],"tags":[239,241,4,5,6],"class_list":["post-58","post","type-post","status-publish","format-standard","hentry","category-cloud-and-devsecops","category-linux-and-open-source","tag-backup-and-recovery","tag-cloud-security","tag-linux","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/posts\/58","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/comments?post=58"}],"version-history":[{"count":2,"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":60,"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/posts\/58\/revisions\/60"}],"wp:attachment":[{"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/media?parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/categories?post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tajdini.net\/blog\/wp-json\/wp\/v2\/tags?post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}