Starting with Windows 8 most Desktop PC have EFI as firmware instead of the legacy BIOS. If your EFI based PC is not booting Debian, here are some ways to reinstall grub-efi, the bootloader used by Debian on these PCs.
To reinstall grub, you need either a live CD/USB to access your current system, or you can use the rEFInd boot manager on a live CD/USB to boot your current system.
Using A Live CD/USB To Fix Your Current System
(The following procedure is described in greater detail here.)
Boot (using UEFI) into a live system, such as a DebianLive CD/USB or the Debian installer in rescue mode. You can verify that the system has booted using UEFI by checking for the existence of the directory /sys/firmware/efi or by running efibootmgr.
- If the directory /sys/firmware/efi/efivars is empty, you need to boot the rescue system including the kernel option "efi=runtime" and mount the EFI variables before proceeding:
# mount -t efivarfs none /sys/firmware/efi/efivars
Mount the broken system somewhere into the running filesystem. The exact details of how to do this depend on the particulars of your installation. For example, for a system with an EFI partition on /dev/sdb1, an unencrypted /boot partition on /dev/sdb2, and a LUKS-encrypted / partition on /dev/sdb3, do:
# cryptsetup luksOpen /dev/sdb3 crypt # mount /dev/mapper/crypt /mnt # mount /dev/sdb2 /mnt/boot # mount /dev/sdb1 /mnt/boot/efi
- Bind mount various virtual filesystems:
# for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run; do sudo mount -B $i /mnt$i; doneThe mount executable supplied with busybox does not support the -B option, use "mount -o bind" in this case.
- Chroot into the broken system:
# chroot /mnt
- Reinstall GRUB to the appropriate disk (without partition number):
# grub-install /dev/sdb
- Generate the GRUB configuration file:
Exit the chroot environment (<CTRL>-D).
- If everything worked, reboot.
Using the rEFInd rescue media
At the author's web page, http://www.rodsbooks.com/refind/getting.html, you will find updated direct links to all sorts of packaging. To boot from a rescue media, select either the CD ISO image or the image for USB sticks. Most firmware offers the choice nowadays. If choosing the latter, make sure to follow the instructions in the README. It is recommended to read the author's web pages to get a better understanding of what you are doing.
Boot your computer with the Refind media
rEFInd will parse your hard drive for installed kernels, and provide you a graphic menu to boot them. Choose your Linux Kernel and boot it.
Reinstalling grub-efi on your hard drive
Check that the computer booted in computer in EFI mode:
[ -d /sys/firmware/efi ] && echo "EFI boot on HDD" || echo "Legacy boot on HDD" should return "EFI boot on HDD".
After starting a root shell (if you boot from a live media, you should start a chroot shell instead, as explained here) check that your EFI system partition (most probably /dev/sda1) is mounted on /boot/efi. If the /boot/efi directory does not exist, you will need to create it.
mount /dev/sda1 /boot/efi
Reinstall the grub-efi package
apt-get install --reinstall grub-efi
Put the Debian bootloader in /boot/efi and create an appropriate entry in the computer NVRAM
Re create a grub config file based on your disk partitioning schema
You should check afterwards that:
Check 1. the bootloader is existing in /boot/efi/EFI/debian/grubx64.efi
file /boot/efi/EFI/debian/grubx64.efi /boot/efi/EFI/debian/grubx64.efi: PE32+ executable (EFI application) x86-64 (stripped to external PDB), for MS Windows
Check 2. the NVRAM entry was properly created.
efibootmgr --verbose | grep debian
You can now reboot, and Grub should greet you.
If after this steps you're not booting, the EFI of your PC might have some bugs.
Problem1: Weak EFI implementation only recognizes the fallback bootloader
The UEFI firmware refuses to boot the debian/grubx64.efi bootloader, and so we have to hijack the UEFI fallback boot loader. See http://mjg59.livejournal.com/138188.html for details.
Using Debian installer in rescue mode, /dev/sda1 being the FAT32 ESP partition, /dev/sda2 the root partition
mkdir /target mount /dev/sda2 /target mount /dev/sda1 /target/boot/efi for i in /sys /proc /dev; do mount --bind $i /target$i; done chroot /target
cd /boot/efi/EFI mkdir boot cp debian/grubx64.efi boot/bootx64.efi exit for i in /sys /proc /dev; do umount /target$i; done umount /target/boot/efi umount /target
Once booted into your normal Debian, tell grub to ensure the fallback boot loader up to date. To do that, run the following:
echo "grub-efi-amd64 grub2/force_efi_extra_removable boolean true" | sudo debconf-set-selections
Note: The above command will permanently hijack the fallback bootloader, which might be undesirable in dual-boot setups.
Problem2: EFI boot entries disappear after reboot
The UEFI firmware did not create a proper boot entry in NVRAM. This has been seen in a Lenovo Thinkcenter M92Z. The symptom for this will be a missing HD path after the Debian entry in the efibootmgr --verbose output.
BootCurrent: 0024 Timeout: 0 seconds BootOrder: 0024,0022,0023,0016,0000,0001 Boot0000* debian Vendor(99e275e7-75a0-4b37-a2e6-c5385e6c00cb,) Boot0016* Generic Usb Device Vendor(99e275e7-75a0-4b37-a2e6-c5385e6c00cb,) Boot0022* UEFI: IPv4 Intel(R) 82579LM Gigabit Network Connection ACPI(a0341d0,0)PCI(19,0)MAC(d43d7e6d8bfc,0)IPv4(0.0.0.0:0<->0.0.0.0:0,0, 0AMBO Boot0023* UEFI: IPv6 Intel(R) 82579LM Gigabit Network Connection ACPI(a0341d0,0)PCI(19,0)MAC(d43d7e6d8bfc,0)030d3c000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000AMBO Boot0024* UEFI: Generic Flash Disk 8.00 ACPI(a0341d0,0)PCI(1d,0)USB(1,0)USB(1,0)HD(1,800,2a5f,02f23208-1aa9-4b6c-b6e1-8155390eb9db)AMBO
You can then try to install rEFInd as your bootloader in the hard drive, following the steps at this gist: https://gist.github.com/EmmanuelKasper/9590327.