258

Upon trying to upgrade from 10.10 to 11.04 all seemed to go well until the restart. This error message is what comes up:

Kernel Panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

How do we fix that?

David Foerster
  • 36,264
  • 56
  • 94
  • 147
Jeffrywith1e
  • 2,835
  • 2
    Your troubles might having nothing to do with your main system, but rather with your install media (USB stick)... ➪ see here: http://askubuntu.com/a/632636/479118 – Frank N Dec 04 '15 at 18:00
  • 1
    I can't post an answer since I don't have enough rep, but when I got this problem I solved it by booting to a live USB stick, mounting the main and EFI partitions, enabling networking, and running sudo apt-get install linux-image-generic to upgrade to the latest kernel. – Owen Apr 23 '19 at 04:04
  • 1
    This has way too many answers, but not what I needed: dpkg --configure linux-kernel-<version>-generic - not with -a because that triggered the recovery menu again. See my answer for more. – Ondra Žižka Oct 30 '20 at 01:13
  • 11
    It's now 11 years later, and 22.04 fails to automatically fix this problem and/or give decent clues of what steps to take !! – Rick James May 16 '22 at 19:20
  • 1
    Boot to the Boot-Repair live CD and repair GRUB. Detailed instructions here. – Collin Krawll Dec 02 '22 at 05:56

12 Answers12

257

You are missing the initramfs for that kernel. Choose another kernel from the GRUB menu under Advanced options for Ubuntu and run sudo update-initramfs -u -k version to generate the initrd for version (replace version with the kernel version string such as 4.15.0-36-generic) then sudo update-grub.

Zanna
  • 70,465
psusi
  • 37,551
  • 12
    what if the kernel panic is being shown when selecting the unique kernel option that exists for that OS (in a multi-boot scenario), how does one go to launch update-initramfs? – knocte Jan 29 '14 at 09:04
  • 6
    @knocte, See Tomeu Roig's answer. – psusi Jan 29 '14 at 14:07
  • 4
    I cannot enter Ubuntu System or Recovery Mode, how can I execute that command to test whether it works? – Casper Jul 16 '16 at 09:54
  • @Casper, try an older kernel version ( under Advanced Options ). – psusi Apr 02 '17 at 17:48
  • Good call, though the error message does not reflect this very well. I immediately assumed it had something to do with the rootfs, not the ramdisk. +1 – sherrellbc Feb 10 '18 at 15:17
  • 2
    @sherrellbc, it does have to do with the rootfs. The kernel can't mount the rootfs because it isn't configured correctly to do so. Instead it is assumed that the kernel will use an initramfs to mount the rootfs. In the days before initramfs, you had to configure the kernel to know a hard coded block number for the rootfs to mount, and this is the behavior it falls back to when it has no initramfs. – psusi Feb 11 '18 at 02:43
  • 2
    In my case, the cause was running out of storage space. So I chose a previous kernel, booted, deleted stuff from the hard drive, and rebooted back to the original kernel. – Ibu Jun 11 '18 at 21:51
  • When I try to enter in Advanced options for Ubuntu then I go back to the main GRUB menu . If I go in my windows partition it works, otherwise it does not. Can you help me? – desmond13 Aug 27 '19 at 08:17
  • EDIT: I was not able to enter in the Advanced Options because I did not have the correct rights to do it. Once I discussed this with the IT of my lab he just entered in the Advanced Options with his own account and it was entering without any problems.

    He booted through network. Then he went through a different kernel (precedent to the one I was trying to install) and then ubuntu was starting. Once it started he resumed the package installations which were happening when I turned off my laptop. Then he gave me the grub rights to do everything by myself (if it will happen again)

    – desmond13 Aug 27 '19 at 16:36
  • On my ubuntu 19.10 I've had to run apt install initramfs-tools in order to get update-initramfs command – yunspace Oct 29 '19 at 12:28
  • Does that fix stuff for the future? Or do I have to do it after every kernel update from now on? – uav Jun 03 '20 at 17:50
  • 1
    Sorry, but this doesn't work for me. I can reboot with another version, I can execute all commands, but when rebooting, same problem again. – Denis BUCHER Dec 06 '20 at 01:59
  • @DenisBUCHER, double check that the version you passed to update-initramfs is the one grub is booting by default. – psusi Feb 03 '21 at 14:24
  • 1
    This worked when I got the VFS issue after running do-release-upgrade, thank you! – Gloat May 20 '21 at 05:02
  • You saved my day! – mixalbl4 Apr 12 '22 at 11:38
  • my laptop dropped from some 3ft while running it has debian 10 and now i get this error (and then some and finishes with this message also) might this work for me? i don't know how to get another kernel either i'm just in grub and this command doesn't work – user163831 Nov 02 '22 at 19:52
  • Thanks! Btw this is generic and works with Kali too – Shivang Kakkar Feb 28 '23 at 14:52
109

Start with a livecd, open a a terminal and execute:

sudo fdisk -l
sudo mount /dev/sdax /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt 

If you /boot is on a separate partition also call:

sudo mount /dev/sday /mnt/boot

and now you can make update-initramfs and update-grub without errors.

update-initramfs -u -k 2.6.38-8-generic (or your version)

If you don't know your version. Use:

dpkg --list | grep linux-image

And just update Grub.

update-grub

Reboot your system.

mchid
  • 43,546
  • 8
  • 97
  • 150
Tomeu Roig
  • 1,091
  • 2
    I have added sudo mount --bind /dev/pts /mnt/dev/pts and sudo mount --bind /sys /mnt/sys in my edit; without this, update-grub2 complained. – Hbf Nov 08 '12 at 15:51
  • 8
    how can I found out the exact version? – knocte Jan 29 '14 at 09:05
  • 2
    None of the mount points exist beyond the first one /dev/sdax if you're using EFI. – Paul Gregoire Jul 28 '14 at 14:36
  • @knocte try ls /mnt/boot and look for the latest kernel version. Or if you want to do it properly, read the menuentry 'Ubuntu' from /mnt/boot/grub/grub.cfg – Ciro Santilli OurBigBook.com Oct 01 '15 at 07:10
  • Worked on Ubuntu 14.04! The initrd was missing from /boot. The question is: how is it possible that the file simply disappeared? I did nothing that seemed dangerous. – Ciro Santilli OurBigBook.com Oct 01 '15 at 07:11
  • 1
    Very nice - this worked for me in eliminating the 'kernel panic' error. I still had to follow it up by selecting the 'repair' start-up option in grub and selecting 'fix broken packages'. That took care of my remaining issues. – Gatmando Mar 22 '16 at 23:27
  • 1
    mount: mount point {path} does not exist. All the mount points does not exist. How can I solve the problem? – Casper Jul 16 '16 at 10:07
  • Since you used --bindand chroot you don't need the -k option – Déjà vu Oct 01 '16 at 11:20
  • 1
    Trying this, getting these types of error message: update-initramfs: Generating /boot/initrd.img-4.15.0.50.52 WARNING: missing /lib/modules/4.15.0.50.52 Ensure all necessary drivers are built into the linux image! depmod: ERROR: could not open directory /lib/modules/4.15.0.50.52: No such file or directory depmod: FATAL: could not search modules: No such file or directory depmod: WARNING: could not open /var/tmp/mkinitramfs_ch6X8K/lib/modules/4.15.0.50.52/modules.order: No such file or directory – JeanSibelius Jun 02 '19 at 18:53
  • You are my life savior – oya163 Dec 18 '20 at 00:42
  • Thank you! Afterwards though, when I run vagrant it says throws errors about a read-only file system as it tries to remove the vboxvideo file within /lib/modules - is there a way to resolve the fact that it changed it to readonly? – meder omuraliev Nov 05 '21 at 19:02
  • I had to do similar to this: use a Live CD and mount the filesystem before doing update-initramfs. But I'm using full disk encryption (as chosen during installation of Ubuntu) so mounting is different; trying it like this will result in errors namely about inexistent mount points. – Daniel Nov 20 '21 at 12:31
  • Ensure you use the same version of live CD as your current installation. e.g Trying Ubuntu 20 live CD on my current 16, had incompatible kernel versions. Had to download the old Ubuntu 16 live CD – shreyansp Mar 17 '22 at 16:05
  • how can i do this my drive is lvm idk how to mount it – user163831 Nov 02 '22 at 19:54
72

In case this happened after an aborted kernel update (e.g. system crash while aptitude safe-upgrade),

  1. boot with an older kernel and
  2. run dpkg --configure -a.

This will complete the upgrade, including configuring the boot settings as psusi explains.

