Language
Category
Search

How to Create and Configure initrd in Slackware Linux: Complete Guide

Find out what initrd is, what it's for and how to generate and use it. Learn how to configure ELILO for a new kernel and use scripts such as mkinitrd, geninitrd and eliloconfig

How to Create and Configure initrd in Slackware Linux: Complete Guide
At Terminal By Rudi Drusian Lange
Published on
Last updated

Environment

This article is specific to Slackware Linux users, and the commands presented were tested on version 15 of the system. The conceptual part is valid for all Linux systems, but the mechanisms adopted for handling initrd are developed specifically for this distribution. The ELILO is adopted as the default boot loader.

Quick Guide

Use the geninitrd and eliloconfig scripts to generate and install, automatically and simply, the new initrd and kernel in the EFI boot. For detailed information on the manual and automated process, continue reading the article.

Introduction

This article will follow the format proposed by Patrick Volkerding in his tutorial titled "Slackware initrd mini HOWTO" and will answer the questions presented by him:

  1. What is initrd?
  2. Why do I need an initrd?
  3. How do I generate the initrd?
  4. Now that I've created an initrd, how can I use it?

What is initrd?

The initrd is a temporary file system loaded into RAM during the Linux boot process. It contains modules and scripts necessary to mount the real root file system before the kernel can take full control of the system.

Why do I need an initrd?

The initrd is necessary when the kernel does not have built-in drivers to access the hardware needed to mount the root file system, for example, drivers for disk controllers (SCSI, RAID) or specific file systems (ext4, reiserfs, xfs).

In modern Linux kernels, there is a wide variety of available options and configurations. It is not practical to distribute multiple different kernels to meet all specific needs; it is much more flexible to provide a generic kernel accompanied by a set of modules that can be loaded as needed.

This is where initrd comes into play. It can be generated via command line to load the specific modules needed for the hardware and file system used on a given system.

That said, Slackware provides a version of the kernel called huge that contains enough built-in drivers so that, in most cases, an initrd is not required to boot the system.

It is strongly recommended to use a generic kernel as this will save some memory, possibly avoid some warnings during boot, and maintain better compatibility of kernel modules.

How do I generate the initrd?

Most likely, the first time you will need to create an initrd will be after updating the kernel. In Slackware 15, every time the kernel is updated, it will be necessary to recreate the initrd manually.

Fortunately, this is not a difficult task nowadays. There are some scripts available to assist in this process. First, a more manual version will be presented, which will help clarify what is being done and will be useful for those using more than one kernel and do not want their configuration files to be overwritten.

To create the initrd, you will need to know the version of the new kernel after the update. To find this information, run the command:

# bash

uname -r

5.15.161

The mkinitrd_command_generator.sh script will be used to extract the necessary system options, which will be used as parameters in the mkinitrd command. This command, in turn, will be used to generate the new initrd.

In the following command, replace 5.15.161 with your kernel version:

# bash

/usr/share/mkinitrd/mkinitrd_command_generator.sh -k 5.15.161

#
# mkinitrd_command_generator.sh revision 1.45
#
# This script will now make a recommendation about the command to use
# in case you require an initrd image to boot a kernel that does not
# have support for your storage or root filesystem built in
# (such as the Slackware 'generic' kernels').
# A suitable 'mkinitrd' command will be:

mkinitrd -c -k 5.15.161 -f ext4 -r /dev/sdb2 -m xhci-pci:ohci-pci:ehci-pci:xhci-hcd:uhci-hcd:ehci-hcd:hid:usbhid:i2c-hid:hid_generic:hid-asus:hid-cherry:hid-logitech:hid-logitech-dj:hid-logitech-hidpp:hid-lenovo:hid-microsoft:hid_multitouch:jbd2:mbcache:crc32c_intel:crc32c_generic:ext4 -u -o /boot/initrd.gz

Copy the generated command at the end of the script execution and run it to generate the initrd:

# bash

