The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
Difference between revisions of "Initramfs"
(Updated the <code> and <console> tags on the page to {{c}} and {{console}} templates. Replaced the old table of better initramfs arguments with a new one.) |
(this package no longer present) |
||
Line 27: | Line 27: | ||
###i## make image | ###i## make image | ||
###i## cp output/initramfs.cpio.gz /boot | ###i## cp output/initramfs.cpio.gz /boot | ||
}} | }} | ||
Revision as of 11:45, March 23, 2016
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.
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 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:
root # cd /opt root # git clone https://bitbucket.org/piotrkarbowski/better-initramfs.git
Building /initramfs.cpio.gz
Now that you have the better-initramfs sources on your system, we can build the initramfs.cpio.gz
image and move it to /boot
.
Do not run make prepare
or make image
until you have configured your kernel. If you have not installed / configured a kernel yet, read: Building a Kernel From Source and Funtoo Linux Kernels.
root # cd better-initramfs root # bootstrap/bootstrap-all root # make prepare root # make image root # cp output/initramfs.cpio.gz /boot
Configuring /etc/boot.conf
Now that the initramfs.cpio.gz
or 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):
Options
Option | Description |
---|---|
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 '1.2.3.4/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. |
Examples
Below are examples of different use cases for better-initramfs and how your /etc/boot.conf
should be configured for them.
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
}
Dracut
Installation
To install Dracut, emerge it:
root # emerge dracut
Build the initramfs
To build the initrd with dracut, run:
root # 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...).
Configuring /etc/boot.conf
Examples
Encrypted root with lvm
/etc/boot.conf
boot {
generate grub
default "Funtoo Linux dracut"
timeout 3
}
"Funtoo Linux dracut" {
kernel vmlinuz[-v]
initrd initramfs[-v].img
params = quiet rootfstype=ext4
params += luks enc_root=/dev/sda3
params += lvm root=/dev/mapper/vg-root
}