Saturday, July 22, 2023

Linux boot - kernel, initrd vs initramfs

The bootloader will load the kernel. This could be GRUB or BCD for windows

 Initrd - meant initial ram disk. Initramfs - initial ram file system.
It detects hawdware and loads drivers. Has all drivers so tjhe kernel image remains small and doesnt cause errors from conflicting drivers, and mount file system (it could be raid, netowork storage etc).
It is big 50MB and contains all drivers. 

initrd - is compressed image. Zstandard compressed data/ ASCII cpio archive
initramfs - uncompressed for older pcs.

It is called initrd in many places although it is a initramfs, particularly in boot loaders, as for them it is just a BLOB. The difference is made by the OS when it boots.

dmesg

systemd-analyze 
systemd-analyze plot > plot.svg

Startup finished in 2.840s (kernel) + 11.378s (userspace) = 14.218s graphical.target reached after 11.364s in userspace

Userspace will be since systemd (init) starts to load services. 
sudo systemctl disable/enable/start/stop NAME_OF_SERVICE

journalctl --disk-usage
journalctl --vacuum-size=50M
journalctl --verify   (verify integrity)


/etc/systemd/journald.conf
SystemMaxUse=50M

How to compile a linux kernel


https://www.kernel.org/  download kernel
If you have enough ram I recommend to build it in a ramdisk.

make mrproper- The make mrproper command cleans up any leftover files from previous kernel builds in your source directory. It also wipes out any . config files in your source directory. If you want to do a new clean build.
Boot a Linux MX image to detect all drivers.
ADD all drivers loaded either built into kernel or as modules.

sudo apt update
sudo apt install gcc flex bison libncurses-dev libssl-dev

make localyesconfig - add local modules as built into kernel
make localmodconfig - add local modules as modules
lsmod > /tmp/mylsmod
 make LSMOD=/tmp/mylsmod localmodconfig
make menuconfig
make -j4 (-j is number of cores)
make modules
sudo make modules_install (optional INSTALL_MOD_PATH=/mnt/partition/lib/ -- does nothing )
sudo make install (optional INSTALL_PATH=/mnt/partition/boot/ )

Press / and search for ex USB_SERIAL_CONSOLE  for usb to serial driver - and it shows the path where to find it.

TO disable initrd, disable:
General Setup -> at the bottom - initrd imitramfs support
Need to have added as drivers in kernel ext4 and sata/ahci or nvme drivers

For iwlwifi driver to work when built as driver into the kernel you need  to set:
CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
Linux Kernel Configuration
└─> Device Drivers
└─> Generic Driver Options
└─> Firmware loader
└─> Force the firmware sysfs fallback mechanism when possible

No rule to make target 'debian/certs/debian-uefi-certs.pem'
scripts/config --disable SYSTEM_TRUSTED_KEYS
scripts/config --disable SYSTEM_REVOCATION_KEYS
Drivers are locate in /usr/lib/modules/$(uname -r)/kernel/
/lib -> /usr/lib/

sudo apt install pciutils
lspci -k
lshw
lsusb
dmidecode - list hw parts

sudo dmesg | tail
lsmod - list loaded drivers
insmod / modprobe - load driver
rmmod - unload driver / modprobe -r

Edit apt sources and add contrib non-free  
nano /etc/apt/sources.list 
deb https://deb.debian.org/debian/  main contrib non-free  
apt update

apt search firmware 
firmware-misc-nonfree 
firmware-iwlwifi

Video drivers: 
xserver-xorg-video-intel 
xf86-video-intel 
xf86-video-amdgpu 
nvidia nvidia-utils

Add driver at debian install time:
Search here:
https://www.debian.org/distrib/packages#search_contents
Put contents in /dev/sdc1/drivers and mount to /lib/firmware
/lib/firmware/iwlwifi-3945-2.ucode

mkdir /lib/firmware
mount /dev/sdc1/drivers /lib/firmware

I have an Intel Corporation HD Graphics 5500
Step 1. Check video card driver.

Type lspci

lspci -k  -- to see loaded drivers in my case its the intel i915 driver.
sudo apt install xserver-xorg-video-intell

This package provides the driver for the Intel i8xx and i9xx family of chipsets, including i810, i815, i830, i845, i855, i865, i915, i945 and i965 series chips.

Step 2. Check OpenCL drivers

You can run clinfo (sudo apt install clinfo ) and if it says 0 devices

sudo apt install intel-opencl-icd