I mistakenly erased one the vmlinuz files in my /boot directory. However, I made a backup of /boot inside /tmp, just to be sure.

Consequently, I cannot boot up, as I get the missing vmlinuz file error. So I booted up using a live USB, but when I got into the /boot dir in my hard drive (sda5), it's completely empty. If I copy the files from /tmp/boot to that /boot directory, I still cannot boot up.

How can I restore those files to the appropriate directory?

  • 1
    Even this older post asked similar question, its answer only explained how to reinstall the packages to restore boot files without explaining chroot steps since the OP there knew how to do by himself. In contrast, the current question is explicitly asking how to restore boot files i.e. using Live USB, in which answer should include steps to do chroot. So I see this question as unique and voted +1. – clearkimura Nov 16 '15 at 14:20

vmlinuz is the Linux kernel image itself (the z indicates that it is compressed).

Reinstalling the kernel package that is currently referenced by linux-image-generic (or your HWE kernel) and probably linux-singed-image-generic in UEFI secure boot environments should solve your issue.

Reinstalling a kernel from a chroot

Preferably boot live media of the same version and mount the partition of your installation (you can do that with Nautilus, it will be something like /media/ubuntu/… then) or your /boot partition (this will be a bit more complex). This will be ${my_installation} in the following instructions.

Look into /lib/modules/ of your installation (${my_installation}/lib/modules/) for the particular kernel versions that were installed and pick the latest version number you can find, this is referenced as ${kernel_ver} in the following instructions, in my test VM it was 3.16.0-46.

As I stated in a comment before, the procedure is very similar to reinstalling Grub in chroot, so let me quote this answer with some slight modifications:

  1. Bind mount some other necessary stuff:

     for i in /sys /proc /run /dev; do sudo mount --bind "$i" "${my_installation}$i"; done
  2. chroot into your Ubuntu install:

     sudo chroot ${my_installation}
  3. At this point, you're in your install, not the live session, and running as root. …

Now reinstall your kernel (the signed package is for UEFI secure boot):

apt-get install --reinstall linux-image-${kernel_ver}-generic linux-signed-image-${kernel_ver}-generic

Check the /boot directory if the initrd for this kernel is still missing. To generate it manually run:

mkinitramfs -o /boot/initrd.img-${kernel_ver}-generic ${kernel_ver}-generic

My example:

mkinitramfs -o /boot/initrd.img-3.16.0-46-generic 3.16.0-46-generic

Then run update-grub like in the quoted answer so that you can be sure that the "new" kernel and initrd are included.

If you need to reinstall Grub too you can follow the the remaining steps. Remember that these instructions were written for MBR, if you have UEFI (where bootloaders from different OSes shouldn't overwrite each other) you need to check that grub-efi-amd64-bin is installed install before reinstalling Grub.

| improve this answer | |
  • 1
    But I cannot do this from a USB live image, can I? – NVaughan Nov 11 '15 at 15:22
  • 1
    Oops you are right, but is should be possible the same way as reinstalling Grub via chroot only that you are installing something slightly different. The live image version must match your installation. – LiveWireBT Nov 11 '15 at 17:17
  • @clearkimura Okay just reproduced it in a VM and updated my answer. – LiveWireBT Nov 16 '15 at 17:47
  • @NVaughan The answer has been updated, so follow the steps and feedback to LiveWireBT if this now works for you? – clearkimura Nov 17 '15 at 8:47
  • hi there, I get an error when I try to apt-get install... error is: cannot stat 'usr/share/syslinux/themes/debian-wheezy/extlinux/memtest.bin' no such file or directory failed to process /etc/kernal/postrm.d – Paul Preibisch Dec 22 '15 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.