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.) |
|||
Line 6: | Line 6: | ||
== Do I need an initramfs? == | == 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 | 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 == | == better-initramfs == | ||
Line 12: | Line 12: | ||
=== Installation from git === | === Installation from git === | ||
To install better-initramfs on your system, change to the | To install better-initramfs on your system, change to the {{c|/opt}} directory (or any other directory that you deem suitable for building packages in) and clone the better-initramfs repository from bitbucket: | ||
{{console|body= | |||
###i## cd /opt | ###i## cd /opt | ||
###i## git clone https://bitbucket.org/piotrkarbowski/better-initramfs.git | ###i## git clone https://bitbucket.org/piotrkarbowski/better-initramfs.git | ||
}} | |||
=== Building | === Building {{c|/initramfs.cpio.gz}} === | ||
Now that you have better-initramfs on your system, we can | Now that you have the better-initramfs sources on your system, we can build the {{c|initramfs.cpio.gz}} image and move it to {{c|/boot}}. | ||
{{ | {{Note|Do not run {{c|make prepare}} or {{c|make image}} until you have configured your kernel. If you have not installed / configured a kernel yet, read: [[Building_a_Kernel_from_Source| Building a Kernel From Source]] and [[Funtoo_Linux_Kernels| Funtoo Linux Kernels]].}} | ||
{{console|body= | |||
###i## cd better-initramfs | ###i## cd better-initramfs | ||
###i## bootstrap/bootstrap-all | ###i## bootstrap/bootstrap-all | ||
Line 27: | Line 27: | ||
###i## make image | ###i## make image | ||
###i## cp output/initramfs.cpio.gz /boot | ###i## cp output/initramfs.cpio.gz /boot | ||
}} | |||
=== Installation using portage === | === Installation using portage === | ||
If you don't want the version from git with the newest features and bugs, you can emerge | If you don't want the version from git with the newest features '''and''' bugs, you can emerge {{c|better-initramfs-bin}}: | ||
{{console|body= | |||
###i## emerge better-initramfs-bin | |||
}} | |||
==== The {{c|gzip}} use flag ==== | |||
The ebuild for {{c|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 {{c|better-initramfs-bin}} without the gzip USE flag. To disable the gzip use flag for {{c|better-initramfs-bin}}, do the following: | |||
{{console|body= | |||
###i## mkdir /etc/portage/package.use (if it doesn't exist on your system) | |||
###i## echo "sys-kernel/better-initramfs-bin -gzip" > /etc/portage/package.use/better-initramfs-bin | |||
}} | |||
Now, when better initramfs is emerged, the initramfs file in {{c|/boot}} will be called {{c|/boot/initramfs.cpio}} instead of {{c|initramfs.cpio.gz}}. To emerge better initramfs, run the following: | |||
{{console|body= | |||
###i## emerge better-initramfs-bin | ###i## emerge better-initramfs-bin | ||
}} | |||
=== Configuring | === Configuring {{c|/etc/boot.conf}} === | ||
Now that the | Now that the {{c|initramfs.cpio.gz}} or {{c|initramfs.cpio}} file is in {{c|/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 [https://bitbucket.org/piotrkarbowski/better-initramfs better-initramfs Bitbucket page]): | ||
==== Options ==== | ==== Options ==== | ||
{{TableStart}} | |||
<tr class="info"><th>Option</th><th>Description</th></tr> | |||
<tr><td>rescueshell</td><td>Drop to rescueshell just before mount rootfs to /newroot.</td></tr> | |||
<tr><td>sshd</td><td>Run sshd server. Lets you ssh into initramfs on error, to input password for encrypted rootfs, or to fix something remotly.</td></tr> | |||
<tr><td>sshd_wait=x</td><td>Wait X seconds after setting up sshd, useful when you want to login (and thus pause boot process) before booting real system.</td></tr> | |||
<tr><td>sshd_port=x</td><td>Setup sshd to listen on X port. Default: 22.</td></tr> | |||
<tr><td>binit_net_if=<id></td><td>Specify on which interface the network should be configured. Optionally a vlan can be specified separated by a dot. Example: eth0 or eth0.55</td></tr> | |||
<tr><td>binit_net_addr=<addr/cidr></td><td>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.</td></tr> | |||
<tr><td>binit_net_gw=<addr></td><td>Optional gateway config, if you want to connect via WAN.</td></tr> | |||
<tr><td>rw</td><td>Mount rootfs in read-write. Default: read-only.</td></tr> | |||
<tr><td>mdev</td><td>Don't check if kernel support devtmpfs, use mdev instead. (Useful for really old kernels).</td></tr> | |||
<tr><td>softraid</td><td>Get up raid arrays</td></tr> | |||
<tr><td>init=x</td><td>Run X after switching to newroot, Default: /sbin/init.</td></tr> | |||
<tr><td>tuxonice</td><td>Try resuming with TuxOnIce. Depends on resume= variable which points to the device with image, usualy swap partition.</td></tr> | |||
<tr><td>uswsusp</td><td>Try resuming with userspace software suspend. Depends on resume= variable which points to the device with the system snapshot, usually swap partition.</td></tr> | |||
<tr><td>swsusp</td><td>Try resuming with swusps (in-kernel suspend). Depends on resume= variable which points to the device with system snapshot, usually swap partition.</td></tr> | |||
<tr><td>resume=<device/path></td><td>Specify device from which you want to resume (with tuxonice or uswsusp).</td></tr> | |||
<tr><td>lvm</td><td>Scan all disks for volume groups and activate them.</td></tr> | |||
<tr><td>luks</td><td>Do cryptsetup luksOpen on enc_root variable.</td></tr> | |||
<tr><td>enc_root=<device></td><td>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.</td></tr> | |||
<tr><td>root=<device></td><td>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.</td></tr> | |||
<tr><td>rootfstype=<filesystem type></td><td>Set type of filesystem on your rootfs if you do not want to use 'auto',</td></tr> | |||
<tr><td>rootdelay=<integer></td><td>Set how many seconds initramfs should wait [for devices]. Useful for rootfs on USB device.</td></tr> | |||
<tr><td>rootflags=x</td><td>Pass X flag(s) to mount while mounting rootfs, you can use it to specify which btrfs subvolume you want to mount.</td></tr> | |||
<tr><td>luks_no_discards</td><td>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.</td></tr> | |||
<tr><td>bcache</td><td>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.</td></tr> | |||
{{TableEnd}} | |||
==== Examples ==== | ==== Examples ==== | ||
Below are examples of different use cases for better-initramfs and how your | Below are examples of different use cases for better-initramfs and how your {{c|/etc/boot.conf}} should be configured for them. | ||
{{ | {{Note|Realize that your {{c|enc_root}}, {{c|root}}, and {{c|rootfstype}} variables may be different from the examples provided below.}} | ||
==== Regular ext4 root ==== | ==== Regular ext4 root ==== | ||
Line 145: | Line 109: | ||
== Dracut == | == Dracut == | ||
=== Installation === | === Installation === | ||
To install Dracut, | To install Dracut, emerge it: | ||
{{console|body= | |||
###i## emerge dracut | ###i## emerge dracut | ||
}} | |||
=== Build the initramfs === | === Build the initramfs === | ||
To build the initrd with dracut, | To build the initrd with dracut, run: | ||
{{console|body= | |||
###i## dracut -f --fstab --xz /boot/initramfs-3.2.6-pf.img 3.2.6-pf | ###i## dracut -f --fstab --xz /boot/initramfs-3.2.6-pf.img 3.2.6-pf | ||
}} | |||
Generally, this should be enough! | 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...). | 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. {{c|--add-drivers "xz dm_crypt"}} etc...). | ||
=== Configuring | === Configuring {{c|/etc/boot.conf}} === | ||
==== Examples ==== | ==== Examples ==== | ||
Revision as of 16:13, June 30, 2015
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
Installation using portage
If you don't want the version from git with the newest features and bugs, you can emerge better-initramfs-bin
:
root # emerge better-initramfs-bin
The 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:
root # mkdir /etc/portage/package.use (if it doesn't exist on your system) root # 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:
root # emerge better-initramfs-bin
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
}