Thursday 4 June 2015

Installing a Linux only OS in an UEFI hardware

So, this is the situation: twenty months ago I bought an HP Pavilion 23 All-in-one with Windows 8.1. I never use Windows, I develop rails websites on Debian. Usually when I get a new computer from any brand (HP, Dell, Toshiba, Acer) I remove Windows and all that "quick restore" crap re-partitioning my hard drive and then I install Debian.

But this HP machine has this thing called UEFI. At the time, I had no opportunity to read all the UEFI related stuff so I just shrink the Windows NTFS partition from 1.7TB to 80 GB and then I installed Debian in the new free space.

After that, I never booted into Windows and all was well until two weeks ago when I started to see weird hard drive messages. Fortunately I had time to backup all my stuff, but four days ago I got the feared "no disk found": my HD died definitively.

So I went to Mexico City downtown and I bought a $90 dollars 2TB new Hitachi hard disk.

After I came back to home, I read a couple of hours and I learned some stuff:

1) UEFI is the new BIOS.
2) Instead of say "enter into the BIOS" (the good old well known blue screen options) now you must say "enter into the UEFI options".
3) Some UEFI systems have the option to "emulate" the old BIOS and this is known as "legacy mode" or "BIOS mode".
4) If you install Linux in "legacy mode" and then you change the option to "UEFI mode" you won't be able to boot in that already installed Linux system.
5) The same happens in the other way: if you install Linux in the "UEFI mode" and then you change the UEFI to "legacy mode" you won't be able to boot into Linux.
6) There is NO reason to install Linux in "Legacy mode", Linux understands UEFI pretty well.
7) There is something called "Secure Boot" and this thing is NOT related at all with UEFI. As a Linux user, the best way to proceed is disable the "Secure Boot" option in the UEFI menu.
8) UEFI is a firmware and can be upgraded.
9) When a UEFI computer is turned on, UEFI looks for a boot loader in an special "UEFI partition" in the hard disk to load the operating system.
10) Normally on Linux systems, the bootloader is installed by grub in:  /boot/efi/EFI/debian/grubx64.efi
11) An "UEFI partition" is just a normal partition with a FAT32 format and the "boot" flag enabled.
12) On Linux, the UEFI partition must be mounted on the /boot directory.

So if you are a Linux user and you want to install a Linux only OS in an UEFI hardware you need to do this:

1) From http://www.rodsbooks.com/refind/getting.html, download the "flash drive image file". It is an .img file. Pass it to a USB drive with the dd command.
2) Using another USB drive, put the testing Debian net installer in it. As usual, use the dd command to pass the ISO file to the USB drive and boot with it.
3) Into the installer, when you get into the "HD partition" screen, create the first partition as a 500MB (0.5 GB) partition with the FAT32 option, the boot flag enabled and the label set as "UEFI". The UEFI partition must be /dev/sda1.
4) Create the other partitions as usual:  /, swap, /home. Finish the installation.
5) Boot with rodsbooks USB drive. You should be able to boot into the Debian system.

6) Install grub-uefi:

apt-get install --reinstall grub-efi
grub-install /dev/sda
update-grub

7) HP and other brand computers look for the boot loader in the "Microsoft" or the "Boot" directories so:

cd /boot/efi/EFI
mkdir Microsoft
mkdir Microsoft/Boot
cp debian/grubx64.efi Microsoft/Boot/bootmgfw.efi
mkdir Boot
cp debian/grubx64.efi Boot

Voila! now you can reboot and enter into your Debian system as usual. If you need to reinstall Debian or any other Linux flavor, just don't touch the UEFI partition and the installer will find the bootloader.

No comments: