4

No laughing!

I just did sudo rm -vr /boot/*. Is there a way to restore the content?

Just to clarify why I would do this: I have a SD-card with a boot-partition mounted at /media/boot that I wanted to replace.

The computer is still running. What are my options?

Update (my solution): This might be a little unsatisfactory for future reference, but I simply backed up all my files and then reinstalled Ubuntu.

Important note if you have the same problem: Don't turn off your computer until you have everything backuped

6
  • You are not the 1st: unix.stackexchange.com/questions/13654/… ;)
    – Rinzwind
    May 2, 2012 at 19:12
  • He'll also need to put back the OS files. I don't think reinstalling grub will do that, although I didn't read the link. Of course, being Rinzwind, I guess you know the magical incantation to do this. :) May 2, 2012 at 19:14
  • @Rinzwind: I will try to not reboot, but at some point I will have to.
    – Lucas
    May 2, 2012 at 19:18
  • My motto (stolen from a usenet personality on ba.internet) is "Learn by destroying". But it helps to have backups. I usually have several distros sitting around on my drives, so I can just go in and copy files back into the directory, if necessary. It's not really that big a deal. May 2, 2012 at 19:20
  • Since its still running, I think I will simply back up everything and then reinstall.
    – Lucas
    May 2, 2012 at 19:22

2 Answers 2

4

You can restore /boot from a live CD using a chroot.

http://ubuntuforums.org/showpost.php?p=11893615&postcount=2

Assuming ubuntu is installed in /dev/sda1 ...

sudo mount /dev/sda1 /mnt
sudo cp /etc/resolv.conf /mnt/etc/

Depending on your configuration, you may also need to copy the hosts file

sudo cp /etc/hosts /mnt/etc/

mount /mnt/dev and chroot, configure the chroot

sudo mount --bind /dev/ /mnt/dev
sudo chroot /mnt /bin/bash
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devpts none /dev/pts

To avoid locale issues and in order to import GPG keys

export HOME=/root
export LC_ALL=C

Restore grub

grub-install /dev/sda

If that does not restore the grub files in /boot, reinstall grub first apt-get install --reinstall grub2 grub-install /dev/sda

Reinstall the kernel

apt-get install --reinstall linux-gnereic
3
  • but 1st make a backup ;) (still smiling)
    – Rinzwind
    May 2, 2012 at 19:54
  • 1
    This sounds very interesting, but I just backup-ed my files and reinstalled Ubuntu. So I unfortunately I cannot verify if this works.
    – Lucas
    May 3, 2012 at 14:56
  • Since I have the same issue (wiped the /boot folder and with it the whole EFI partition) I wanted to know if this could also work, when I'm currently running a BIOS Ubuntu and want to chroot into a UEFI Ubuntu (the one with the empty /boot folder).
    – mark
    Apr 9, 2021 at 20:58
1

Unless you have backups, then the answer is "You can't."

The OS does not keep a backup of that folder for you (or any other to my knowledge) without you expressly telling it to by installing or configuring a backup program.

Your best way forward IMO is to quickly backup any and all files you need to keep from this machine, and reinstall the operating system. I've marked this answer as community wiki so that if I'm wrong, people can update my answer with a note indicating that there's a better way. You may want to wait a day or two if you can in case anyone posts a better answer.

1
  • You could probably reinstall the relevant packages tho, to avoid a reinstall. If you rebooted, you could boot a livecd, and chroot into the system and reinstall the packages.
    – vidarlo
    Aug 13, 2017 at 13:25

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.