mkinitrd -c -k 5.15.161 -f ext4 -r /dev/sdb2 -m xhci-pci:ohci-pci:ehci-pci:xhci-hcd:uhci-hcd:ehci-hcd:hid:usbhid:i2c-hid:hid_generic:hid-asus:hid-cherry:hid-logitech:hid-logitech-dj:hid-logitech-hidpp:hid-lenovo:hid-microsoft:hid_multitouch:jbd2:mbcache:crc32c_intel:crc32c_generic:ext4 -u -o /boot/initrd.gz

OK: /lib/modules/5.15.161/kernel/drivers/usb/host/xhci-hcd.ko added.
OK: /lib/modules/5.15.161/kernel/drivers/usb/host/xhci-pci-renesas.ko added.
OK: /lib/modules/5.15.161/kernel/drivers/usb/host/xhci-pci.ko added.
....
60343 blocks
/boot/initrd.gz created.
Be sure to run lilo again if you use it.

Your new initrd has been generated and is located at /boot/initrd.gz.

Now that I've created an initrd, how can I use it?

After creating the initrd, you will need to load it along with the kernel during boot. If you are using ELILO as the boot loader, copy the generated file to the EFI boot folder at /boot/efi/EFI/Slackware/.

Copy the new kernel along with the initrd to the EFI boot directory:

# bash

cp /boot/initrd.gz /boot/efi/EFI/Slackware/
cp /boot/vmlinuz-generic /boot/efi/EFI/Slackware/vmlinuz

Done! Your new kernel and initrd are now installed and will be loaded correctly on the next boot.

Next, we will explore more options and a little more context if you want to understand better what you are doing. However, the necessary configurations to load the new kernel and initrd successfully have already been completed in the previous instructions.

A bit of context

In the EFI boot directory are the files responsible for booting the operating system. Let's list some of them:

# bash

ls -lh /boot/efi/EFI/Slackware/

total 17M
-rwxr-xr-x 1 root root  160 Dec  7 11:35 elilo.conf
-rwxr-xr-x 1 root root 233K Jun 12  2018 elilo.efi
-rwxr-xr-x 1 root root 9.2M Dec  7  1131 initrd.gz
-rwxr-xr-x 1 root root 7.5M Jun 16  2024 vmlinuz
  1. elilo.conf
    • Bootloader configuration file.
  2. elilo.efi
    • Boot file read by UEFI; responsible for loading the kernel and initrd.
  3. initrd.gz
    • Modules for hardware and file systems needed for proper operation before system boot.
  4. vmlinuz
    • Linux kernel.

The location of the initrd is defined in the elilo.conf file. Let's take a look at it:

# bash

vi /boot/efi/EFI/Slackware/elilo.conf

The content of the file should be something like:

elilo.conf

chooser=simple
delay=1
timeout=1
#
image=vmlinuz
    label=Linux
    initrd=initrd.gz
    read-only
    append="root=/dev/sdb2 vga=normal ro"

In this file, bootloader customizations are made, such as the choice of multiple kernels to be selected during boot, the waiting time before automatic loading, and other configuration options.

More on generating the initrd

You can set default options for the mkinitrd command in the /etc/mkinitrd.conf configuration file. An example version of this file is available in /etc/mkinitrd.conf.sample and serves as a good starting point.

Use man mkinitrd.conf for more information on the configuration file and man mkinitrd for details on the command.

The mkinitrd_command_generator.sh script, when used with the -c option, will display parameters based on the current system that can be used in the configuration file.

# bash

/usr/share/mkinitrd/mkinitrd_command_generator.sh -c

SOURCE_TREE="/boot/initrd-tree"
CLEAR_TREE="1"
OUTPUT_IMAGE="/boot/initrd.gz"
KERNEL_VERSION="5.15.161"
KEYMAP="us"
MODULE_LIST="xhci-pci:ohci-pci:ehci-pci:xhci-hcd:uhci-hcd:ehci-hcd:hid:usbhid:i2c-hid:hid_generic:hid-asus:hid-cherry:hid-logitech:hid-logitech-dj:hid-logitech-hidpp:hid-lenovo:hid-microsoft:hid_multitouch:jbd2:mbcache:crc32c_intel:crc32c_generic:ext4"
LUKSDEV=""
ROOTDEV="/dev/sdb2"
ROOTFS="ext4"
RESUMEDEV=""
RAID=""
LVM=""
UDEV="1"
WAIT="1"

