Howto achieve dual boot in spite of a rudimentary UEFI

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

Howto achieve dual boot in spite of a rudimentary UEFI

Postby Palmstroem » 2017-08-22 10:35

The goal is to have a Linux/Windows dual boot configuration. Problem can be an UEFI with very limited capabilities.

Specs of my model:
    Acer Aspire ES1-533-P9C3
    UEFI only, no legacy/MBR boot
    Intel N4200 processor
    8 GB RAM
    1920x1080 LCD display (crystal-clear!)
    DVD+CD R/W optical drive
    1 GB Harddisk (slow, could not afford SSD)
    3 x USB, HDMI, ethernet, wlan, bluetooth, SD card reader

Summary:
Do not use the Linux program efibootmgr to write to the NVRAM - it will freeze your system (for this laptop)!
Instead start an UEFI shell and use the command bcfg to add a Linux boot entry to the NVRAM.

If you are interested in the gory details how finally I managed to achieve the dual boot, or if you have similar problems, read on. But be warned: it's a long story.

1. Since the laptop comes pre-installed with Windows 10 we have to make room for Linux. I wanted to keep Windows, therefore I had to shrink the main Windows partition. If you already have data on this partition back it up before continuing. Now the laptop is an UEFI-only machine which means that the harddisk (1 TB) is partitioned by a GUID partition table (GPT) with a dedicated EFI system partition (ESP). Normally the ESP is the first partition and is FAT32-formatted. Right-click on the windows start button and open the Disk Management tool to see your partitions. Right-click on the main Windows partition (C:) and choose Shrink Volume.... In my case there was a large unmovable file on the second half of the windows partition which prevented a shrinking to a value below 600 MB. You can get rid of this file by temporarily switching off Virtual memory and System backup/restore options (look under Advanced System Settings).

2. It is also advisable to switch off Hibernate and Fast Boot. In Windows open an Admin Command Prompt and enter
Code: Select all
powercfg /h off
This switches off Hibernate. Fast Boot can be disabled under Power Options -> Choose what the power button does, choose Shut down. Windows is often configured in such a way that it not really powers down your computer when you ask it to do so but only goes into a sleep mode. This feature enables a faster boot up but is not helpful when you want to work with other operating systems.

3. After these preparations we can restart the laptop while pressing F2. This brings up the UEFI menu. Under Main I changed the F12 Boot Menu to Enabled, under Security I set a Supervisor Password (write it up somewhere), and under Boot I changed Secure Boot to Disabled. I also modified the order of the boot devices to: ATAPI CDROM:, USB HDD:, HDD:, USB CDROM:, USB FDD:, Network Boot IPV4, Network Boot IPV6, Windows Boot Manager. Press F10 to save the modifications and exit the UEFI menu.

4. Since this laptop has an optical disk drive you can download and burn an image of your favourite Linux distro, put the CD or DVD into the tray, reboot, and the system will start installing Linux. However, I find it more convenient tu use an USB stick for the task. I downloaded the Debian 9.1 netinstall image which works if you have ethernet. If you happen to have wifi only (like I have at home),
you will need the iwlwifi-3168 firmware drivers which are not part of the standard distribution. I therefore switched to the 9.1.0+nonfree image, put it on an USB and booted it.

5. For a dual boot configuration you have to inform the installer (be it Debian, Ubuntu, or ...) to use the freed space on the harddisk. Then a Linux root partition will be generated and formatted. Normally the installer will also generate a swap partition. If you like you can make a separate /home partition. I decided against it, so in the end my GPT had the following partitions:
    /sda1: 100 MB, the EFI System Partition
    /sda2: 16 MB, Microsoft reserved
    /sda3: 272 GB, NTFS Windows C:
    /sda4: 1 GB, NTFS Windows recovery
    /sda5: 650 GB ext4 Linux root
    /sda6: 8 GB Linux swap

6. The Debian installer installs the system to /sda5 but when it tries to install GRUB and add a boot entry to the NVRAM, it fails. However, the Debian installer gives a message that some test entry could not be written, and that the installation therefore could not be finished, then it returns to the installer menu. The Ubuntu installer (also from other distros) is not so clever - it just tries to install GRUB and then the system freezes! Of course, there is a bug. However, I don't know whether the problem is with the command efibootmgr or with the UEFI firmware or with both. It appears that
Code: Select all
efibootmgr -v
can read out the NVRAM but not write to it! And, as far as I can see, every Linux installation for an UEFI system seems to use efibootmgr sooner or later and freezes (this laptop). Debian allows you to gracefully exit the installation before that happens but nevertheless Linux cannot be booted because the UEFI boot manager does not know about it.

