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>
Here's what to do:
Boot a live distro. This can be your Ubuntu installation disc or another one such as Knoppix.
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.
Assuming that your root partition that you found from the last step is
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
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 (
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 ...
... 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.
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:
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.