In this article, I will give an example of how you can refuse to use a third-party bootloader, be it Grub or Lilo, if your computer supports the modern UEFI standard, which came to replace the BIOS. An interesting feature is that we carry out all the work on the already installed and working system.
In terms of complexity, this article is aimed at experienced Linux users, because Some of the points I touch superficially, relying on evidence, so as not to go away from the main topic covered.
Introduction
')
I'll tell you a bit of history - I have been a Gentoo Linux user for over 5 years now, and as the main and only OS on all the laptops I use: Lenovo (from X61s to X1) and Apple MacBook Pro. Always with the new installation used the classic method of installing Gentoo on a clean hard drive, using chroot. I set up the partition table and system boot in the old-fashioned way, as bequeathed by
Handbook , based on the traditional MBR.
Kernel configuration
You must provide support for booting using UEFI in our kernel:
- CONFIG_EFI = y - enable support for the UEFI standard
- CONFIG_EFI_STUB = y - enable the ability to load the kernel with UEFI firmware, which is what we need
- CONFIG_EFI_VARS = y - enabling the UEFI management interface via the variables / sys / firmware / efi / vars / *, you will need to specify where to look for the kernel to be loaded, used by the efibootmgr utility
When switching to UEFI, it is necessary to take into account the fact that it does not accept kernel boot parameters, therefore we will add all our parameters to the kernel itself:
CONFIG_CMDLINE="root=/dev/sda2 rootfstype=ext4 quiet splash=silent,fadein,theme:natural_gentoo console=tty1"
In the example, the parameters I use, if we talk about the required minimum, then there’s enough of where the root file system is located:
CONFIG_CMDLINE="root=/dev/sda2"
After making these changes, we compile and install the kernel according to the usual procedure. Gentoo has a very handy tool called genkernel for this. After assembly, we need to restart the computer, because We need some new parameters for working with UEFI firmware.
Testing
To check the performance of our kernel, you need to try to load the OS via UEFI, but in order not to risk the boot partition of our working system, we will use a usb flash drive, after removing all partitions from it.
Training
To load with UEFI, we need a special partition called EFI Secure Partition or abbreviated ESP, which will have only one file on it - this is the UEFI support kernel that we prepared earlier. At its core, this is a regular GPT partition with a specific type and FAT32 file system.
Creating an ESP Partition
To create an ESP partition, we need the gptfdisk package, information from the Gentoo package base:
* sys-apps/gptfdisk Available versions: 0.8.4 ~0.8.5 {{kernel_linux}} Homepage: http://www.rodsbooks.com/gdisk/ Description: gdisk - GPT partition table manipulator for Linux
You can install it by running the command as root:
emerge sys-apps/gptfdisk
Working with this tool is almost no different from all the familiar fdisk. Suppose that our usb flash drive was defined in the system as / dev / sdb and we, of course, have root rights. Perform the following steps:
As a result, we created a new sdb1 partition with a type of 'EFI System' and 100 MB in size, which is enough for testing. Now, as with any new partition, we need to create a file system on it, in our case it is FAT32. It's very simple to do - just execute just one command with root rights:
After executing the command, the file system will be created.
Copy core
Mount the new sdb1 partition into any directory and copy our prepared kernel there, with CONFIG_EFI_STUB enabled and other parameters described above (all commands should be executed with root privileges):
BIOS setup
After preparing the test usb flash drive, you need to restart the computer and go to the BIOS settings and select the use of UEFI in the section responsible for the boot process. After that, the system should boot up without any problems if the kernel and flash drive were prepared without errors. Testing can be considered as passed and leave the system loaded from a flash drive.
Migrating boot on a production system
According to the results of the test passed above, we checked that our kernel works correctly with the UEFI firmware on our computer, so let's start migrating our working system to use a new type of boot. The main problem is that the system is located on the partition created by the traditional MBR (Master Boot Record) based partitioning scheme, and for the UEFI you need a GPT partition. This problem is solved by a tool we already know — gdisk from the sys-apps / gptfdisk package. When you first run gdisk for our hard disk, let it be / dev / sda, it will prompt us to convert partition tables to GTP format, warning of possible data loss. Then we will do everything that we did when creating a usb-flash drive, but with a few changes.
In view of the above, the work plan will be as follows:
- disable boot partition
- backup partition
- convert MBR -> GPT
- create a new file system on the boot partition
- connect to mount point and copy core
- configure UEFI firmware
- reboot the system and check the result
Next, we will focus on each item in more detail.
Disable boot partition
In most cases, the boot partition is connected to the / boot directory and has the first number among the partitions of the block device, i.e. / dev / sda1, given that sda is our system disk. Everything on my system is exactly the same, so we run the following command, with root privileges:
If this directory is not used by any applications, then it silently and without problems disconnect from the root and we will be able to back up the entire partition / dev / sda1.
Backup Boot Partition
At this stage, we need to make a backup of the entire section in order to be able to quickly roll back all changes. Ideally, you can backup the entire system if you have the necessary tools at hand. Copying the partition is done as follows, again as root:
Check the suitability of our backup:
After executing the ls command, we should see the contents of the directory similar to what was on the production system before disabling the / boot mount point.
Convert MBR table -> GPT
Moving on to the gdisk utility. The whole conversion process is simple and requires a minimum of participation on our part. We need to run the gdisk command, change the sda1 partition type to EF00 (EFI System) and save the changes, i.e. the procedure is completely analogous to the one we did with a usb flash drive, except for the fact that the partitions have already been created. After saving the settings, our table will be transferred to the new format used by GPT and suitable for working with UEFI.
Create a new file system on a new bootable GPT partition
By analogy with the procedure for creating a usb-flash drive, we need to prepare the FAT32 file system on our boot partition, now of the type 'EFI System', by running the command:
After executing the command, the file system will be created.
Connect sda1 and copy core
At this stage, we need to copy the prepared kernel to the new partition. To do this, run:
Preparation of the boot partition is over.
Configure UEFI firmware
In order for UEFI to transfer control to our kernel, you need to specify where it is located. Configuring the UEFi firmware settings is a tool called efibootmgr:
* sys-boot/efibootmgr Available versions: (~)0.5.4 Homepage: http://developer.intel.com/technology/efi Description: Interact with the EFI Boot Manager on IA-64 Systems
It must be installed by running the command:
echo "sys-boot/efibootmgr" >> /etc/portage/package.keywords emerge sys-boot/efibootmgr
After installation, configure UEFI with the following command:
efibootmgr --create --label 'Gentoo-3.6.11' --loader '\bzImage.efi' --part 1
A detailed description of all parameters can be found in the efibootmgr man page. We use the following parameters:
- --create - create a new variable in the loader
- --label 'Gentoo-3.6.11' - the name that will be displayed in the list of boot devices
- --loader '\ bzImage.efi' is the path to the bootloader, in our case it is built into the kernel, the path is absolute and using the "\"
- --part 1 - use the first partition of the sda ​​block device
After executing the command, a detailed conclusion will be shown about the changes that have been made to UEFI.
Reboot the system and check the result.
This completes the setup and we have to reboot the system by disconnecting the usb flash drive to see how the system boots without using a third-party bootloader.
After a successful boot, the bootloader package can be removed:
grep sys-boot /var/lib/portage/world | xargs emerge -Cv
That's all you can work with the system.
Updating the kernel with genkernel
When updating the kernel in the future, using the genkernel tool, the procedure will change somewhat, since the kernel no longer needs to be installed in / boot. Therefore, instead of 'genkernel all', you need to run the 'genkernel kernel', having previously corrected the parameter to the value INSTALL = "no" in the configuration of /etc/genkernel.conf. After building the kernel, it must be renamed and manually copied to the / boot directory.
The upgrade process in the end will look like this:
Results
Pros:
- abandoned one laying in the OS boot process
- decreased system boot time
- learned how to work with the new UEFI standard, which replaced the BIOS
Minuses:
Information sources: