356

I am running an HP pavilion dv6000 dual boot win7 and Ubuntu 12.04. (well, up until today). After a reboot, the boot process drops to the BusyBox shell and I end up at the prompt:

BusyBox v1.18.5 (Ubuntu 1:1.18.5-1ubuntu4) built-in shell (ash)
Enter 'help' for a list of built-in commands.

(initramfs)

I've been researching others who have had this same problem, but haven't been able to find any of those solutions to work for me.

I tried the method described here, and after the final command

mount -t ntfs-3g /dev/sda1 /root -o force

it does nothing and gives me another (initramfs) prompt.

I can boot to a live CD (USB) and get to a terminal, but it doesn't seem to do much good, as I can see the /dev/sda1 in the ls command, but it doesn't recognize it when I try to cd to it.

One more question: using the command fdisk -l how can I tell which mount point (sda1/sda2) is my windows partition and which one is Ubuntu?

pomsky
  • 68,507
dpm
  • 3,561
  • 2
    This was the winner, BTW

    http://www.cyberciti.biz/faq/recover-bad-superblock-from-corrupted-partition/

    – dpm May 17 '12 at 01:30
  • 6
    I can't believe Canonical hasn't implemented yet a proper user-friendly workflow to fix this situation :( – knocte Jul 12 '16 at 03:35
  • There has to be a better way to fix the case. You do not need Live Ubuntu for the task, since I have managed to solve it without it. I think you can fix the thing even in (inittramfs). – Léo Léopold Hertz 준영 Aug 18 '16 at 05:57
  • 4
    @Masi Actually, running fsck from initramfs fixes it in most cases now, but in the ubuntu release that was current when this question was posted, even after fsck was run, the same error was shown on boot again. – Amith KK Dec 14 '16 at 11:46
  • This very same issue happens also on Kubuntu 18.04. Whenever system suddenly freeze so I have to hard reset system; then this error occurs. I solved using with ramsudharsan's solution. – emre can Nov 09 '19 at 03:25
  • Boot recovery to see device path and "check and repair a Linux filesystem" with fsck <device-path> -y.

    I don't think fsck can cause data loss - but make a backup if the drive is gonna give up..

    On my system the error was probably due to memory errors.

    – dahe Mar 21 '21 at 17:58

7 Answers7

395

While at initramfs console, I passed a command exit to come out of the shell. The same console was presented before me but this time with the exact name of the partition that got corrupted.

BusyBox v1.18.5 (Ubuntu 1:1.18.5-1ubuntu4) built-in shell (ash) 
Enter 'help' for a list of built-in commands.

(initramfs) exit

/dev/mapper/ubuntu--vg-root: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY. (i.e., without -a or -p options) fsck exited with status code 4. The root filesystem on /dev/mapper/ubuntu--vg-root requires a manual fsck.

BusyBox v1.18.5 (Ubuntu 1:1.18.5-1ubuntu4) built-in shell (ash) Enter 'help' for a list of built-in commands.

(initramfs) fsck /dev/mapper/ubuntu--vg-root -y

fsck from util-linux 2.27.1 e2fsck 1.42.13 (17-May-2015) /dev/mapper/ubuntu--vg-root contains a file system with errors, check forced.

After the checking is done, I rebooted the system.

BusyBox v1.18.5 (Ubuntu 1:1.18.5-1ubuntu4) built-in shell (ash)
Enter 'help' for a list of built-in commands.

(initramfs) reboot

If reboot doesn't work, try exit.

and that's it, I got back into the filesystem without any errors.

geras
  • 476
ramsudharsan
  • 4,119
  • 1
  • 13
  • 5
  • 3
    the best solution! indeed saves a lot of time! especially when there's no liveusb near you. – OccamRazor Feb 08 '17 at 18:30
  • 3
    I had to reboot once to see the inconsistency error. Then I just followed this and everything was clean. Thanks! – niazangels Apr 14 '17 at 17:07
  • Just wanted to chime in to say this solution works for ENCRYPTED PARTITIONS as well! I was hesitant to try it, but since it was a virtual machine, I made a snapshot, tried the above fix, and everything went flawlessly. – Dekker500 May 16 '17 at 13:10
  • 15
    Worked for me. But why did it happen? – आनंद May 30 '17 at 17:23
  • Back in fsck /Dev/sda. – danny117 Jul 21 '17 at 19:24
  • ram - Nice! I didn't get the informative description when exiting from initramfs, so I just tried copying what you wrote "fsck /dev/mapper/ubuntu--vg-root -y" and it worked. Glad you posted it! Thanks. – Craig Hicks Aug 29 '17 at 21:34
  • 2
    This worked on Ubuntu 16.04, thanks! My solution was fsck /dev/sda1 -y and it took 20 seconds (https://imgur.com/a/S90z5) – JREAM Aug 30 '17 at 03:13
  • 1
    But what if the keyboard isn't working? :-/ – Matt Sep 06 '17 at 17:45
  • 3
    @Matt Enable the keyboard option in BIOS settings (If you have disabled keyboard during boot-up, hold the power button until you hear the reset sound from the board) – ramsudharsan Sep 07 '17 at 01:52
  • Had a similar issue on Mint. Changed 'fsck /dev/mapper/ubuntu--vg-root -y' to 'fsck /dev/mapper/mint--vg-root -y' and it worked for me. – Keltari Mar 16 '18 at 05:23
  • works for Kubuntu also: /dev/mapper/kubuntu--vg-root – Waqleh Sep 18 '18 at 07:26
  • for me this completely fixed the problem listed in initramfs..... it also did NOT allow me to reboot into the system itself and just lead to a new problem entirely. Referred to @Amith KK's answer below and it completely fixed my problem, really, I get it, people want a fix-all, it's almost like a LIVE BOOT USB REPAIR EXISTS. https://sourceforge.net/p/boot-repair-cd/home/Home/ after searching for a while.... literally people, here you go. This? MAYBE? The Live repair USB? YEP, GONNA FIX IT EVEN WITH BAD SUPERBLOCKS – codingNewb Nov 24 '18 at 10:45
  • Worked for me too! Thanks! OS: Debian GNU/Linux 9.6 (stretch) // Kernel: 4.9.0-8-amd64 – user88349 Nov 25 '18 at 20:10
  • I know exactly what caused this issue with mine. It was google-drive-ocamlfuse that helps me sync my drive files. I hadn't had this issue before and running fsck didn't do anything. I didn't know I had to write the partition path after since instructions weren't clear. This worked on Xubuntu 18.04. Thank you. – Nova Nov 24 '19 at 19:23
  • working on ubuntu 20.04. worked for me – Vilas Joshi May 05 '20 at 05:47
  • 1
    In my case exit didn't show any error and just kept going back to the initial prompt. But the trying fsck /dev/mapper/ubuntu--vg-root -y fixed lot of problems and I was able to run the GUI again. – undefined Jan 13 '21 at 21:29
  • If you, like me, are constantly having to use this fix, the cause may be Logical Volume Management (LVM) and/or disk encryption. I was using full disk encryption and this kept happening to me. I wiped my drive and switched to standard setup, and now everything works great. Have not had this issue again. So, LVM seems to be the problem. – Nate Sep 26 '21 at 16:54
  • I ran fsck /dev/mapper/vgubuntu-root -y on Ubuntu 21.04, then exit and it solved my problem ! – Lyokolux Nov 02 '21 at 18:38
  • @undefined That particular command worked for me when I had this same problem. Tried some of the other fixes suggested here but they didn't work in my case. Going by the results displayed during the fix, it was something to do with disk space counting errors (which I don't understand anything about). – Allan Jan 26 '22 at 13:17
  • Cool. Worked out for me. – lobjc Jul 17 '22 at 21:33
  • I ran fsck /dev/mapper/ubuntu--vg-root -y but it says no such file or directory. exit again comes back to same initramfs prompt. – Siddharth Das Aug 17 '22 at 19:41
  • Upvoted (a long time ago). After running fsck and rebooting, per your instructions, I also had to run sudo apt --fix-broken install once logged back into my system. See my full instructions and context here: Super User: sudo apt-get update couldn't create temporary file – Gabriel Staples Dec 05 '22 at 23:26
117

Actually the solution is easy just write the command of fsck /dev/sdax like the below and give Y if the console ask for fixing something:

(initramfs) fsck /dev/sda1

or

(initramfs) fsck /dev/sdaX

X specifies mounted disk part number.

If you don't want to manually press 'y' every time it asks for a fix, you can also run the command with the -y option.

(initramfs) fsck /dev/sdaX -y
efkan
  • 1,389
  • 4
    Get an image of the disk before doing this. It will modify the filesystem and you could lose all your files. – givanse Jul 24 '18 at 15:33
  • 2
    On my system fsck is not recognized as a command - it's not in the list of built-in commands when typing help. So it's not a fix for every time this problem occurs. – levitopher Aug 29 '18 at 14:05
  • 1
    @levitopher , what is the name of your linux distro? – efkan Aug 29 '18 at 14:59
  • 2
    @efkan: Fair comment, it's PoP!_OS by System76, but my impression is that the only difference from vanilla Ubuntu is graphics/user interface, and not in the base system. In addition, I'm tri-booting on a Mac, so obviously there are system differences, but my only comment is that contrary to the other comments, this is not a solution for everyone. – levitopher Aug 29 '18 at 16:15
  • 2
    The best and the easiest solution. But my question is why this happens. It's not that it happened onli in my system, many other have faced the same problem. But why? – Sandip Nath Jul 11 '20 at 18:26
  • 1
    I experienced this issue whenever I was trying to upload a file via the telegraph Ubuntu desktop app, the computer would freeze and when you restart it you land on the the busybox prompt. I just used the fsck /dev/sdaX - y & exit. Then I returned back to my computer's Ubuntu gui – Lord Luke Feb 23 '22 at 11:57
  • You have to press Y for like a gazillion prompts. Are you fucking insane? – chx101 Jul 25 '22 at 16:43
97

Note: Try this answer if you continue to face the issue even after attempting the steps in @ramsudharsan's answer. If you have not tried following those instructions yet I recommend you to do so since that seems to fix the problem in most cases.

It seems that you have a bad superblock. To fix this:

Firstly, boot into a live CD or USB

Find out your partition number by using

sudo fdisk -l|grep Linux|grep -Ev 'swap'

Then, list all superblocks by using the command:

sudo dumpe2fs /dev/sda2 | grep superblock

Replace sda2 to your drive number

You should get a similar output like this

  Primary superblock at 0, Group descriptors at 1-6
  Backup superblock at 32768, Group descriptors at 32769-32774
  Backup superblock at 98304, Group descriptors at 98305-98310
  Backup superblock at 163840, Group descriptors at 163841-163846
  Backup superblock at 229376, Group descriptors at 229377-229382
  Backup superblock at 294912, Group descriptors at 294913-294918
  Backup superblock at 819200, Group descriptors at 819201-819206
  Backup superblock at 884736, Group descriptors at 884737-884742
  Backup superblock at 1605632, Group descriptors at 1605633-1605638
  Backup superblock at 2654208, Group descriptors at 2654209-2654214
  Backup superblock at 4096000, Group descriptors at 4096001-4096006
  Backup superblock at 7962624, Group descriptors at 7962625-7962630
  Backup superblock at 11239424, Group descriptors at 11239425-11239430
  Backup superblock at 20480000, Group descriptors at 20480001-20480006
  Backup superblock at 23887872, Group descriptors at 23887873-23887878

Choose an alternate superblock from this list, for this case alternate superblock # 32768

Now, to check and repair a Linux file system using alternate superblock # 32768:

sudo fsck -b 32768 /dev/sda2 -y

The -y flag is used to skip all the Fix? questions and to answer them all with a yes automatically

You should get similar output like this:

fsck 1.40.2 (12-Jul-2007)
e2fsck 1.40.2 (12-Jul-2007)
/dev/sda2 was not cleanly unmounted, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong for group #241 (32254, counted=32253).
Fix? yes
Free blocks count wrong for group #362 (32254, counted=32248).
Fix? yes
Free blocks count wrong for group #368 (32254, counted=27774).
Fix? yes
..........
/dev/sda2: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sda2: 59586/30539776 files (0.6% non-contiguous), 3604682/61059048 blocks

Now try mounting the partition

sudo mount /dev/sda2 /mnt

Now, try to browse the filesystem with the following commands

cd /mnt
mkdir test
ls -l
cp file /path/to/safe/location

If you are able to perform the above commands, you have most probably fixed your error.

Now, restart you computer and you should be able to boot normally.

(source)

Amith KK
  • 13,412
  • 1
    I have followed all the steps for sda1 but can't do last part "mkdir test"!! There is also sda5 so I suppose to repeat steps for that? – Freddy Apr 08 '15 at 09:40
  • 2
    You write "Select an alternate superblock". Alternate to what? Can I pick any from the list? – Mads Skjern Oct 27 '15 at 11:32
  • 1
    I suggest adding to the answer, that one must answer yes to each of the "Fix questions". But also that there can be hundres of these questions, and one can answer yes for all, by using "-y" flag. – Mads Skjern Oct 27 '15 at 11:46
  • 1
    Also, does one risk doing irreversable harm? If for some reason, this is not the actual problem/solution. – Mads Skjern Oct 27 '15 at 11:50
  • I believe one must use sudo for mkdir and cp. – Mads Skjern Oct 27 '15 at 11:53
  • 1
    Don't understand the last line "cp file ...", the rest is done. – juanuni Jan 20 '16 at 05:48
  • @juanuni, I think it means you just pick one of the files you find in /mnt (or /mnt/*, somewhere below) and copy them to a path that you know will survive a reboot. – Sir Jane Jan 20 '16 at 14:46
  • @juanuni It's just a copy to any other drive or someplace to verify that copying does work.

    It's not a necessary step, and is used just to verify that the error has indeed been fixed

    – Amith KK Jan 20 '16 at 19:22
  • @MadsSkjern It only fixes stuff if there's an error in the free block count. It'll just run normally and exit if there are no errors – Amith KK Jan 20 '16 at 19:26
  • I don't understand what "an alternate superblock" is either (I don't even know what a superblock is in the first place). – ABu Jan 21 '16 at 17:01
  • 1
    @Peregring-lk http://unix.stackexchange.com/a/4403/8919.

    I recommend you read this

    – Amith KK Jan 27 '16 at 18:54
  • 2
    +1 for those that were using gparted and now are here – Vitor Abella Aug 27 '16 at 03:29
  • 3
    what if sudo fdisk -l|grep Linux|grep -Ev 'swap' returns 2 lines? /dev/sda2 and /dev/sda5 for me – knocte Oct 02 '16 at 08:42
  • 1
    I made busybox font-color orange this way – Ertürk Öztürk Apr 08 '17 at 19:48
  • @Amith - hi, I could do all the steps given above and when the process was finished, I could create directory/files in my sdaX. But all my files from home folder had moved to lost+found. And also, during login I could only see box like characters and after login, it was just a blank screen. Before login, a black screen still appears and display that "files contains error" and then takes me to a login screen – m0rpheu5 Jan 21 '18 at 05:56
  • Is it possible that in 90% of the cases, most people are just finding this answer helpful because it includes running fdisk, rather than because they're trying a different superblock? – mwfearnley Jan 12 '19 at 14:39
  • Can anyone help to understand , what exactly alternate superblock means ? – Arun Mar 31 '21 at 15:30
10
  1. Simple Answer is remove your hard disk attach in another system and start the system (please don't boot from your initramfs error hard disk use any with Ubuntu and gparted installed).
  2. start gparted and select your hard disk and select CHECK from right click menu.
Alexis Wilke
  • 2,707
6

Slightly different answer (Ubuntu 16.04), although other answers eventually led me to it.

I first had to choose a recovery mode kernel before being able to see the error messages to know which partition/file system had errors.

From then on, running fsck /dev/sdb1/ -y fixed it for me.

Felipe
  • 479
4

I just tried a lucky shot by booting the system with the "Parted Magic" tool from a Live CD. Looking at the partitions, there was a declared "unknown space" of some GBytes on the Linux partition.

So I just widened the Linux space over the whole Partition and voila - since then my Linux boots as before without any fail so far.

Braiam
  • 67,791
  • 32
  • 179
  • 269
Kai
  • 41
0

I have been dropping to busybox. The cause varies yet having a USB drive plugged in that is not the target drive makes the issue worse. Best to unplug before booting. With that drive unplugged: often a hard boot (power down and wait 10 seconds to power up) will boot correctly. For me the target drive is a SSD with a classic spinning hard drive pointing to it. My settings are a bit like this. Add a M.2 drive to Ubuntu:

https://ubuntuforums.org/showthread.php?t=2415658&page=4&p=13849399#post13849399s.

Really sped up an old system. Only caveat is dropping in to busybox now and then.