[Revised]HOWTO: AMD64 Debian GNU/Linux and UEFI

Share your own howto's etc. Not for support questions!

[Revised]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby hkoster1 » 2012-06-24 14:15

This HOWTO describes switching an installation of stable/Wheezy from booting in BIOS mode to UEFI mode on a computer that supports both BIOS and UEFI firmware.

Note that the Debian Installer (D-I) for AMD64 testing/Jessie already correctly boots and installs on a computer with UEFI firmware, putting in a GUID partition table (GPT) on a raw drive in the process. The D-I for stable/Wheezy, however, only boots and installs in BIOS mode; now UEFI booting can be implemented afterwards as long as the computer can be switched from BIOS to UEFI mode.

My example PC is a VMware virtual machine, for which switching from BIOS (the default) to UEFI is as simple as adding the line firmware = "efi" to its .vmx file. Consult the manual of a physical PC on how this must be done in the setup menu.

Note that the 'secure boot' option of UEFI is a different matter that only plays on computers on which Microsoft's Windows~8 is the principal OS.

The Preliminaries
The UEFI Boot Manager searches by default VFAT-formatted partitions for an /efi/boot/bootx64.efi boot loader and uses the first one that is found. It is customary to provide an EFI Systems Partition (ESP) on the HD specifically for that purpose, usually as the first (primary) partition on the HD. This partition should preferably be 200--500 MB in size, with room for other OS'es and boot loaders.

If an existing ESP isn't large enough, then I recommend copying its contents to a memory stick and replacing that content after the HD has been (re)partitioned or resized.

HD partitioning or resizing
UEFI can work both with the older MBR partition table and with the newer GUID Partition Table (GPT). If you're going to repartition the HD, then you might as well use GPT, as it does away with the distinction between primary and logical partitions. The Wheezy D-I partitioner can work with GPT, but does not offer an option for installing it on a raw drive.

Installing GPT can be done with a liveCD like PartedMagic before starting the Wheezy D-I. The alternative is to let the Wheezy D-I install an MBR partition table instead.

In either case, with GPT or MBR, room should be found on the HD for the ESP as a primary partition, e.g. 500 MB formatted with FAT32. It does not have to be the first partition on the drive, but it simplifies things if it is. I assume in the following that the ESP is /dev/sda1.

Note that the Wheezy D-I will in the presence of GPT also make a tiny 1MB BIOSGRUB partition, which will remain unused after the switch to UEFI booting.

Switching from BIOS to UEFI
With Wheezy (or later) properly installed and booting in BIOS mode, we now prepare for the switch to UEFI booting. All commands below are to be run with root privileges.

Configuring GRUB for UEFI
We mount the ESP (assumed to be /dev/sda1) on the newly-made mount point
Code: Select all
# mkdir /boot/efi
# mount /dev/sda1 /boot/efi
Next, prepare for and install the proper version of GRUB,
Code: Select all
# modprobe efivars
# aptitude install grub-efi-amd64
# grub-install /dev/sda
# update-grub
which also removes the grub-pc package used for BIOS. Error messages about procfs and sysfs may be ignored, but GRUB itself should report that it installed without error.

Configuring UEFI for GRUB
The above installation has installed the /EFI/debian/grubx64.efi boot loader on the ESP, which can be used provided that we let UEFI know of its existence. We can do this in two ways: simple, suited for Debian GNU/Linux as the only bootable OS; and not-so-simple, also suited when there are multiple boot options.

Since we are still in BIOS mode at this stage, we must do it first the simple way. The more complicated way can be implemented after rebooting in UEFI mode. For the simple way we need only copy and rename grubx64.efi as follows,
Code: Select all
# mkdir /boot/efi/EFI/boot
# cp /boot/efi/EFI/debian/grubx64.efi \
                  /boot/efi/EFI/boot/bootx64.efi
The UEFI Boot Manager will, in the absence of other instructions, find this renamed boot loader and use it. Use of upper and lower case letters in the path is optional.

The computer may now be rebooted in UEFI mode, after first enabling UEFI booting in the computer setup menu.

More UEFI boot options
The UEFI Boot Manager looks at non-volatile RAM (NVRAM) on the motherboard for additional instructions, which may be provided or changed with efibootmgr, which also relies on kernel module efivars.

