Recently, I needed to repair a Ubuntu droplet server that was stuck in a kernel panic. The server maintainer decided to upgrade the OS from Ubuntu 16.04 to 18.04. Everything went well until the final restart after the upgrade when the dorplet was stuck during boot. The maintainer could not SSH into the system and the website was down as well. In the DO control centre, CPU usage of the droplet was showing 100% and the console was showing the kernel panic state and the system calls that caused it.
I searched around and found this post that had a similar problem and solved it. Basically, these are the steps:
apt-get install --reinstall linux-image-generic linux-image
However, when I entered the command during Step 3, I got an error from /usr/sbin/grub-probe that it "failed to get canonical path of overlay".
I used the 'df' command to list mounted filesystems and realised that, the live CD ISO mounts overlay at the root i.e. '/', but it was not mounted when I chroot into the broken system.
After a few more searches, I found some usefule info in here and here that says I need to bind mount '/dev', '/proc' and '/sys' before chroot, so that they can be found by applications. I did that and it all worked out! This time, the reinstall was completed successfully without any error (though there were a few warnings and fallbacks).
In summary, the following steps were performed:
I searched around and found this post that had a similar problem and solved it. Basically, these are the steps:
- Boot into the recovery ISO
- Mount and chroot into the existing filesystem
- Reinstall the kernel
apt-get install --reinstall linux-image-generic linux-image
However, when I entered the command during Step 3, I got an error from /usr/sbin/grub-probe that it "failed to get canonical path of overlay".
I used the 'df' command to list mounted filesystems and realised that, the live CD ISO mounts overlay at the root i.e. '/', but it was not mounted when I chroot into the broken system.
After a few more searches, I found some usefule info in here and here that says I need to bind mount '/dev', '/proc' and '/sys' before chroot, so that they can be found by applications. I did that and it all worked out! This time, the reinstall was completed successfully without any error (though there were a few warnings and fallbacks).
In summary, the following steps were performed:
- Power off the droplet and boot from the recovery ISO
- Choose 6 for interactive shell (don't mount or chroot)
- In the interactive shell,
- Mount the filesystem: "mount /dev/vda1 /mnt"
- Bind mount /dev: "mount --bind /dev /mnt/dev
- Bind mount /proc: "mount --bind /proc /mnt/proc"
- Bind mount /sys: "mount --bind /sys /mnt/sys"
- Chroot: "chroot /mnt"
- Update and upgrade: "apt update" and "apt upgrade"
- Exit the interactive shell and restart the droplet to boot from main harddisk
THANK YOU!
ReplyDeleteCan you reprint your article
ReplyDeleteThank you very much i could kiss you... but we social distancing. I had an issue with apt update it wouldnt resolve host names, I had to exit chroot and run "sudo mount -o bind /run /mnt/run" then get back to chroot, and it worked like a bomb... thanks.
ReplyDeletethank you so much. let me spred this article on my facebook.
ReplyDeleteif the system cannot resolve any hostname, make sure to edit /etc/resolv.conf properly by adding "nameserver 8.8.8.8". Likely will face the issue when "sudo apt update". Thanks.
ReplyDeleteThank you so much!!!
ReplyDeleteYou save my life with this!
It's 1:15 AM and your post just saved me. I can't thank you enough.
ReplyDelete