Booting the Linux Kernel without a bootloader
Since version 3.3.x, and ONLY on EFI machines, it is possible to boot the Linux kernel without using a bootloader such as iELILO or GRUB. You will experience shorter boot times by using this, but a less interactive boot in case you need to make some diagnostics. In any case, you can almost always resort to some kind of removable media when you get into trouble. If you are installing Linux on a machine where you will never, ever, have any kind of alternative booting method, I do not recommend you use this method and go with a bootloader instead. You may need them to save your life in the future.
Take a note: for this step to work, you need to have booted your system using UEFI. If you have a system that can boot both in UEFI mode and MBR mode, you need to switch it to UEFI mode in the setup and boot it using UEFI compatible media. This document makes several assumptions about paths which you need to correct to apply to your particular installation. For example, this document assumes your root partition is /dev/sda2 and that your kernel sources are in the /usr/src/linux folder and that your UEFI boot partition is /dev/sda1. These need not be necessarily the same in your system.
After booting, you need to chroot into your installation. Fire up a terminal and do this:
- mkdir /mnt/root
- mount /dev/sda2 /mnt/root # if this fails, try fsck'ing your partition first
- mount -t proc none /mnt/root/proc
- mount --bind /dev /mnt/root/dev
- mount --bind /sys /mnt/root/sys
- chroot /mnt/root /bin/bash
Now, mount any additional partitions you require, including the EFI boot partition if you already have it set up.
If you are using a customized kernel, you need to make sure your kernel has the following options active:
- CONFIG_EFI_VARS=m #or y works too.
Your kernel needs to support the EFI stub loader, GPT and MBR partitions, your primary filesystem of choice, the MSDOS and VFAT filesystems, the EFI Framebuffer, the EFI variables and be relocatable. Stock kernels from binary distributions usually will not require any kind of customization and will already include support for everything you need. Also, don't forget to disable the "Tickless system".
Since you're not using a boot loader but you still need your kernel to know where your root partition is, you need to set CONFIG_CMDLINE as well:
- CONFIG_CMDLINE="root=/dev/sda2 ro"
This example was for a JFS formatted root partition as the second entry on the first drive - remember, JFS root partitions need to be mounted read-only (hence the "ro") at boot time and only mounted read-write during init.
Recompile your kernel and install the modules. Usually you'll do something like this:
- make && make modules_install
Since you are using EFI, you must also be using a harddisk partitioned using the GPT format. This means that you also must have an EFI boot partition. This is a FAT32 formatted partition over 200MB in size. In this example, the said partition is /dev/sda1.
It is typical to mount such partition under /boot/efi. You can add an entry to your "fstab" file if you like:
- /dev/sda1 /boot/efi vfat noauto 1 2
Make sure you have the partition mounted. This tutorial assumes the previous folder as mountpoint.
Now, inside that partition, you should have an "EFI" folder. And, inside the "EFI" folder, you should have a "boot" folder. So, yes, you'll have a path like "/boot/efi/EFI/boot/".
You now need to copy your kernel to that folder, giving it the name bootx64.efi. For example:
- cp /usr/src/linux/arch/x86/boot/bzImage /boot/efi/EFI/boot/bootx64.efi
Did it hurt, so far? I'm guessing no. So, keep on reading.
The kernel is in the right place, what are we missing? Adding it to the boot menu. For this we need the "efibootmgr" utility. If it's not installed, go for it. These are examples for Gentoo and Debian-based systems (which includes Ubuntu and it's derivatives).
- emerge efibootmgr
- sudo apt-get install efibootmgr
Make sure you have access to the EFI variables. How? Well, either your running kernel has already the support for it, your you can load the appropriate module:
- sudo modprobe efivars
And you can now, finally, add your kernel to the EFI boot menu:
- efibootmgr --create --part 1 --label "Linux" --loader '\efi\boot\bootx64.efi'
This code creates an entry in the boot menu (--create), for the EFI boot partition which is partition 1 of the first drive (--part 1), labelled "Linux" (--label "Linux") and with the loader '\efi\boot\bootx64.efi' (--loader '\efi\boot\bootx64.efi' ) - which is the kernel. The path of the loader is relative to the EFI boot partition and not to the whole mounted filesystem tree.
Atention: efibootmgr, unless otherwise stated, assumes /dev/sda - in the case of this example it's the right drive, but in your case it may be different.
Leave the chroot'ed environment, unmount all mounted filesystems, remove the additional EFI bootable media and reboot your system. If all goes well, you can now enjoy a faster booting machine.