Instead of letting the UEFI Boot Manager look for a bootx64.efi boot loader in a default path, we can tell it specifically where our grubx64.efi is located with the commands
Code: Select all
# modprobe efivars
# efibootmgr -c \
             -l "\\EFI\\debian\\grubx64.efi" \
             -L "Debian GNU/Linux"
This is in effect the method used by the D-I for testing (Jessie) when installing on a computer in UEFI booting mode. The output of that latter command will also show a numbering for other boot options, like CD/DVD and PXE network booting. The last-installed option, our Debian GNU/Linux, was given number 0004 in my case, and was automatically made the default option. Should this not be desired, then we can for example issue the command
Code: Select all
# efibootmgr -o 3,4
to make boot option 0003 the default.

The UEFI boot menu
Consult your computer manual on how to reach the UEFI boot menu at startup; on my VMware Fusion VM this needs hitting the fn-F2 key. Two items in the UEFI menu are of interest: Boot Manager and Boot Maintenance Manager.

Boot Manager
This menu item shows all bootloaders that are stored in NVRAM, such as our GRUB installed with efibootmgr. The desired bootloader can be chosen in this menu when it is not the default.

Boot Maintenance Manager
This menu item contains the option to Boot from a File, and gives a choice of available (VFAT-formatted) partitions. We can find the boot loader of our choosing by following the appropriate path. This way, our computer stays bootable in case something went wrong during the earlier switch-over.

The UEFI boot menu does the job, yet is rather stark-looking, while entering it requires a quick reaction during the initial startup. I'll discuss the nice-looking rEFInd boot manager in the follow-up to this post.

Enjoy!
Last edited by hkoster1 on 2014-02-02 21:00, edited 30 times in total.
Real Debian users don't do chat...
hkoster1
 
Posts: 1256
Joined: 2006-12-18 10:10

UEFI boot options with rEFInd

Postby hkoster1 » 2012-06-29 09:37

The rEFInd menu is a good-looking alternative to the UEFI menu, with some important advantages: you don't have to be super-quick with a function key to start it, and it handles all boot choices on the ESP without having to first store them in UEFI NV-RAM.

rEFInd is a fork of the once-popular but no longer maintained rEFIt boot menu used to boot GNU/Linux in MBR-legacy mode on recent Mac computers. rEFInd can be downloaded from http://www.rodsbooks.com/refind/. The documentation on that site may appear a little daunting, so here are a few pointers on installing rEFInd that tie in with the HOWTO:

a. At minimum two files are needed from the rEFInd archive, refind_x64.efi and refind.conf, the latter an edited version of refind-sample.conf. You'll also need a subdirectory of icons and other graphical features to make for a nice-looking menu.

b. Simplest, in terms of the HOWTO, is to do the installation manually directly to the ESP, mounting it first if not already mounted, e.g.
Code: Select all
# mount /dev/sda1 /boot/efi
# mkdir /boot/efi/EFI/refind
# cp refind_x64.efi refind.conf /boot/efi/EFI/refind/
# cp refind_x64.efi /boot/efi/EFI/boot/bootx64.efi
where that last line will make UEFI boot into the rEFInd menu by default. Copy also any icon files, etc, as per the documentation on the rEFInd website.

c. An alternative to step b. is to use efibootmgr to add rEFInd to UEFI's NV-RAM, as described in the HOWTO. Either way will work.

d. You may have to move the bootloader of "that other OS" from /boot/efi/EFI/boot/ to a separate subdirectory /boot/efi/EFI/<otherOS>/,
Code: Select all
# makedir /boot/efi/EFI/<otherOS>
# mv /boot/efi/EFI/boot/<otherOS>.efi /boot/efi/EFI/<otherOS>/
# umount /dev/sda1
Your PC now boots into the rEFInd menu on startup, giving you your choice of bootloaders.

Enjoy!
Last edited by hkoster1 on 2014-02-02 21:09, edited 5 times in total.
Real Debian users don't do chat...
hkoster1
 
Posts: 1256
Joined: 2006-12-18 10:10

Re: [Updated 2x]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby hkoster1 » 2012-10-18 17:47

Good news for those of you interested in UEFI-booting your AMD64-versions of Debian GNU/Linux: the Beta3 version of the D-I for Wheezy has just been announced to allow installation with only UEFI-booting, so without the BIOS detour of my HOWTO.

