A cute little backup disk, and reinstalling grub-efi

At work I requested a new portable drive to which I can backup my notebook’s files – backups are always a good idea. After looking up the available models I opted for a small 500GB SSD from Korean maker (and market leader) Samsung, the T5. And it’s tiny as you can see:

Samsung T5 SSD, image is from their website

And yesterday I installed Debian 10 “Buster” onto it, making use of encryption – I changed that again today since my notebook refused to even “see” it as a vaild and connected USB device, so I reformatted it at work and also made my first backup.

This installing of Debian at my home machine had consequences tho – I somehow managed (like with the latest Windows 10 update as well) to corrupt my grub-efi boot sector so that I was able to still boot into Windows, but not into Linux, my main work system (I keep Windows only for the Olympus and some free (giveaway) music programs, but almost never use these).

So in case you should end up with that

grub>

boot sector message instead of a menu with options to boot one day, here’s what you can do.

First, don’t panic! Your system isn’t severely damaged, and everything can be repaired quite easily. If you want to make sure that everything is still where it belongs, try this:

grub> ls

will give you a list of hard drives and partitions, depending on what is installed in your system. In mine, I have two physical hard drives, the first one with several partitions (like EFI, Windows, Linux, and so on), the second and much bigger one is only for my /home directory. So these are easy to identify. I also know that my Linux system is on partition 6 (in the following, the variable ‘y’ represents it) of hard disk 1 (in the following, the variable ‘x’ stands for that one). So type in the following lines, setting the disk number instead of ‘x’ and the partition number instead of ‘y’:

grub> set root=(hdx,y)
grub> set prefix=(hdx,y)/boot/grub
grub> insmod normal
grub> normal

At this point, you should see something like your normal grub menu from which you can start your system.

Once in it, you can’t repair it from here tho – you need to start it another way to do that, using your installation media (in my case, this was a USB stick) which itself is EFI-formatted, and using a GPT instead of the old legacy MBR boot sector. So don’t throw away that CD or DVD after installation, or make a new USB startup disk with Debian Live on it. You might have to press some keys during startup to get your BIOS to boot from that one, make sure to use it in GPT (EFI) boot mode.

Once that image is up, the by far best and easiest description I have found to go on is the one on askubuntu.com. You may need some program (they mention gparted which isn’t available on a Debian Live image, but another program called ‘disks’ is) to again identify your partitions and device identifiers, which they describe with ‘x’es in the following.

The highest rated of the current 7 answers (with 48 votes as I write this) is the one which works flawlessly. Here it is:

Reinstall the GRUB boot loader to your Ubuntu installation in EFI mode this way …
Boot from the Ubuntu installation medium and select ‘Try Ubuntu without installing’.
(Boot your install medium in EFI mode, select the Ubuntu entry with UEFI in front.)
Once you are on the Live desktop, open a terminal and execute these commands :

sudo mount /dev/sdXXX /mnt
sudo mount /dev/sdXX /mnt/boot/efi
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
sudo chroot /mnt
grub-install /dev/sdX
update-grub

Note : sdX = disk | sdXX = efi partition | sdXXX = system partition
To identify the partitions use GParted, the tool is included in the installation medium.
After having run the commands GRUB will be installed in the separate EFI partition.

And that should be it – this solution from user ‘cl-netbox‘ works as described. So should you ever need this, please go and thank him (or her) instead of me.

So I’m typing this from my repaired system. Life is great.

As always, thanks for reading.