mkinitcpio

Aus wiki.archlinux.de

mkinitcpio ist die nächste Generation der initramfs-Erstellung. Es hat viele Vorteile gegenüber den alten Skripten mkinitrd und mkinitramfs.

  • Es nutzt klibc und kinit der Linux-Entwickler, welches eine kleine und leichtgewichtige Basis bereitstellt, um Programme sehr früh im userspace laufen zu lassen.
  • Es kann mittels udev die Hardware zur Laufzeit erkennen, so dass nur die wirklich nötigen Module geladen werden.
  • Die hook-basierenden init-Scripte sind leicht erweiterbar und können auch durch externe Pakete genutzt werden.
  • Es unterstützt bereits lvm2, dm-crypt (legacy und luks volumes), raid, swsusp und suspend2 Fortsetzen und Starten von usb Datenträgern.
  • Viele Funktionen können von der Kernel-Kommandozeile konfiguriert werden ohne das Image neu erstellen zu müssen.
  • Mit dem mkinitcpio-Skript ist es möglich, das Image in den Kernel zu integrieren.

mkinitcpio wurde von phrakture und tpowa mit Hilfe aus der Community entwickelt.

Installation

Das Programm ist als mkinitcpio in core verfügbar, und kann von dort mittels Pacman installiert werden.

pacman -S mkinitcpio

mkinitcpio ist Bestandteil jeder Arch Linux Installation.

Konfiguration

Die Konfigurationsdatei lautet /etc/mkinitcpio.conf.

MODULES

Mit dem MODULES-Eintrag können Module explizit dem Image hinzugefügt werden.

Beispiel: Bei Verwendung des nouveau Treiber wird bereits die Konsole beim Starten diesen verwenden.

MODULES=(nouveau)

BINARIES und FILES

Mit diesen Optionen können Dateien dem Abbild hinzugefügt werden. Der einzige Unterschied zwischen BINARIES und FILES ist, dass BINARIES die Bibliotheken nach Abhängigkeiten durchsucht, während FILES nur Dateien hinzufügt.

HOOKS

Dies ist der wichtigste Teil der mkinitcpio Konfiguration. Diese Zeile enthält alle HOOKS, welche während der Imageerstellung oder zur Laufzeit ausgeführt werden. Hierbei muss die Reihenfolge beachtet werden:

HOOKS=(foo1 foo2 bar1 bar2)

Am besten man prüft anhand des eigenen Systems, welche HOOKS aktuell verfügbar sind. Zusätzlich wird angezeigt, welche als veraltet gelten, und welche zukünftig verwendet werden sollen.

mkinitcpio -L

Für jeden gelisteten HOOK gibt es eine Zusatzinfo.

mkinitcpio -H base

Verfügbare HOOKS

Hook Information
base This hook provides crucial runtime necessities for booting. DO NOT remove this hook unless you know what you're doing.
udev This hook will use udev to create your root device node and detect the needed modules for your root device. It is also required for firmware loading in initramfs. It is recommended to use this hook.
microcode This hook adds early microcode update files for Intel and AMD processors. If /boot/amd-ucode.img or /boot/intel-ucode.img exist, they are included in the initcpio. If not, the individual microcode files in /lib/firmware/ are included if they exist. If the autodetect hook runs before this hook, it will only add early microcode update files for the processor of the system the image is built on.
systemd This will install a basic systemd setup in your initramfs, and is meant to replace the 'base', 'usr', 'udev' and 'timestamp' hooks. Other hooks with runtime components will need to be ported, and will not work as intended. You also may wish to still include the 'base' hook (before this hook) to ensure that a rescue shell exists on your initramfs.
modconf This hook installs modprobe configuration files from /etc/modprobe.d and /usr/lib/modprobe.d.
usr This provides a support for mounting /usr via a late running hook. No configuration is needed, as the mount options will be pulled directly from the fstab on the real root device.
autodetect This hook shrinks your initramfs to a smaller size by autodetecting the needed modules. Be sure to verify included modules are correct and none are missing. This hook must be run before other subsystem hooks in order to take advantage of auto-detection. Any hooks placed before 'autodetect' will be installed in full.
sata This hook is deprecated in favor of 'block'
scsi This hook is deprecated in favor of 'block'
usb This hook is deprecated in favor of 'block'
fw This hook is deprecated in favor of 'block'
block This hook loads the necessary modules for most block devices using pata, sata, scsi, firewire, usb, or mmc. Detection will take place at runtime. To minimize the modules in the image, add the autodetect hook too.
usbinput This hook is deprecated in favor of 'keyboard'
keyboard This hook loads the necessary modules for keyboard devices. As a side-effect modules for some non-keyboard input devices might be added to, but this should not be relied on. Detection will take place at runtime. To minimize the modules in the image, add the autodetect hook too.
filesystems This hook adds filesystems modules to the image. If you would like to minimize the modules installed in the image, add the autodetect hook too.
lvm2 This hook enables LVM2 volumes in initramfs. Do pacman -S lvm2 before.
sd-lvm2 This hook enables LVM2 volumes in systemd-based initramfs. Do pacman -S lvm2 before.
mdadm This hook loads the necessary modules for any raid root device, and assembles the raid device when run. If arrays are defined in /etc/mdadm.conf, the file will be used instead of command line assembling. Do pacman -S mdadm before. Please see mkinitcpio -H mdadm
dmraid This hook loads the necessary modules for a dmraid root device. Do pacman -S dmraid before.
encrypt This hook allows for an encrypted root device. Users should specify the device to be unlocked using 'cryptdevice=device:dmname' on the kernel command line, where 'device' is the path to the raw device, and 'dmname' is the name given to the device after unlocking, and will be available as /dev/mapper/dmname. Do pacman -S cryptsetup before. Please see mkinitcpio -H encrypt
sd-encrypt This hook allows for an encrypted root device. Users should specify the device to be unlocked using 'cryptdevice=device:dmname' on the kernel command line, where 'device' is the path to the raw device, and 'dmname' is the name given to the device after unlocking, and will be available as /dev/mapper/dmname. Do pacman -S cryptsetup before. Please see mkinitcpio -H sd-encrypt
resume This hook initializes support for resuming from Disk. Supports swsusp and suspend2.
fschk This hook provides fsck and filesystem specific helpers to perform an fsck operation on the root device prior to mounting. If the autodetect hook is used, only the fsck helper specific to your filesystem will be added to the image. It is highly recommended that if you include this hook that you also include any necessary modules to ensure your keyboard will work in early userspace. Please see mkinitcpio -H fsck
consolefont This hook loads consolefont specified in vconsole.conf during early userspace.
sd-vconsole This hook adds the keymap(s) and font specified in vconsole.conf to the image and loads them during early userspace.

