- 1 What is initramfs?
- 2 Do I need an initramfs?
- 3 better-initramfs
- 4 Dracut
What is initramfs?
Wikipedia defines initramfs as:
initramfs, abbreviated from "initial ram file system", is the successor of initrd. It is a cpio archive of the initial file system that gets loaded into memory during the Linux startup process. The Linux kernel mounts it as root file system and starts the init process from it. This will complete certain tasks before the real root file system is loaded; thus, initramfs needs to contain all of the device drivers and tools needed to mount the real root filesystem.
Do I need an initramfs?
The reason to build a kernel with an initramfs is mostly for interoperability (e.g. live-cd's) and special features like an included busybox, ssh, etc. But mostly, and that's why we are doing this here now, to have a proper kernel up and running quick'n dirty in a reasonable time without fighting hours and days until a more or less exotic hardware is perfectly run by the kernel. After having a proper basic kernel running with the help of an initramfs, I really recommend you to go a step further and build a true kernel with all features includes without an initramfs. However, relying only on a kernel to boot a system can be quite time consuming, so we have provided several initramfs options for Funtoo. If you have decided to use an initramfs, not just a kernel, check out the options below and choose the one that you like the most.
Piotr's better-initramfs is a popular approach among Funtoo'ers to building an initramfs. It is quick, nice, and shiny. The biggest plus is that, once built, it is kernel version independent.
To install better-initramfs on your system, change to the
/opt directory (or any other directory that you deem suitable) and clone the better-initramfs repository from bitbucket.
# cd /opt # git clone https://bitbucket.org/piotrkarbowski/better-initramfs.git
Now that you have better-initramfs on your system, we can make the
initramfs.cpio.gz image and move it to
do not run
make imageuntil you have configured your kernel. If you have not installed / configured a kernel yet, check out: Building a Kernel From Source and Funtoo Linux Kernels.
# cd better-initramfs # bootstrap/bootstrap-all # make prepare # make image # cp output/initramfs.cpio.gz /boot
Now that the
initramfs.cpio.gz file is in
/boot, we can configure what we want the initramfs to do for us when the system boots. Below is a table of options that better-initramfs supports (from better-initramfs Bitbucket page):
|rescueshell||Drop to the rescueshell before mounting rootfs to |
|sshd||Run the sshd server when the initramfs loads. This allows you to ssh into your initramfs to fix any errors that may have occurred while booting.|
|sshd_wait=x||Wait x number of seconds after starting sshd to continue booting the system.|
|sshd_port=x||Change the port that sshd "listens" on. The default port for sshd is port 22.|
|binit_net_if=interface||Choose which interface the network should be configured on. For example: wlan0, eth0, etc.|
|binit_net_gw=ipaddr||The address of your gateway. Only needed if you want to connect to WAN.|
|rw||Mount the rootfs as read-write. By default, the rootfs is mounted as read only.|
|mdev||Use mdev instead of devtmpfs. This option can prove handy on older kernels.|
|softraid||Detect and run RAID arrays.|
|init=||Change the init system. For example, if you are using systemd, change this to |
|tuxonice||Try resuming with TuxOnIce.|
|uswsusp||Try resuming the system with userspace software suspend. This depends on the |
|swsusp||Try resuming the system with in-kernel suspend. This depends on the |
|resume=<device/path>||Specify the device and path from which you want to resume.|
|lvm||Scan for volume groups. If any are found, activate them.|
|luks_trim||Enable support for TRIM on your LUKS encrypted root device. This option is very helpful for those using SSDs.|
|enc_root=<device>||The device that you wish to decrypt using |
|root=<device>||The name of your root device.|
|rootfstype=<fstype>||Specify the type of filesystem that your rootfs uses.|
|rootdelay=||How long the initramfs should wait before attempting to mount devices.|
|rootflags=x||Pass x flags to |
Below are examples of different use cases for better-initramfs and how your
/etc/boot.conf should be configured for them.
Realize that your
rootfstypevariables may be different from the examples provided below.
Regular ext4 root
Encrypted root with lvm
Encrypted root with lvm and RAID
To install Dracut, simply emerge it:
# emerge dracut
Build the initramfs
To build the initrd with dracut, we just execute:
# dracut -f --fstab --xz /boot/initramfs-3.2.6-pf.img 3.2.6-pf
Generally, this should be enough! If you experience booting problems like missing modules / drivers then just boot from your livecd and fix Dracut or consider changing to another initramfs. You can look into the man page to tweak the command a bit (e.g. --add-drivers "xz dm_crypt" etc...).