Rough guide to grub-efi-amd64 on Debian Wheezy

This is a rough guide on how to get Debian testing (wheezy) to boot from UEFI.  I’ve tried on Squeeze but unfortunately there’s so many bugs in it that it basically fails for me on an Intel S1200BTL motherboard with AMI Aptio UEFI.

The Debian Installer CD does not yet boot from UEFI itself so the process is made a little bit more complex than it might otherwise be.

Step 1 – Preparation

  1. Back up your data.
  2. Please make a copy of your data for safe keeping purposes.
  3. Store a second copy of your data somewhere where it won’t get wiped.
  4. Have you backed up your data yet?
  5. Backing up your data is a really good idea.
  6. Please back up your data, and do it now before you forget.
  7. Reminder – don’t forget to back up your data.
  8. I’d install a copy of backup software and use it if I were you at this point.
  9. Backing up is a good idea.
  10. You are strongly advised to do your backups before you attempt steps 1-9.
  11. Burn yourself a Debian Installer CD so that you can recover if it all goes wrong.
  12. Make sure the CD you’ve just burned actually works.

Step 2 – Make sure you have an EFI System Partition

UEFI machines require a special partition called an ‘EFI System Partition’ to store boot loaders and other assorted drivers from, unless you fancy installing GRUB2 to a USB stick, that is.  100MiB seems a reasonable size for it and must be FAT32 formatted otherwise the UEFI probably won’t see it.  If you are going to be installing Microsoft products on this box, then you should make it the first partition, but the UEFI standard itself doesn’t require this.  If you are using GPT partition tables, the EFI System Partition needs to have a type GUID code of C12A7328-F81F-11D2-BA4B-00A0C93EC93B (if you are using parted to make your partitions you can turn a partition into an EFI System one by running the command set <partition-number> boot on which will set this for you.  MBR (“normal”) partition tables should use partition type 0xEF for it.

When you create it, it should be formatted with a FAT32 file system and you must ensure that it has a directory called efi placed in the root directory.

Step 3 – Boot into your existing Debian system

If you haven’t already, boot up your existing Debian system and log in as root.  Please ensure you have a working grub-pc (BIOS) configuration (i.e. GRUB 2) before you go any further.  If you are still using GRUB 1, then upgrade to GRUB 2 and get it working before you carry on.

Install the grub-efi-amd64 package using aptitude or apt-get.  This conflicts with the grub-pc package and will cause the old ‘BIOS’ grub to be removed.

Mount your EFI System Partition on to /boot/efi, and it’s a good idea to make sure it’s always mounted on boot by altering the fstab.

Now run grub-install (The EFI version does not require any parameters).  This should install the grub-efi files to your EFI System Partition.  Once the installation is complete, you should find a single file in \efi\debian called grubx64.efi.

Important – Check your grub.cfg to make sure that it loads the efi_gop module in the load_video function.  If it doesn’t, your computer will boot, but you won’t see the screen display!  (Some old UEFIs may need efi_uga instead, but most UEFIs use efi_gop these days.)

Step 4 – First UEFI boot

The first time you boot from this, there will be no entry in the UEFI boot manager to start it up automatically, so you’ll need to go into the EFI Shell and boot grub2 by hand.

Shut down your machine, and reboot into the UEFI setup and switch mode from BIOS to UEFI.  (Not all UEFIs need this step – some like my AMI Aptio has a mode which will let you boot from either BIOS or UEFI).

Boot into the EFI Shell.  At the prompt, type in fs0: to switch to the EFI System Partition, and then type \efi\debian\grubx64.efi to start GRUB manually.  If all has gone well, you should be rewarded with the bog standard GRUB2 boot menu as normal.  Choose your kernel and off you go!  Don’t forget to congratulate yourself that you managed to UEFI boot your Debian install on the way!

Step 5 – Reinstall grub2

This may sound a bit silly, but it’s the easiest way of getting a boot option into the UEFI boot manager.  Once your machine has succesfully booted again, load the efivars module by typing modprobe efivars, make sure the EFI System Partition is mounted at /boot/efi, and then run grub-install again, then update-grub.  You should find now, if you run efibootmgr, that you should have an entry “debian” in there which will boot the new grub install you have just made.

Finally, make sure that efivars module is loaded every time you boot by inserting it into the /etc/modules file.