Eat.Sleep.Learn.Repeat

My way of reminding my future-self about stuff

Installing Kali Linux on EFI32

This is the story on how I managed to install Kali Linux on an oldish HP AtomCPU based laptop/tablet hybrid with an EFI32 “BIOS” implementation. If you are trying to do something similar, this post could save you some time, or even teach a thing or two about how EFI works.

I am a big fan of reusing and repurposing old hardware that otherwise would end up on the electronics recycle bin. I have installed linux in countless old-ish devices, and even on some VERY old ones like a SUN E250 server, but I digress. The most recent device that received my linux treatment was a small 2-in-1 convertible small “laptop/tablet” hybrid from HP: a Pavillion X2 10-N001NS. It was running Windows 10, but given the specs of the machine (Atom 1.3GHz CPU, 2GB RAM, 32 GB eMMC SSD), the performance and user experience was quite bad. I tested various USB live linux distros to test HW compatibility and overall experience, and settled with Kali linux, because it is lightweight with the default xfce4 desktop environment and filled with all the tools I might need (security related and otherwise). Hardware compatibility is mostly good, except for some small wifi hicups, and a not working webcam.

The problem

Kali installer was unable to install the grub2 bootloader, because of the oldish EFI32 implementation on the Intel Atom Bay Trail platform. This CPU is perfectly capable of running a x64 linux kernel, but in this incarnation the platform still uses a 32bit EFI, instead of the most common EFI64. This presented the type of tech challenge I like to solve! :)

Initial state

Kali Linux was fully installed on the internal eMMC SSD, and was “only” missing a working bootloader. To reach this state, I used the “expert” text-mode installer, because that way I have full control of the install process. With no bootloader in place, the machine was just a fancy paperweight.

Options considered (not working)

  • Change to legacy BIOS boot: this laptop is EFI ONLY, meaning you cannot fallback to traditional BIOS for the boot process.
  • Use custom EFI Boot Menu Entry, or manually boot from EFI Shell: this particular EFI implementation is quite basic or “primitive”. It does not offer support for custom EFI Boot Menu entries, nor an accesible EFI shell… either that, or no obvious (or documented) method to access it.
  • Use ‘efibootmgr’ to create EFI boot menu entry: you can actually use ‘efibootmgr’ to create boot entries and reorder boot priority. It work, and settings are saved to NVRAM, because the changed settings do survive reboots, but the EFI implementation just ignores them. In a more feature-rich EFI64 implementation, you actually don’t strictly need a bootloader (grub2). It is possible to directly load and boot a linux kernel from EFI, if compiled with the appropiate .config options, so that the linux kernel image (vmlinuz) is also a valid EFI executable.
  • Use an intermediate bootloader, like rEFInd, but unfortunately it does not support booting a 64bit linux kernel from a 32bit EFI, I tried and failed.

Solution

At high level, what I ended up doing to succesfully install grub2 in this particular scenario was:

  1. Boot Kali from a live DVD image copied to a USB drive and made it bootable with the excellent Ventoy tool.
  2. From the live environment chroot to the already installed Kali root-fs in the internal eMMC SSD. From there download and install grub-efi-ia32 package, which does have the ability to cross boot a 64bit linux kernel from a 32bit EFI environment.
  3. ????
  4. Profit!

Detailed Step 2

Once booted from a liveCD, you can chroot to the already installed Kali Linux in the internal eMMC. On my device the internal eMMC device is /dev/mmcblk1 and it was partitioned like this:

/mnt/mmcblk1p1 FAT32, EFI BOOT
/mnt/mmcblk1p2 ext4, root filesystem
/mnt/mmcblk1p3 swap

If you decided to use a different partition scheme, remember to adjust the partition and device names (mmcblkp*) in the instructions below. In order to chroot and install grub2 (efi32), I did the following:

mount /dev/mmcblk1p2 /mnt #Mount root filesystem
mkdir /mnt/{dev,proc}
mkdir -p /mnt/sys/firmware/efi/efivars
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
mount --bind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars
mkdir -p /mnt/boot/efi
mount -o remount,rw /dev/mmcblkc1p1 /mnt/boot/efi
chroot /mnt
apt install grub-efi-ia32
grub-install /dev/mmcblk1
update-grub
exit
umount /mnt/{dev,proc,sys/firmware/efivars,sys,boot/efi}
umount /mnt

Conclusion

Always keep a spare USB with Ventoy and a bunch of bootable ISOs (linux/windows/tools). It is a fantastic tool to have in your arsenal, and it is very easy to keep them updated, because all that is required is to copy a new file to the USB drive. Could not be any simpler.


Share