Beispiele:

Diese Konfiguration sollte für die meisten Benutzer funktionieren:

HOOKS=(base systemd autodetect modconf block filesystems sd-vconsole fsck)

Du kannst verschlüsselte Dateisysteme innerhalb von lvm nutzen:

HOOKS=(base autodetect modconf block lvm2 encrypt filesystems keyboard consolefont fsck)

Du kannst verschlüsselte Dateisysteme innerhalb von lvm nutzen, wenn systemd im Einsatz ist:

HOOKS=(base systemd autodetect modconf block sd-lvm2 sd-encrypt filesystems sd-vconsole fsck)

COMPRESSION

# Use this to compress the initramfs image. By default, gzip compression is used. Use 'cat' to create an uncompressed image.
COMPRESSION=(xz)

COMPRESSION_OPTIONS

# Additional options for the compressor
COMPRESSION_OPTIONS=(-9)

Erstellen des Images

Erstelle das Image mit folgendem Befehl:

# mkinitcpio -p linux

Extrahieren des Images

Wenn du wissen möchtest, was sich innerhalb des initrd-Abbildes befindet, kann du es auspacken und in den enthaltenen Dateien herumstöbern.

Das initrd-Abbild ist ein 'SVR4 CPIO'-Archiv, das durch die Befehle find und bsdcpio erstellt wurde und optional durch ein vom Kernel verstandenes Komprimierungsschema komprimiert wurde: genauer gesagt gzip, bzip2, lzma, lzo oder xz.

mkinitcpio beinhaltet ein Werkzeug namens lsinitcpio, welches die Inhalte des initramfs-Abbildes anzeigt und extrahiert.

Das Anzeigen der Dateien im Abbild geschieht durch:

# lsinitcpio /boot/initramfs-linux.img

Man kann sich auch eine Auflistung der wichtigen Teile des Abbildes anzeigen lassn:

# lsinitcpio -a /boot/initramfs-linux.img

Das Extrahieren aller Dateien in das aktuelle Verzeichnis:

# lsinitcpio -x /boot/initramfs-linux.img

Kernelzeile anpassen

Einige Optionen müssen in der Kernelzeile angegeben werden. Einige Mkinitcpio Hooks haben spezielle Optionen. Um diese soll es in diesem Abschnitt gehen.

Wenn du nicht weißt was die Kernelzeile ist, schau in die Dokumentationen von GRUB oder Syslinux.

Failsafe Modus

Wenn du

break=y

zur Kernelzeile hinzufügst, dann stoppt Init nach dem das Setup vollständig ist und du landest in einer dash shell. Diese kann genutzt werden um sich über den Erfolg des Vorgangs zu versichern. Wenn du dich ausloggst geht der normale Bootvorgang weiter.

Hooks deaktivieren

Du kannst hooks deaktivieren indem du disablehooks zur Kernelzeile hinzufügst:

disablehooks=hook1,hook2,hook2

zum Beispiel

disablehooks=resume

Module blacklisten

Du kannst Module blacklisten indem du disablemodules zur Kernelzeile hinzufügst:

disablemodules=mod1,mod2,mod3

zum Beispiel

disablemodules=ata_piix