Removing all kernel headers and images from my computer: I did it!!!

This post could be subtitled: because I only have half a brain. But fortunately

  1. first, it was not my computer but my son’s computer (and I don’t give a s*** to his computer which mainly contains video games);
  2. second, using half a sleepless night, I finally succeded to fix this problem.

Episode 1: the accident

My son’s computer is equipped with xUbuntu 14.04 LTS and LVM volume manager and I am naive enough to let him manage it by himself. Unfortunately, he does not read his mom’s blog and when he encoutered the very simple problem described in this post, he just stopped to upgrade his OS. I am the best mom ever so started to fix this issue and cleaned up a bit of the mess he has generated. I just only use an unecessary star; never, ever run the following command line:

sudo apt-get remove --purge linux-image-3.13.*-generic linux-headers-3.13.*-generic

because it will remove all linux kernels and images. I just wanted to remove the older one but was too quick writing the command line and forgot to put the critical 0-4 before the star… Ok, that’s brainless (I am a woman, it can maybe explain things) and worst of all: I rebooted just after this brillant action…!!! In this case, what happens is pretty simple: your /boot directory only contains the following files:

memtest86+.bin      memtest86+.elf      memtest86+_multiboot.bin

and the grub menu then tells your computer to directly boot on the memory test utility.

Episode 2: a problem never comes alone

I already had a very similar problem during the upgrade of an older linux distribution before (see this post for further references). However, in the previous case, I was using a standard volume management whereas my son’s computer uses LVM. Hence,

  1. booting on an external USB device
  2. trying the standard
    sudo mount /dev/sda5 /mnt
    

    to mount the main linux partition / gives the following error message:

    mount: you must specify the filesystem type
    

Episode 3: Best Mom Ever solves the damned problem that she has herself created

So after a few tests, I found the solution which consisted in:

  1. booting on an external USB device
  2. mounting the LVM volume partition on the USB device’s system with the method described on this page: first, the list of partitions is obtained with:
    sudo pvs
    

    which (in my case) gives:

    PV          VG          Fmt     Attr     PSize     PFree
    /dev/sda5   xubuntu-vg  lvm2    a--      465.52g   52,00m
    

    and indicates that the volume group to which our physical volume /dev/sda5 belongs is called xubuntu-vg. Then the command

    sudo lvdisplay /dev/xubuntu-vg
    

    starts with

    LV PATH     /dev/xubuntu-vg/root
    LV Name     root
    VG Name     xubuntu-vg
    

    and it can thus be mounted with:

    sudo mount /dev/xubuntu-vg/root /mnt
    
  3. The purpose is now to chroot into /mnt which contains the computer’s system. Before doing so, a few additional directory has to be mounted:
    sudo mount --bind /dev /mnt/dev
    sudo mount --bind /proc /mnt/proc
    sudo mount --bind /sys /mnt/sys
    sudo mount --bind /var/run/dbus /mnt/var/run/dbus
    

    and most importantly,

    sudo mount /dev/sda1 /mnt/boot
    

    to mount the /boot directory of your computer before chrooting into it.

  4. chrooting into /mnt with
    sudo chroot /mnt
    

    To check that everything was OK, I did:

    cd /boot
    ls
    

    which confirmed that the /boot directory only contained:

    memtest86+.bin      memtest86+.elf      memtest86+_multiboot.bin
    

    At this stage, if /boot is empty, you have failed to mount the /boot directory of your system.

  5. Now, simply fix the problem by installing the current linux header and image:
    sudo apt-get install linux-image-generic linux-headers-generic
    

    and everything should be just fine at the next reboot.