I now had a chance to try it out on a virtual machine with "efi" firmware (VMware Fusion 5), where I can confirm that everything installs fine. The D-I doesn't say so explicitly, but it installs a GUID Partition Table (GPT) on a virtual drive that has none. I confirmed that by checking afterwards with 'parted'. With GPT already in place, the partitioner automatically installs an EFI boot (or systems) partition.

Only when the partitioner detects an MBR partition table, is the user asked to install an EFI boot (or systems) partition manually.

Anyway, it seems that the D-I for Wheezy can handle all typical UEFI boot cases from a hardware point-of-view. My HOWTO can still give some pointers on the processes involved, while my second post in this thread points the way to using a nice-looking boot manager.

Enjoy!
Real Debian users don't do chat...
hkoster1
 
Posts: 1256
Joined: 2006-12-18 10:10

Re: [Updated 4x]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby hkoster1 » 2012-12-29 09:57

A new grub-efi-amd64 package has just (29 December 2012) entered Sid. When I installed it as an upgrade, I noticed that its install script automatically puts the Debian boot option as first-to-boot in NV-RAM, even if prior to that the simple default method was used. No man overboard if that is what you want.

Since I don't boot any other OS on this computer, I don't know what happens when another OS should boot first. If this situation pertains to you, a heads-up would be in order.
Real Debian users don't do chat...
hkoster1
 
Posts: 1256
Joined: 2006-12-18 10:10

Re: [Updated 4x]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby YetAgain » 2013-02-14 05:34

Thanks for the excellent posts. They were a big help in installing Wheezy on my new PC.

I used the Beta4 version of the Debian Installer for Wheezy which can install a GPT, EFI systems partition, and appropriate Grub image to a new hard drive without special intervention if the drive (CD-ROM, DVD, USB, etc.) containing the Debian Installer is booted in UEFI mode. Unfortunately in my case, I could not figure out how to boot the CD drive containing the installer in UEFI mode (because no such option was given) so I booted in BIOS mode and followed the instructions in the posts above. Interestingly enough, once the hard drive was set up for UEFI, UEFI mode appeared as an option for the CD drive. Having the UEFI mode option show up at this point was too late for the installer to install an EFI system partition by default, but it was useful for re-installing Grub with a proper UEFI image as explained at the bottom of this posting.

I have a ASUS M5 A99X EVO motherboard. Maybe someone else can explain how to get the "BIOS" for this board to boot the CD drive in UEFI mode with blank hard drives installed. That would make all the extra work described below unnecessary.

Below is an overview of the installation process I went through, covering mainly the steps that were outside the normal Debian Installer installation process. This was performed around December 29, 2012.

Initially I tried installing a "Squeeze" release of the AMD64 Debian installer. This did not have the capability to write a GPT partition table, EFI system partition, and other items needed for UEFI booting.

I ended up using debian-wheezy-DI-b4-amd64-netinst.iso (Debian Installer, Beta4) which I obtained at http://cdimage.debian.org/cdimage/.

I booted the CD and followed the installation process until I got to the hard drive formatting. At the formatting stage, I chose manual partitioning of the drive instead of guided partitioning.

The Debian Installer did not give me an option to make a partition the UEFI system partition as it does in UEFI mode. Instead I set my first partition (the intended UEFI system partition) to "Fat32 file system" under the "Used as" option. I did not set a mount point for this partition but did set it as bootable. I used the installer to format the rest of the partititions with the options appropriate for my partitioning scheme.

I used the Debian Installer to continue with the installation until I got to the bootloader installation step.

GRUB Installation:
I exited to the shell and followed the procedure in step 4 of the first post above. Everything went fine until I ran aptitude to install grub-efi-amd64. I was asked to install the installation CD into /media/cdrom. However, the installation CD was already mounted. A little investigation revealed that I lost access to the cdrom when I chrooted into /target. To fix this I had to exit the chroot, mount the cdrom under /target/media/cdrom and then chroot back to /target as follows:
Code: Select all
# exit
# mount -o bind /cdrom /target/media/cdrom
# chroot /target

I was able to install grub. However running update-grub returned a fatal error about missing proc and sys efivars. My assessment is that the computer must be booted in UEFI mode for update-grub to create a proper grubx64.efi file. Despite the error, I continued on following step 5 and step 6 in the first post by copying /boot/efi/EFI/debian/grubx64.efi to /boot/efi/EFI/boot/bootx64.efi and exiting from the chroot. I tried rebooting to the hard drive but it was not bootable.

