How can I repair a system with a deleted kernel?

Because I wanted to get more free space on my HDD, I deleted old kernels (dont ask me why I was so mad.). I accidentally deleted the active kernel too (3.2.0-27 on Ubuntu 12.04).

First I couldn't boot. I installed the kernels 3.2.0-23 and 3.2.0-27 via a live system (see here).

Now, when I start my system now, I only get these lines:

mountall: Event failed
fsck from util-linux 2.20.1
/dev/sda1: clean, 832254/40099840 files, 21092083/160394239 blocks
 * Stopping Flush boot log to disk
 * Stopping Enabling additional executable binary formats
 * Starting bluetooth daemon

Other PC specs:

  • Intel i5 2500K 4x 3.3 GHz
  • 8 GB RAM
  • /dev/sda1 is Ubuntu, about 1400GB
  • Zotac Nvidia GTX 560
  • ASRock Z68 Pro3

Thank you in advance!

EDIT: Here you can find some log files from /var/log: kern.log boot.log


Solution 1:

Boot from the livecd, mount the hard disk, and reinstall the kernel. For example:

sudo -s
mount /dev/sda1 /mnt
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc
mount --bind /dev /mnt/dev
chroot /mnt
apt-get install linux-image-3.2.0-27-generic-pae

Solution 2:

An option is a manual recovery:

Files are the easiest part. You can do what Ramchandra suggested, but if you want to preserve your apps you should avoid reinstalling (as that would, as you've seen, remove the apps.) If you want to avoid uninstalling the boot with a missing kernel:

  1. Boot to LiveCD.

  2. Using nautilus, open up the broken partition.

  3. Navigate to /home/myusernamehere. All your files will be there.

Some other files you might want to save:

  • /etc/apt/sources.list, if you have any manual repos.

After you are done with this, stick it onto a flash drive or email it to yourself.

Apps is a trickier part. I have come up with a somewhat roundabout solution that will take some time (most of it without you actively participating), but this should recover your apps (without settings/configurations)

  1. Stick around LiveCD.

  2. Navigate to /usr/lib. (It may take a while to load.)

  3. Woah! Huge amount of folders. Open up gedit in liveCD.

  4. Type this in gedit:

    #!/bin/sh

    sudo apt-get install folder1 folder2 folder3

...Where folder1 folder2 folder3 are the names of the folders.

These are all the programs you have installed on ubuntu (I think). Some of these (about 50%, maybe more) come with the system, so the arent necessary, but a safe bet is just put everything.

Another place to look for apps is /etc and /etc/alternatives. (Update me if I am missing any spots, internet!)

Save the file as .sh and email or flash drive it.

Now, when you first start up your computer (after total reinstall) you can run this script to sudo apt-get all your programs that you previously had. They'll be good as new!

Solution 3:

Did you try the recovery option? You can install Ubuntu over an exisiting Ubuntu installation - all your files will remain. Though if you modify system files, those changes will be wiped out.

To do so, at the installer select advanced partition and use your ubuntu installed partition as / .

I have not tested it though.