Initramfs

From Funtoo
Revision as of 17:09, 5 August 2014 by Duncan.britton (Talk | contribs)

Jump to: navigation, search

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.

better-initramfs

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.

Installation

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

Building /initramfs.cpio.gz

Now that you have better-initramfs on your system, we can make the initramfs.cpio.gz image and move it to /boot.

Note: do not run make prepare or make image until 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

Configuring /etc/boot.conf

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):

Options

Option Description
rescueshell Drop to the rescueshell before mounting rootfs to /newroot
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_addr=<ipaddr/cidr> Configure ipaddr with cidr netmask. For example: 11.11.11.2/24. If you do not add a netmask, the netmask is assumed to be 32. Furthermore, you will have to configure binit_net_gw.
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 /usr/lib/systemd/systemd. The default for this option (/sbin/init) will work fine with OpenRC.
tuxonice Try resuming with TuxOnIce.
uswsusp Try resuming the system with userspace software suspend. This depends on the resume option.
swsusp Try resuming the system with in-kernel suspend. This depends on the resume option.
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 Run cryptsetup luksOpen on the enc_root variable.
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 cryptsetup luksOpen.
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 mount as it mounts your rootfs.

Examples

Below are examples of different use cases for better-initramfs and how your /etc/boot.conf should be configured for them.

Note: Realize that your enc_root, root, and rootfstype variables may be different from the examples provided below.

Regular ext4 root

/etc/boot.conf
"Funtoo Linux" {
	kernel	vmlinuz[-v]
	initrd	/initramfs.cpio.gz
	params	+= root=/dev/sdaX rootfstype=ext4
}

Encrypted root with lvm

/etc/boot.conf
"Funtoo Linux" {
	kernel	vmlinuz[-v]
	initrd	/initramfs.cpio.gz
	params	+= enc_root=/dev/sdaX lvm luks luks_trim root=/dev/mapper/funtoo--vg-root rootfstype=ext4
}

Encrypted root with lvm and RAID

/etc/boot.conf
"Funtoo Linux" {
	kernel	vmlinuz[-v]
	initrd	/initramfs.cpio.gz
	params	+= enc_root=/dev/md0 lvm luks luks_trim softraid root=/dev/mapper/funtoo--vg-root rootfstype=ext4
}