Fixing GRUB:
The solution was to boot to the Debian Installer on the CD drive in UEFI mode (which was now an option in the BIOS), run the installer in rescue mode, re-run "update-grub", and then copy grubx64.efi over again.

In more detail, upon booting GRUB on the CD there was a quick message saying, "Welcome to GRUB. Error 'prefix' is not set" and then the installer menu appeared. The installer menu appeared different in UEFI mode than it did in BIOS mode. I selected rescue mode("Debian 7.0 text-mode rescue (64-bit, EFI)"). After asking the questions about the keyboard, language, etc., the installer asked which partition I would like to install as root. Since my root partition was on the 3rd partition of sdb, I selected /dev/sdb3. I then selected "Execute a shell in /dev/sdb3". /usr and /boot were on separate partitions so I had to mount them to access them. They were already listed in fstab so I simply entered:
Code: Select all
# mount /usr
# mount /boot

Mounted the EFI system partition on /boot/efi
Code: Select all
# mount /dev/sdb1 /boot/efi

Re-ran "grub-install /dev/sdb" (may not have been necessary) and "update-grub". Then copied /boot/efi/EFI/debian/grubx64.efi to /boot/efi/EFI/boot/bootx64.efi.
The /boot/efi/EFI/boot directory was left over from the first time I tried copying grubx64.efi over to bootx64.efi so I did not need to create it this time.

After exiting rescue mode and rebooting to the hard drive in UEFI mode the system booted.
YetAgain
 
Posts: 12
Joined: 2011-02-18 06:05

Re: [Updated 4x]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby buntunub » 2013-03-02 01:25

I ran the wheezy installer and it just plopped that EFI garbage in and screwed up my dual boot pretty badly. I still cant get windows to boot. At all. I have a legacy system so no clue how this happened and I did nothing different than I normally do when installing Squeeze.
User avatar
buntunub
 
Posts: 505
Joined: 2011-02-11 05:23

Re: [Updated 4x]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby hkoster1 » 2013-03-03 11:51

That's tough, but that's what can happen when you install a Beta-release. FWIW, the current release notes do address possible UEFI problems...

Why not file a bug report? Start a new thread outside the HOWTO section?

Edit: I see you already started an "install saga" thread... got that off your chest.
Real Debian users don't do chat...
hkoster1
 
Posts: 1256
Joined: 2006-12-18 10:10

Re: [Updated 5x]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby hkoster1 » 2013-03-15 11:35

I just tried out the 15 March 2013 daily snapshot of the D-I for amd64-testing, and there has been some regression on the UEFI front, as some of you have already noticed. This is what I found:

1. The D-I will install/use a legacy MBR partition table on a bare HD when UEFI firmware is present. The D-I partitioner has no way, AFAICT, of installing a GUID partition table at this stage, not even when dropping into manual partitioning. I have not tried dropping into a shell to do that, since I prefer using the likes of GParted-liveCD for that.

2. When the HD has first been given a GUID partition table (GPT), the D-I will still install a legacy MBR partition table, complete with "biosgrub" partition to store some of the MBR data in. You can undo that (and save some space and that coveted /dev/sda1 moniker for the ESP partition) by doing the partitioning manually -- as described in the HOWTO.

The HOWTO is no longer obsolete...
Last edited by hkoster1 on 2013-03-26 11:15, edited 1 time in total.
Real Debian users don't do chat...
hkoster1
 
Posts: 1256
Joined: 2006-12-18 10:10

Re: [Updated 5x]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby llivv » 2013-03-15 14:02

hkoster1 wrote:I just tried out the 25 March 2013 daily snapshot of the D-I for amd64-testing, and there has been some regression on the UEFI front, as some of you have already noticed.
could you give the url for the image.
all I'm finding is 15 March for both sid d-i
http://cdimage.debian.org/cdimage/daily-builds/sid_d-i/
and wheezy d-i images
http://cdimage.debian.org/cdimage/daily-builds/wheezy_d-i/

also found these unofficial images
http://cdimage.debian.org/cdimage/unofficial/efi-development/
while looking for the 25 march snapshots
in the kitchen with Julia ....
[...]
Get on the D bus to B Can ....
[...]
User avatar
llivv
 
Posts: 5582
Joined: 2007-02-14 18:10
Location: willo the tree

