BIOS vs. UEFI boot

technicalUEFI (Unified Extensible Firmware Interface) can be considered as the next-gen replacement of BIOS. It is a layer that sits on top of the system firmware and enables your OS to communicate to the firmware through it. UEFI takes care of the inherent design shortcomings of BIOS with the ability to access the total system memory, run in 64-bit mode, an extensible design by plugging in new features like an appealing graphical mode and so on. In this article we will see how different traditional BIOS boot (from a hard disk) is from UEFI boot.

BIOS Boot Mechanism

The bootstrap code (bootcode) resides in the first 446 bytes of the first sector (Master Boot Record) of a hard disk. The bootcode is loaded at location 0x7C00 in the RAM and gets executed. Even writing a basic bootcode needs the knowledge of assembly language programming (example simple bootcode). An example of a full-fledged bootcode is the Linux i386 bootcode. The size constraint of 446 bytes also needs many responsibilities to be handed over to a second level bootloader like GRUB. Additionally BIOS cannot access the total RAM available in your system and runs in 16-bit mode. x86 Boot Sector tutorial.

UEFI Boot Mechanism

UEFI overcomes the above problems with BIOS boot by moving the bootcode to a partition on your disk called the EFI system partition. The EFI system partition is a FAT12, FAT16 or FAT32 partition on a GPT partitioned disk (as opposed to an MBR based disk for BIOS). Hence the size of the bootcode, which is now the EFI binary bootloader file, can be much more. UEFI detects the EFI partition on a hard disk and if the file is present it starts executing it. This UEFI bootloader file can be generated in the EDK II development environment using the C language (examples). The bootloader can chainload another bootloader like GRUB or load the OS. Another OS boot mechanism is: the OS installed in the system adds an entry in the NVRAM which points to the device (lets say a hard disk) where the bootloader is present. At system boot, the UEFI environment looks into the NVRAM entries and loads the bootloader from the disk pointed to.

As you can understand by now, the boot mechanism is greatly simplified and enhanced in UEFI. More on EFI Boot Loaders:

Managing EFI Boot Loaders for Linux

Install ArchBang on USB for UEFI

arch_compArchBang 14.06.2013 got released one week back. I was looking for a Linux distro for UEFI and this seemed to be it. I have never used any Arch based distro before so thought of trying it out. I tried to get the USB ready on Ubuntu. Here is how I could boot it from USB on a UEFI based laptop:

  1. Download the 64-bit version – archbang-14.06.2013-x86_64.iso. Extract the iso to a directory using archive manager or mount it somewhere. On Ubuntu archive mounter can do that automatically for you when you click on an iso file. You need to copy the files to your USB later.
  2. Connect your pen drive. Run GParted (you may have to install it from synaptic as it doesn’t come by default). Be very careful about selecting the correct device in the upper right corner of GParted main window (e.g. for me it was /dev/sdb). Then go to Device menu ▸ Create Partition Table. Expand Advanced. In the drop-down menu select gpt. Apply. Once the operation is over you have a USB with GPT partition table.
  3. Now you need to install the filesystem on the device. Create a FAT32 filesystem on the device using GParted – select the pen drive (should show unallocated at this point), right click and click New. Choose your options in the next window. Set the device label as ARCHBANG. Once again, be very careful to select the right device.
  4. Your pen drive is ready now. Open it and copy all the files from the iso mounted in Step 1.
  5. Download the rEFind deb package. Open it using archive manager and extract usr/share/refind-x.x.x/refind/refind_x64.efi. Rename it to bootx64.efi and overwrite the EFI/boot/bootx64.efi file on the pendrive.
  6. Create a new file refind.conf in the pen drive under EFI/boot/ (at same place as bootx64.efi). Copy the following content in it. Got it from the Arch wiki and slightly modified it. The important point is to use the same label as archisolabel that you used in Step 3 e.g. I used ARCHBANG.
timeout 5

showtools about,reboot,shutdown,exit
# scan_driver_dirs EFI/tools/drivers_x64
scanfor manual,internal,external,optical

scan_delay 1
dont_scan_dirs EFI/boot

max_tags 0
default_selection "ArchBang UEFI USB"

menuentry "ArchBang UEFI USB" {
loader /arch/boot/x86_64/vmlinuz
initrd /arch/boot/x86_64/archiso.img
ostype Linux
graphics off
options "archisobasedir=arch archisolabel=ARCHBANG add_efi_memmap"

menuentry "UEFI x86_64 Shell v2" {
loader /EFI/shellx64_v2.efi
graphics off

menuentry "UEFI x86_64 Shell v1" {
loader /EFI/shellx64_v1.efi
graphics off

Now you are done! Unmount the USB. Keep it plugged it. Reboot your laptop and boot from the USB. Make sure USB device boot is enabled in UEFI settings. In my case I also had to reconnect the pen drive to the USB 2.0 port as it didn’t boot when plugged-in to a USB 3.0 port.

To set brightness for my laptop on ArchBang:

echo 5 > /sys/class/backlight/acpi_video0/brightness
//check /sys/class/backlight directory for your option

ArchBang 2013.06 released

arch_compSince SliTaz 5.0 is uncertain, I was looking for a stable alternative distro to install on USB and coincidentally the latest release of ArchBang has just been released yesterday. Comes in both 32-bit and 64-bit flavours, can be installed on USB, supports UEFI and has the latest Linux kernel. I’ll be trying it out shortly. Though the bulk is much more than that of SliTaz, I would settle for it if the performance is good.