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 included 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.
Installation from git
To install better-initramfs on your system, change to the
/opt directory (or any other directory that you deem suitable for building packages in) and clone the better-initramfs repository from bitbucket:
# cd /opt # git clone https://bitbucket.org/piotrkarbowski/better-initramfs.git
Now that you have the better-initramfs sources on your system, we can build the
initramfs.cpio.gz image and move it to
# cd better-initramfs # bootstrap/bootstrap-all # make prepare # make image # cp output/initramfs.cpio.gz /boot
Installation using portage
If you don't want the version from git with the newest features and bugs, you can emerge
# emerge better-initramfs-bin
gzip use flag
The ebuild for
better-initramfs-bin allows for the installation of the better-initramfs initramfs without gzip compression. Although gzip compression is enabled on the image by default, it can be disabled by emering
better-initramfs-bin without the gzip USE flag. To disable the gzip use flag for
better-initramfs-bin, do the following:
# mkdir /etc/portage/package.use (if it doesn't exist on your system) # echo "sys-kernel/better-initramfs-bin -gzip" > /etc/portage/package.use/better-initramfs-bin
Now, when better initramfs is emerged, the initramfs file in
/boot will be called
/boot/initramfs.cpio instead of
initramfs.cpio.gz. To emerge better initramfs, run the following:
# emerge better-initramfs-bin
Now that the
initramfs.cpio 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 rescueshell just before mount rootfs to /newroot.|
|sshd||Run sshd server. Lets you ssh into initramfs on error, to input password for encrypted rootfs, or to fix something remotly.|
|sshd_wait=x||Wait X seconds after setting up sshd, useful when you want to login (and thus pause boot process) before booting real system.|
|sshd_port=x||Setup sshd to listen on X port. Default: 22.|
|binit_net_if=<id>||Specify on which interface the network should be configured. Optionally a vlan can be specified separated by a dot. Example: eth0 or eth0.55|
|binit_net_addr=<addr/cidr>||Configure <addr> with <cidr> netmask on binit_net_if. Usualy you want something like '188.8.131.52/24'. If you will not add /CIDR, the IP will be configured with /32 thus you will be not able to connect to it unless you specify binit_net_gw.|
|binit_net_gw=<addr>||Optional gateway config, if you want to connect via WAN.|
|rw||Mount rootfs in read-write. Default: read-only.|
|mdev||Don't check if kernel support devtmpfs, use mdev instead. (Useful for really old kernels).|
|softraid||Get up raid arrays|
|init=x||Run X after switching to newroot, Default: /sbin/init.|
|tuxonice||Try resuming with TuxOnIce. Depends on resume= variable which points to the device with image, usualy swap partition.|
|uswsusp||Try resuming with userspace software suspend. Depends on resume= variable which points to the device with the system snapshot, usually swap partition.|
|swsusp||Try resuming with swusps (in-kernel suspend). Depends on resume= variable which points to the device with system snapshot, usually swap partition.|
|resume=<device/path>||Specify device from which you want to resume (with tuxonice or uswsusp).|
|lvm||Scan all disks for volume groups and activate them.|
|luks||Do cryptsetup luksOpen on enc_root variable.|
|enc_root=<device>||For example /dev/sda2 if sda2 is your encrypted rootfs. This variable is ignored if luks isn't enabled. You can specify multiple devices with colon as separator, like enc_root=/dev/sda2:/dev/sdb2:/dev/vda1.|
|root=<device>||For example /dev/mapper/enc_root if you have LUKS-encrypted rootfs, /dev/mapper/vg-rootfs or similar if lvm or just /dev/sdXX if you haven't rootfs over lvm or encrypted.|
|rootfstype=<filesystem type>||Set type of filesystem on your rootfs if you do not want to use 'auto',|
|rootdelay=<integer>||Set how many seconds initramfs should wait [for devices]. Useful for rootfs on USB device.|
|rootflags=x||Pass X flag(s) to mount while mounting rootfs, you can use it to specify which btrfs subvolume you want to mount.|
|luks_no_discards||Disable discards support on LUKS level, use if you don't want to allow lvm layer (if used) to send discards on reduce/resize or filesystem layer on file deletions to underlaying storage thru dmcrypt luks layer. Disabling discards on SSD-type storage may noticable degradate performance over time.|
|bcache||Bring up bcache devices. This will get ready for use /dev/bcache* which means one can have rootfs on bcache as well as anything else.|
Below are examples of different use cases for better-initramfs and how your
/etc/boot.conf should be configured for them.
Realize that your
rootfstype variables may be different from the examples provided below.
Regular ext4 root
Encrypted root with lvm
Encrypted root with lvm and RAID
To install Dracut, emerge it:
# emerge dracut
Build the initramfs
To build the initrd with dracut, run:
# 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...).