7. Now we have the following situation: Debian is installed in its own partition and the relevant GRUB file grubx64.efi has been added to the ESP at /EFI/debian/grubx64.efi, similarly to the Windows boot manager which is located at /EFI/Microsoft/Boot/bootmgfw.efi. Make sure that these efi files exist on the ESP. (I have read that on some systems Linux was not able to write to the ESP. If that happens to you, you could alternatively just generate the debian directory and copy the grubx64.efi file using Windows. Open an Admin Command Prompt and mount the normally hidden EFI partition with the command
Code: Select all
mountvol S: /s
Then you can read/write the ESP as drive S:)

8. But how to tell the UEFI boot manager about Linux? I contacted the Acer support people and they responded friendly but could not help. Repeatedly they told me that I should mark a Linux boot file as "trusted for execution" in the UEFI menu. However, there is no such menu entry! I have seen in a forum that this might be different for other Acer laptops/UEFI versions. In my UEFI (InsydeH20, version V1.08) you may only modify the boot order of the listed hardware devices plus the Windows Boot Manager. It is not possible to add or remove entries or to "establish trust" for a file.

9. I tried some things with the Windows admin command bcdedit but was not successful. For instance,
Code: Select all
bcdedit /set {fwbootmgr} timeout 5
responded with the error message that the medium was write-protected. What really helped me to finally achieve a dual boot solution was Rod Smith's rEFInd package which gives you access to the UEFI shell. Rod runs an excellent website (http://www.rodsbooks.com/refind) where he elaborates in detail on several boot problems. Note, however, that it is not possible to regularly install the rEFInd boot manager as a debian package, because the install script also uses efibootmgr and freezes the system. I downloaded the rEFInd live image, prepared an USB stick with it (use a low-level copy tool like dd, just copying the file with cp will not work), and booted this stick. Then you have the option (second row in the rEFInd graphics screen) to launch the UEFI shell. The shell provides you with a very basic text-only operating system (like DOS :D) where you may add, remove and modify boot entries!

10. Use the UEFI shell command
Code: Select all
bcfg boot dump -v
to list all your current boot entries. You can then add the Debian entry with
Code: Select all
bcfg boot add # fs0:\EFI\debian\grubx64.efi "GRUB Manager"
Replace # by a suitable position after the last entry of your list. You can also change the order of these entries with
Code: Select all
bcfg boot move #fromhere #tohere
If you now reboot the laptop and press F12 when the Acer logo appears, you will notice that there are more boot options. In my case, I have 1. GRUB Manager, 2. Windows Boot Manager. If I choose 1, the UEFI boot manager loads grubx64.efi which in turn starts the Debian kernel. Bingo! And if I choose 2, I still can work in Windows. If you fear that Windows will remove the Debian entry at a later time (for example when an update is installed), you could as well change the boot order and make Windows no. 1. Since I normally want Debian, I have Debian as 1 and I must say that up to now it survived as 1 in spite of several Windows updates. If something goes wrong you could go back and use the rEFInd image to repair things with the help of the UEFI shell. When the dual boot runs stably you should modify the device boot order in the UEFI menu to first boot from HDD: since it is dangerous to give an USB stick or CDROM a high boot priority.

11. Note that you could as well work with the rEFInd boot manager, if you don't like GRUB. IMHO, GRUB is powerful but quite complex: a bunch of scripts that start other scripts, etc. rEFInd is much easier to configure and it can directly start the Linux kernel or Windows, so you don't need GRUB. Just install the relevant rEFInd stuff under /EFI/refind and generate the corresponding UEFI entry for rEFInd with the help of bcfg.

EDIT:
Yesterday I noticed that Acer offers an UEFI update on their support website. I installed this update, so now it is V1.10 as of 2017/07/31. I could not detect any differences: just the same limited UEFI options. However, the UEFI update reset all previous UEFI configurations and options to default values. That means, Windows became the first and only boot manager, all other entries were gone! Harddisk partitions, including the ESP, were untouched, though. So I entered the UEFI with F2, set F12 Boot Menu as Enabled, set a supervisor password, set Secure Boot as disabled, re-ordered the boot order, rebooted into my USB rEFInd rescue stick, chose the UEFI shell, re-established the Debian/GRUB entry, and Voilá: now everything works as before: Debian is the default OS #1 and Windows the OS #2.

Happy Linuxing!
Palmstroem
Palmstroem
 
Posts: 13
Joined: 2017-08-12 12:36

Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable