Reinstalling Grub from an USB

Here is how to reinstall your Grub if it has been wiped out by a Windows install for example. This will deal with a small Debian Live USB.

The easiest solution would be to create an Ubuntu Live USB and to follow these instructions. For small USB keys, it’s best to use a Debian netinstall, which weighs around 10M.

Create live usb

First, we need to ensure the usb has a partition with the correct format. As a superutilisateur run:

$ fdisk /dev/sdc

whire /dev/sdc is your USB partition (the whole device, so not /dev/sdc1 which is a partition). Then create a FAT32 partition:

n
p
1
[Enter]
[Enter]

Make it FAT32:

t
b

Make it bootable and write the change to disks

a
w

Finally, format it, just to be sure :

$ mkfs.vfat /dev/sdc1

Now we need to copy an image on it. The first solution is to use a program called unetbootin and follow the instructions.

If it does not work, get the .iso and write it on the device (not the partition):

$ dd if=my.iso of=/dev/sdc

Reinstall grub

Now boot from the USB, start install and go to partitoning step. Then go the the shell with Alt-F2. Mount the partition containing your root folder, along with /dev :

$ mkdir /target
$ mount /dev/sdb1 /target
$ mount --bind /dev /target/dev

Chroot into it and reinstall grub (to the correct device, which should be (hd0) but do not take my word for it):

$ chroot /target
$ grub-install '(hd0)'

And there you are, just reboot and everything is back to normal.