Re: [Updated 5x]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby hkoster1 » 2013-03-15 16:55

This is what I used: http://cdimage.debian.org/cdimage/daily-builds/daily/arch-latest/amd64/iso-cd/, in fact the
image called debian-testing-amd64-netinst.iso dated 15-03-2013.

I'm still playing with this installer image, I noticed that it won't load the efivars module in the chroot, probably because the kernel on the installer-image doesn't have the module available to it on the image. So, the work-around is then to install first the old way BIOS-way
using that "biosgrub" partition, then reboot and do the chroot thing. My advice: don't let the D-I install biosgrub as /dev/sda1... 8)

Edit: no, doesn't work either, although the efivars module now loads...
Real Debian users don't do chat...
hkoster1
 
Posts: 1256
Joined: 2006-12-18 10:10

Re: [Updated 5x]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby hkoster1 » 2013-03-17 13:07

I have updated the HOWTO such that configuring UEFI booting is no longer done in a chroot at the end of regular installation. That method may fail when the required efivars kernel module cannot be loaded in the chroot, as was the case with the daily snapshot of the amd64 installer dated 15 March 2013. The method of the HOWTO now reboots one final time in BIOS-mode, then configures GRUB for UEFI with just a default boot option. More complicated boot options can be configured after rebooting in UEFI-mode.

Enjoy!
Real Debian users don't do chat...
hkoster1
 
Posts: 1256
Joined: 2006-12-18 10:10

Re: [Updated 5x]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby eddyagain » 2013-04-11 01:14

I'm working on a Debian install in VirtualBox & in I made it thru step3 in post #1 rendered my VM unbootable outside of the Ubuntu desktop iso that I use for rescue purposes.
I noticed that you mention 3 different efi-boot-managers, anyway VB is efi capable, but does it have an efi-boot-manager?
Grub2 says it's capable here.
says it's capable.
I just wanted to be sure as I'm on another install & I can't see any documentation stating if while VB has support for efi, it doesn't say if it has a boot manager.
eddyagain
 
Posts: 6
Joined: 2013-04-11 00:41

Re: [Updated 5x]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby hkoster1 » 2013-04-12 08:57

Check out a VirtualBox forum?
Real Debian users don't do chat...
hkoster1
 
Posts: 1256
Joined: 2006-12-18 10:10

Re: [Updated 5x]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby johnson33 » 2013-04-18 06:19

I am agree with "hkoster" that this is a Good news for those of you interested in UEFI-booting your AMD64-versions of Debian GNU/Linux: the Beta3 version of the D-I for Wheezy has just been announced to allow installation with only UEFI-booting, so without the BIOS detour of my HOWTO.so enjoying dears



underwater-hotel-dubai.com
Last edited by johnson33 on 2014-01-25 09:33, edited 5 times in total.
Allen123
johnson33
 
Posts: 1
Joined: 2013-04-18 06:08

Re: [Updated 5x]HOWTO: AMD64 Debian GNU/Linux and UEFI

Postby pier » 2013-04-18 19:55

Many thanks for the very useful HOWTO hkoster1!
I have ALMOST succesfully installed wheezy in UEFI double boot on my new acer V5 571G (the other system is windows 8, which I only intend to use for compelling work-related reasons, if any).
Different from the HOWTO, I have the UEFI partition on sda2 (sda1 is used by W8 as a recovery partition and I didn't want to mess the windows stuff up), which means that I had to add grub to the UEFI boot order with:
# efibootmgr -c -p 2 -l "\\EFI\\debian\\grubx64.efi" -L "Debian GNU/Linux"
Also, I have now upgraded the system to sid (to mirror my the system on my old laptop).

The ALMOST above is because the grub loader doesn't show the W8 system as an option. When I do "grub-install /dev/sda", I get the error messages about procfs and sysfs, I wonder if these are related to the fact that grub cannot find W8 boot?
I can access the windows 8 system by giving boot priority to "windows manager" at startup (pressing "esc+F12"). Otherwise startup enters grub and debian as a default, which is fine by me, but ideally I would like to have W8 acessible from grub.

Ah, I have found the "Boot from a file" option in Boot Maintenance Manager, but I'm not given any file to select... this means I cannot restore the safe booting feature... shall I bother?

Can anyone help / has anyone the same problem/s?
pier
 
Posts: 1
Joined: 2013-04-18 18:59

Next

Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 8 guests

fashionable