How can I repair a system with a deleted kernel?

13,394

Solution 1

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 2

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 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.

Share:
13,394

Related videos on Youtube

slashcrack
Author by

slashcrack

Updated on September 18, 2022

Comments

  • slashcrack
    slashcrack over 1 year

    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

    • Andrejs Cainikovs
      Andrejs Cainikovs almost 12 years
      Please provide logs from /var/log/messages. If you are not able to log in, you can obtain them while booted via live CD.
    • ish
      ish almost 12 years
      dmesg | pastebinit please
    • Eliah Kagan
      Eliah Kagan almost 12 years
      I had originally thought that the problem here was that the kernel was not properly reinstalled. But I am not convinced this is true, and the upvotes on my answer (which provided a more detailed reinstallation procedure) made this question look answered in the questions list. So I've removed that answer, and posted it (with appropriate changes) in the question where it better belongs. Anyone who needs it can find it there. Good luck with this problem!
    • slashcrack
      slashcrack almost 12 years
      The problem is that I installed the kernel but the system doesn't boot up!
    • JXPheonix
      JXPheonix almost 12 years
      In the future, you can remove old kernels using sudo apt-get autoremove.
  • slashcrack
    slashcrack almost 12 years
    First, thank you for your answer. The new installation without formatting helped! Now I have got all my data from my home directory. But: All applications, all settings and all my configurations are lost. In addition to that there are many bugs and glitches with the window manager and Unity. I also tried a new installation and this worked better for me.
  • Michael
    Michael about 11 years
    Hi Psusi - I ran these commands (askubuntu.com/questions/89710/…) yesterday on a small laptop and accidentally erased my kernel. By following your instructions in this post I recovered my system in 2 minutes. If I had followed any other instructions I would still have been fighting to recover. Thanks again!
  • Gianluca Della Vedova
    Gianluca Della Vedova almost 10 years
    I can confirm these instructions works also on 14.04
  • mako
    mako almost 10 years
    This answer is incorrect in at least two ways: (1) It does not describe how to repair a system but rather how to backup, remove, and then reinstall your system! (2) It gets the back/reinstalling part wrong too! For reference: /usr/lib/ does not contain a list of packages and neither does /etc/alternatives. If you want a list of packages installed on your system, you can get one easily with: <code>dpkg --get-selections</code> and can restore it with <code>dpkg --set-selection</code> although on the newest version of Ubuntu getting the reinstall to work without dselect can take some effort.
  • mako
    mako almost 10 years
    This is correct but there are several things worth noting: (1) Your root filesystem might not be /dev/sda1. (2) The network will normally not be accessible from within the chroot if you need to download the package with apt-get. (3) If your filesystem is encrypted, not only will it likely not be /dev/sda1 but the new kernel will (having been run from the LiveCD) not include the LUKS cryptsetup tools necessarily to unencrypt your disk while booting. Fixing this is possible, but much harder.