Let's create the mkinitrd.conf configuration file from the mkinitrd.conf.sample example file and the parameters generated by the script:

vi /etc/mkinitrd.conf

/etc/mkinitrd.conf

KERNEL_VERSION="$(uname -r)"
KEYMAP="br-abnt2"
MODULE_LIST="xhci-pci:ohci-pci:ehci-pci:xhci-hcd:uhci-hcd:ehci-hcd:hid:usbhid:i2c-hid:hid_generic:hid-asus:hid-cherry:hid-logitech:hid-logitech-dj:hid-logitech-hidpp:hid-lenovo:hid-microsoft:hid_multitouch:jbd2:mbcache:crc32c_intel:crc32c_generic:ext4"
ROOTDEV="/dev/sdb2"
ROOTFS="ext4"

Explanation

Parameters assumed by default, such as SOURCE_TREE, OUTPUT_IMAGE, UDEV, and WAIT, were omitted from the configuration file. The CLEAR_TREE option was also omitted as it is not recommended when maintaining support for multiple kernels. Other options like LUKSDEV, RESUMEDEV, RAID, and LVM do not apply to this example.

  1. KERNEL_VERSION
    • Using $(uname -r), the current kernel version will automatically be used, eliminating the need to enter it for each command.
  2. KEYMAP
    • Defines the custom keyboard map to be loaded during boot.
  3. MODULE_LIST
    • Specifies the list of modules to be included in the initrd.
  4. ROOTDEV
    • Defines the device where the root file system is located.
  5. ROOTFS
    • Specifies the type of file system used for the system's root.

Configurations for the MODULE_LIST, ROOTDEV, and ROOTFS parameters were taken from the output generated by the mkinitrd_command_generator.sh -c command.

With these few lines in the configuration file, it is now possible to replicate the entire command generated by the script using just mkinitrd -F. The -F option instructs the command to use the configuration file contents as parameters.

With these configurations, unless there is a hardware change impacting the modules to be loaded, it will be possible to update the initrd after a kernel upgrade using the following commands:

# bash

mkinitrd -F
cp /boot/initrd.gz /boot/efi/EFI/Slackware/
cp /boot/vmlinuz-generic /boot/efi/EFI/Slackware/vmlinuz

Using Slackware's automated scripts

The process becomes much easier by using the default options available in Slackware to create the initrd and copy the new kernel to the EFI boot folder.

So why so much information if this could all be solved quickly?

Many people choose Slackware because it offers total control over each configuration step, which is especially useful when you need to perform customizations beyond the scope of automated scripts.

If this is not your case, your life will be simpler. After updating the kernel, just run:

# bash

geninitrd

geninitrd

The previous image will be displayed, and at the end, when the command prompt is released, the new initrd.gz will be available in /boot.

To copy the initrd and the kernel to the EFI boot folder, execute the eliloconfig command and follow the instructions until the script completes:

# bash

eliloconfig

Select install

eliloconfig-01

Select install again. Use skip only if you are using Apple hardware ↓

eliloconfig-02

Remove the old boot entry. Select Yes

eliloconfig-03

Process completed successfully. OK

eliloconfig-04

With the two scripts, geninitrd and eliloconfig, your system will be ready to use the new kernel and the new initrd, both generated and installed in the boot sector.

Conclusion

In this article, we learned how to create and use initrd in Slackware, covering from manual generation to using automated scripts to simplify the process. With the detailed configurations and procedures, it is possible to ensure that the new kernel and initrd are correctly configured and loaded during boot. Although Slackware offers automatic methods, the system's flexibility allows customizations, ensuring full control for the user to make specific adjustments according to their needs.

References

Some of the sources used in the preparation of this article:

This is not my original language and I don't speak it very well. I used my little knowledge and translators tools to compose the text of this article. Sorry for possible spelling or grammatical errors, suggestions for corrections are appreciated and can be sent to the contact email in the footer of the site. My intention is to share some knowledge and I hope this translation is good enough.


Some of the content on this website, including text, images, graphics and other materials, may be generated or enhanced by artificial intelligence (AI) tools. For more details on the use of AI, please see our Term of Use.