Raphael
  • 1,982
  • 2
    When I upgraded from Ubuntu 20.04 to 22.04, I received the above error. Applying your solution fixed everything. Thanks! – user238607 Mar 01 '22 at 16:40
  • I was getting the following error ERROR (dkms apport): binary package for evdi: 1.12.0 not found, search results showed it is related to DisplayLink which I was not using anymore, so I uninstalled it, sudo displaylink-installer uninstall and redid the above and it worked. – Waqleh May 15 '23 at 08:21
  • Wow, thanks. Kernel Panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) sound really bad, I was ready to nuke the old server and install a new HDD. I just needed to remove some old kernels. – Eric Duminil Sep 08 '23 at 09:34
  • this worked on 20.04 – strix25 Sep 23 '23 at 15:46
30

In my situation the problem was that /boot was at 100% capacity, so the last 2 kernel updates had not completed successfully, hence on reboot when GRUB2 selected the latest Kernel, it failed.

I resolved the issue by booting into the oldest kernel installed, and removing some unused kernels using aptitude. By using aptitude, after the uninstall had happened, dpkg automatically tried to configure the broken packages, and this time succeeded.

tshepang
  • 1,967
  • 5
    This was the closest to my solution; just running dpkg --configure -a was enough to trigger the update-initramfs hook, and fix the broken kernel. – Symmetric May 11 '13 at 19:44
  • 1
    You mean you had a separate /boot partition is that it? – Ciro Santilli OurBigBook.com Oct 01 '15 at 07:00
  • 2
    It was a server set up prior to my arrival, and it was configured with /boot on it's own partition and unattended-upgrades – sheepeatingtaz Oct 01 '15 at 14:24
  • 4
    You can use sudo apt-get autoremove to remove old kernels in case your running out of space on /boot. – Florian Brucker Jul 21 '16 at 05:42
  • 2
    I booted into an older kernel, did a sudo apt-get autoremove, rebooted again (older kernel), then did a sudo apt-get dist-upgrade, and this worked. This was on a small test machine I have. Same issue though, 100% /boot – jmlumpkin May 23 '18 at 02:51
10

Full diagnosis procedure based on kernel messages

But using this QEMU emulation setup I tried to produce minimal examples of every possible failure type to help you debug your problem.

In that simple setup, QEMU emulates a system with:

  • a single virtio disk which represents a hard disk or SDD of real hardware
  • that virtio disk has a raw unpartitioned ext4 image in it. In normal operation, that device would appear under /dev/vda (v is the indicator letter for virtio, if it were partitioned the partitions would be /dev/vda1, /dev/vda2, etc.)

The possible errors you could get are:

  1. Linux cannot read bytes from the disk.

    This could be either because the disk is broken, or because you didn't configure Linux with the ability to read from that hardware type.

    In my QEMU case I can reproduce this by removing the key options that allow the kernel to read that virtio disk:

    CONFIG_VIRTIO_BLK=y
    CONFIG_VIRTIO_PCI=y
    

    The resulting error message is looks like this

    <4>[    0.541708] VFS: Cannot open root device "vda" or unknown-block(0,0): error -6
    <4>[    0.542035] Please append a correct "root=" boot option; here are the available partitions:
    <0>[    0.542562] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
    

    So here Linux tells us that it can't read from vda at all at: VFS: Cannot open root device "vda" or unknown-block(0,0): error -6.

    Then, at Please append a correct "root=" boot option; here are the available partitions: it gives a list of partitions it could read.

    In our case, the list is empty however, since the next line is completely unrelated.

  2. Linux can read bytes from the disk, but it doesn't understand the filesystem to read files out of it.

    This is normally because you didn't configure the kernel to read that filesystem type.

    I can reach this case by removing the kernel's ability to read an ext4 filesystem:

    CONFIG_EXT4_FS=y
    

    With that removed, the error message is:

    <4>[    0.585296] List of all partitions:
    <4>[    0.585913] fe00          524288 vda
    <4>[    0.586123]  driver: virtio_blk
    <4>[    0.586471] No filesystem could mount root, tried:
    <4>[    0.586497]  squashfs
    <4>[    0.586724]
    <0>[    0.587360] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(254,0)
    

    So Linux tells us that it managed to find a vda partition by reading the disk with the virtio_blk device.

    But then, it was not able to read that partition. It tried squashfs, which is the only other filesystem we have enabled, but that didn't work, because we have an ext4 partition.

  3. You passed the wrong root= kernel command line option.

    This one is easy, just pass the correct one! The kernel even gives you a list of the ones it knows about!

    For example, if we pass a wrong:

    root=/dev/vda2
    

    which doesn't even exist, the kernel gives an error of type:

    <4>[    0.608475] Please append a correct "root=" boot option; here are the available partitions:
    <4>[    0.609563] fe00          524288 vda
    <4>[    0.609723]  driver: virtio_blk
    <0>[    0.610433] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(254,2)
    

    clearing telling us that "hey: there is no vda2, but there is a vda!"

    This example also clarifies well what the (0,0), (254,0) and (254,2) meant from previous cases:

    • (0,0): first number 0 means could not read from the disk at all
    • (254,2): 254 is some ID that got assigned to the disk. 2 is the partition withing that ID as in /dev/vda2. And partition 0 means a raw non-partitioned partition as in /dev/vda.

Tested on Linux 5.4.3.

3

I faced this problem, as linux headers were getting updated, and electricity was gone. I recovered as below,

Go to grub menu and select advanced options > select a previous kernel and boot,

Once you get terminal, run below command,

sudo dpkg --configure -a

here from man page of dpkg,

--configure package...|-a|--pending
              Configure a package which has been unpacked but not yet configured.  If -a or --pending is given instead of package, all unpacked but unconfigured packages are configured.

              To reconfigure a package which has already been configured, try the dpkg-reconfigure(8) command instead.

              Configuring consists of the following steps:

              1. Unpack the conffiles, and at the same time back up the old conffiles, so that they can be restored if something goes wrong.

              2. Run postinst script, if provided by the package.

logs as below,

Setting up linux-image-4.15.0-76-generic (4.15.0-76.86) ...
Processing triggers for initramfs-tools (0.130ubuntu3.9) ...
update-initramfs: Generating /boot/initrd.img-4.15.0-74-generic
Processing triggers for linux-image-4.15.0-76-generic (4.15.0-76.86) ...
/etc/kernel/postinst.d/dkms:
 * dkms: running auto installation service for kernel 4.15.0-76-generic
   ...done.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-4.15.0-76-generic
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-76-generic
Found initrd image: /boot/initrd.img-4.15.0-76-generic
Found linux image: /boot/vmlinuz-4.15.0-74-generic
Found initrd image: /boot/initrd.img-4.15.0-74-generic
Found linux image: /boot/vmlinuz-4.15.0-72-generic
Found initrd image: /boot/initrd.img-4.15.0-72-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
Found Windows 7 on /dev/sda1
done

and voila, newer package that was downloaded but not configured is working.

mrigendra
  • 207
  • 1
  • 8
1

In my case:

  • It was caused by a crash during upgrade to LTS 20.04.

  • dpkg --configure -a opened the recovery menu again, so the packages were not (re)configured.

  • So I had to list the installed kernels

    dpkg --list | grep linux-kernel | more
    
  • and configure specifically the kernel that was newly installed:

    dpkg --configure linux-kernel-5.20.0-52-generic
    

On a related note, the causes of the upgrade crash may be:

  • Installation ran out of space on the volume with kernels:

    dpkg --purge remove linux-kernel-<someOldVersion>
    

    I wouldn't go with "remove all old kernels" right away because you want some to boot to if the newest is broken.

  • Your disk is wearing off - run smartctl --health --all and e2fsck ...

  • Some driver caused the whole OS to hang - for me this happens with nVidia driver when playing 4K movie on 4K screen.

1

In my case, it was because my Dell XPS 15 9550 has some kind of weird problem of not being able to load the full initrd image in the RAM on the UEFI procedure. Answered on another question specific to that one also.

https://askubuntu.com/a/1412273/170833

morhook
  • 1,610
  • 14
  • 23
0

Tested for Lubuntu 22.04 with LUKS encryption.
Easy way. No terminal commands, no editing files.

  1. reboot your computer, enter your LUKS encryption password, press Enter
  2. Select other boot options
  3. Select old kernel (recovery mode)
  4. Click "fix broken packages"
  5. Click "update grub"
  6. Reboot in normal mode
Nairum
  • 221
0

You can also boot the server in rescue mode, and reinstall only the grub

http://info.w3calculator.com/free-code/linux/recover-from-corrupted-boot-image/

Math
  • 1
0

I got this problem due to my /boot partition was full so my kernel updates had failed. I managed to fix this by booting from an old kernel in the GRUB menu.

When managed to boot I began purging old kernels, but I had manage to get some dependency issues so first I had to uninstall linux-server package

apt-get remove linux-server
apt-get update
apt-get -f install
apt-get upgrade

Then I rebooted and everything was working fine!

0

In addition to Tomeu's instructions, before chroot I needed to:

sudo mount --bind /dev /mnt/dev

Additionally, after the chroot:

cp -r /usr/lib/i386-linux-gnu/pango /usr/lib/

(Got this from here.)

Kris Harper
  • 13,477
Jason
  • 1