Sponsor

Well something is gone bad and when i rebooted to start my new Xubuntu 11.04 i got:

error: cannot read the Linux header.
error: you need to load the kernel first.
Failed to boot both default and fallback entries.
Press any key to continue...

During the upgrade, Ubuntu has removed all old Kernel but one, and so..i find myself without a way to boot my machine.

Fortunately I did a lot of experience with Gentoo in the past, that on this occasion was very useful to recover the system.

When you have an error like that you can do 2 things:

1) Reinstall from zero, but i don’t have a dedicated /home partition so this would erase all my documents and configurations, if for you it’s a fresh install perhaps you can just retry the install from zero.
2) Try to fix the problem, this need some work and the use of chroot

This is how to implement the solution number 2:

1 Boot with another Linux

What do you need: a Live CD/USB Stick, it’s better to use a recent distribution, i used for this Ubuntu 11.04 on a USB Stick (1 GB).

Once that the live distribution has booted, open a terminal and become root (usually a sudo -i is enough).
Also check the internet connection, we could need to download something later.

2 Mount of your filesystem

Now you have to find the partition where you keep your / and if you use it the /boot.
To see the status of your partitions use:

They mounted without problems (so i excluded problems on the filesystems) and moving in these directory i did not find any visible problem.

3 chroot there !

Now we are about to use chroot , anyone using gentoo should be familiar with this concept, because one stage of installation consist in booting from a live CD and then switch into the filesystem, and we’ll do exactly the same, mount the meta filesystems:

Why a “mount -o bind” ?
The difference is that ordinary mount only allows you to mount a block device in one single place, but mount –bind allows you to mount something you’ve already mounted elsewhere in a second place; so you end up with the same stuff mounted in two difference places.

Now that we have all the filesystems ready we can use chroot, this command creates a “jailed” copy of the current operating environment within the current operating environment, so you can run stuff without affecting your main environment:

chroot/mnt/oldubuntu /bin/bash

After this command you’ll find yourself as root on your main system, now it’s time to fix the system.
In my case i noticed that /boot was full, so probably something went wrong when the initrd was created during the install of the new 2.6.38 Kernel, what I’ve done to fix it has been:

1) Delete some old stuff in /boot
2) run aptitude pressing the key g i noticed that there were some unfinished task, including the final configuration of the kernel 2.6.38
3) So i just pressed g again and aptitude finished correctly the installation of the new Kernel

4 Reboot and enjoy your system

Now remove your live distro and reboot into your original system !

This is just an example, but you can use this method to recover a Linux system from many problems.