mistakenly deleted /boot folder and rebooted

I mistakenly deleted the /boot folder from my filesystem, rebooted, and all I get now is this:

error: file '/boot/grub/i368-pc/linux.mod' not found.

grub rescue>

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Oops!

Here’s what to do:

  1. Boot a live distro. This can be your Ubuntu installation disc or another one such as Knoppix.
  2. Find the drive/partition where you have installed your root filesystem. To do this you can open a terminal and run either sudo parted -l or sudo fdisk -l. If you can’t tell, then edit your question and add the output.
  3. Assuming that your root partition that you found from the last step is /dev/sdxy (x should be another letter and y should be a number), then run the following commands in a terminal:
    mkdir mnt
    sudo mount /dev/sdxy mnt
    sudo mount --bind /dev /mnt/dev
    sudo mount --bind /proc /mnt/proc
    sudo mount --bind /sys /mnt/sys
    sudo chroot mnt
  4. You will now be inside a chroot environment meaning that running commands here is equivalent to running them on your installed system. The first thing you want to do is reinstall GRUB2 to the device so that it copies the correct files into the /boot folder. To do this run the following with the drive that your root partition is on (ie /dev/sdxy with the number (y) removed):
    grub-install /dev/sdx
  5. You now want to find out which packages you have installed that have files in the boot directory and reinstall them. This will replace the kernel images that have been deleted among other things. The command to find the packages is:
    dpkg -S /boot

    And to reinstall them:

    apt-get --reinstall install ...

    Where ... is replaced with the names of packages from the first command. Do not include the commas, just have the package names with spaces to separate.

    This step will probably require internet access (unless the packages are already in the cache), so make sure you are connected if there is an problem.

  6. Since you will have deleted your kernels and reinstalled them, this should have triggered a GRUB2 update automatically. But just in case they haven’t, you can run:
    update-grub
  7. Reboot and things should now be fixed. One issue that I had the last time I did something similar was that Windows installs where not found by update-grub when run in the chroot due to a bug in os-prober. If this is an issue, just run sudo update-grub again in the repaired system.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x