October 14, 2023584 words

Grub Bootloader and LFS

What is Grub?

So grub is basically a bootloader to start the system. The point here is I've been using grub for almost a year now without a deep understanding.

Grub boots the system by using grub shell. Grub starts from EFI system partition.

Config

There is a configuration file /boot/grub/grub.cfg that specifies the entry I see when the computer first starts. There is also timeout, default entry.

My grub config looks like this

set timeout=1

menuentry Arch Linux{
    linux   /vmlinuz-linux root=/dev/nvme0n1p3
    initrd  /initramfs-linux.img
}

Config through Grub

Run sudo update-grub on Ubuntu, or sudo grub-mkconfig -o /boot/grub/grub.cfg on Arch, that shall generate
the grub file.

Also os-prober is interesting tool to detect the partitions.

But I just manually configured everything.

What if Grub has errors?

If grub goes wrong, boot from a live usb, go to the partition, then change the files in /boot/grub/ directory, then it shall work right.

Alternatively, I can boot from grub shell.

/boot Parition

This partition stores linux kernel.

mount /dev/nvme0n1p1 /mnt
ls /mnt

I get

EFI  grub  initramfs-linux-fallback.img  initramfs-linux.img  vmlinuz-linux

Backup

It is always a good idea to backup the grub.cfg since without grub(if you don't have alternative bootloaders).

Booting from Grub Shell

The entries in grub is not needed and I can just boot from grub shell.

I can run

linux (hd0,gpt1)/vmlinuz-linux root=/dev/nvme0n1p3
initrd (hd0,gpt1)/initramfs-linux.img
boot

Different Kernels

Also kernels sometimes have the same name, e.g. vmlinuz-lts, vmlinuz-virt, they are different from one distro to the other. Pointing different distros(I tried Alpine and Arch pointing to the same kernel) will have many bugs, for example, the touchpad won't respond, the wifi won't load.

I can put the kernel either in /boot partition or the ext4 partition.

Exploring LFS

So basically after trying out a few distributions I wanted to try something else, and there is Linux From Scratch.

It is basically building a linux environment in a separate disk partition.

There is a handbook, and I followed the handbook closely with ChatGPT explaining some stuff.

It is just a lot of copy pasting code from the handbook to execute in terminal.

Basic Steps

  • Creating and formatting partition
  • Installing Temporary Tools
  • Chroot into it and Installing Packages
  • System Configuration

The first parts are very straightforward, and installing packages took a long time.

Problems

After installing the kernel, the system doesn't boot. So I pointed the kernel to Arch Linux(my host system)'s kernel and it booted, but with some errors and warnings. It can not find wireless interface and only returned lo when I run ip link

BLFS packages

There are many packages depending on each other so installing something is really hard. For example, the Gnome Desktop have a million dependencies, and after a while I run out of patience trying to install them, so I thought no gui good enough.

Without the kernel properly configured, I don't think there is much point in gui anyways, and you don't need a gui for computer to function.

No Package Manager

Without package manager, I need to manually build every package. LFS book specifies how to build many packages and I thought I would run into many more bugs if I am to build them myself.

Conclusion

So after all, I would still use Arch Linux(and a little Ubuntu), and LFS is just a fun project, and hopefully I did understand something more about the system.

I am very grateful for LFS community, and registered my name in their website, and I appreciate and would stick to open source.

Loading...




Loading...