1
0
mirror of https://github.com/MichielDerhaeg/build-linux.git synced 2025-09-03 05:02:36 +02:00

Bootloader grammar

This commit is contained in:
Steve Divskinsy
2017-05-04 10:15:19 +09:30
committed by GitHub
parent b5e73dedb9
commit ce6926396e

View File

@@ -246,7 +246,7 @@ a binary keymap file I use for belgian azerty.
The Boot Loader The Boot Loader
--------------- ---------------
The next step is to install the bootloader, the program that loads our kernel in The next step is to install the bootloader - the program that loads our kernel in
memory and starts it. For this we use GRUB, one of the most widely used memory and starts it. For this we use GRUB, one of the most widely used
bootloaders. It has a ton of features but we are going to keep it very simple. bootloaders. It has a ton of features but we are going to keep it very simple.
Installing it is very simple, we just do this: Installing it is very simple, we just do this:
@@ -257,7 +257,7 @@ grub-install --modules=part_msdos \
/dev/loop0 /dev/loop0
``` ```
The ``--target=i386-pc`` tells grub to use the simple msdos MBR bootloader. This The ``--target=i386-pc`` tells grub to use the simple msdos MBR bootloader. This
is often the default but this can vary from machine to machine so you better is often the default, but this can vary from machine to machine so you better
specify it here. The ``--boot-directory`` options tells grub to install the grub specify it here. The ``--boot-directory`` options tells grub to install the grub
files in /boot inside the image instead of the /boot of your current system. files in /boot inside the image instead of the /boot of your current system.
``--modules=part_msdos`` is a workaround for a bug in Ubuntu's grub. When you ``--modules=part_msdos`` is a workaround for a bug in Ubuntu's grub. When you
@@ -266,7 +266,7 @@ think it needs to support msdos partition tables and won't be able to find the
root partition. root partition.
Now we just have to configure grub and then our system should be able to boot. Now we just have to configure grub and then our system should be able to boot.
This basicly means telling grub how to load the kernel. This config is located This basically means telling grub how to load the kernel. This config is located
at ``boot/grub/grub.cfg`` (some distro's use ``/boot/grub2``). This file needs at ``boot/grub/grub.cfg`` (some distro's use ``/boot/grub2``). This file needs
to be created first, but before we do that, we need to figure something out to be created first, but before we do that, we need to figure something out
first. If you look at ``/proc/cmdline`` on your own machine you might see first. If you look at ``/proc/cmdline`` on your own machine you might see
@@ -278,14 +278,14 @@ BOOT_IMAGE=/boot/vmlinuz-4.4.0-71-generic root=UUID=83066fa6-cf94-4de3-9803-ace8
These are the arguments passed to your kernel when it's booted. The 'root' These are the arguments passed to your kernel when it's booted. The 'root'
option tells our kernel which device holds the root filesystem that needs to be option tells our kernel which device holds the root filesystem that needs to be
mounted at '/'. The kernel needs to know this or it won't be able to boot. There mounted at '/'. The kernel needs to know this or it won't be able to boot. There
are different ways of identifying your the root filesystem. Using a UUID is a are different ways of identifying your root filesystem. Using a UUID is a
good way because it is a unique identifier for the filesystem generated when you good way because it is a unique identifier for the filesystem generated when you
do ``mkfs``. The issue with using this is that the kernel doesn't really do ``mkfs``. The issue with using this is that the kernel doesn't really
support it because it depends on the implementation of the filesystem. This support it because it depends on the implementation of the filesystem. This
works on your system because it uses an initramfs. But we can't use it now. We works on your system because it uses an initramfs, but we can't use it now. We
could do ``root=/dev/sda1``, this will probably work but it has some other problems. could do ``root=/dev/sda1``, this will probably work but it has some other problems.
The 'a' in 'sda' is can depend on the order the bios will load the disk and this The 'a' in 'sda' depends on the order the bios will load the disk and this
can change when you add a new disk or sometimes the order can change randomly. can change when you add a new disk, or for a variety of other reasons.
Or when you use a different type of interface/disk it can be something entirely Or when you use a different type of interface/disk it can be something entirely
different. So we need something more robust. I suggest we use the PARTUUID. It's different. So we need something more robust. I suggest we use the PARTUUID. It's
a unique id for the partition (and not the filesystem like UUID) and this is a a unique id for the partition (and not the filesystem like UUID) and this is a
@@ -295,9 +295,9 @@ a GPT thing). We'll find the id like this:
$ fdisk -l ../image | grep "Disk identifier" $ fdisk -l ../image | grep "Disk identifier"
Disk identifier: 0x4f4abda5 Disk identifier: 0x4f4abda5
``` ```
Then we drop the 0x and append the partition number as two digit hexidecimal. A Then we drop the 0x and append the partition number as two digit hexidecimal. An
MBR only has 4 partitions max so that it's hexidecimal or decimal doesn't really MBR only has 4 partitions max so that it's hexidecimal or decimal doesn't really
matter but that's what the standard says. So the grub.cfg should look like this: matter, but that's what the standard says. So the grub.cfg should look like this:
``` ```
linux /boot/bzImage quiet init=/bin/sh root=PARTUUID=4f4abda5-01 linux /boot/bzImage quiet init=/bin/sh root=PARTUUID=4f4abda5-01
boot boot