mkinitcpio - bunnyamin/bunnix GitHub Wiki

Build

Configuration Example
Build from /etc/mkinitcpio.conf. # mkinitcpio -p linux
Test configuration at different path. Excluding -g <file> will invoke a dry/test run. # mkinitcpio -c <file>
Build configuration at different path. # mkinitcpio -c <file> -g /boot/initramfs-linux.img
Error Remedy
/lib/modules/4.8.11-1-ARCH' is not a valid kernel module directory Manually specify one of the available kernel version in mkinitcpio using -k, for example, list available kernel modules ls -la /lib/modules and provide one to mkinitcpio -k 4.8.12-3-ARCH.

Configuration

Default configuration /etc/mkinitcpio.conf.

Directory Description
/etc/initcpio/install The directory install contains user bash scripts that are to be built.
/etc/initcpio/hooks The directory hooks contains user runtime bash scripts that must have a corresponding build script.

The resulting initramfs should be

  • small, around 50MiB and below, because a larger file could result in error: timeout reading netboot/initramfs-linux.nfs.img (atftpd.log), ICMP enp0s0.localdomain udp port 46503 unreachable, length 40 (tcpdump), and
  • readable otherwise ATFTP returns error File netboot/initramfs-linux.nfs.img not found.
  1. Copy the net bash script as net_nfs4 cp /usr/lib/initcpio/install/net /etc/initcpio/install/net_nfs4.
  2. Edit /etc/initcpio/install/net_nfs4
    1. -add_module nfsv3?
    2. +add_module nfsv4?
    3. -add_binary "/usr/lib/initcpio/nfsmount" "/bin/nfsmount"
    4. +add_binary "/usr/lib/initcpio/nfsmount" "/bin/mount.nfs4"
  3. Copy the net bash script as net_nfs4 cp /usr/lib/initcpio/hooks/net /etc/initcpio/hooks/net_nfs4.
  4. Edit /etc/initcpio/hooks/net_nfs4
    1. -nfsmount ${nfs_option:+-o ${nfs_option}} "${nfs_server}:${nfs_path}" "$1"
    2. +mount.nfs4 "${nfs_server}:${nfs_path}" "$1" ${nfs_option:+-o ${nfs_option}}
  5. Configure the mkinitcpio.netboot.nfs.conf
    • Auto-detect is necessary to keep the size of the initamfs image low.
    • If building on another hardware than the one to deploy on then auto-detect may exclude the necessary network driver. Therefore, manually add the module to ensure that ipconfig finds the network device.
    1. MODULES=(nfsv4 [module for network device])
    2. BINARIES=(/usr/bin/mount.nfs4)
    3. FILES=()
    4. HOOKS="base udev autodetect net_nfs4 ..."
    5. COMPRESSION="xz"
    6. COMPRESSION_OPTIONS="-9e"
  6. Build the new image: mkinitcpio -c <file> -g /netboot/initramfs-linux.nfs.img
  7. Ensure that the binaries are embedded in the initamfs:
    1. $ lsinitcpio -a /boot/initramfs-linux.img

The name of the hook must be "net_nfs4". For exemple, the name "net_nfs" causes the mkinitcpio to report:

==> WARNING: Hook 'net_nfs' is deprecated. Replace it with 'net_nfs4' in your config

For debugging purposes, in /usr/lib/initcpio/hooks/net_nfs4 add the following

nfs_mount_handler() {
  if
    ...
  fi
  + echo ""
  + echo "debug> mount.nfs4 ${nfs_server}:${nfs_path} [$1] -v ${nfs_option:+-o ${nfs_option}}"
  + echo ""

  - mount.nfs4 "${nfs_server}:${nfs_path}" "$1" ${nfs_option:+-o ${nfs_option}}
  + mount.nfs4 "${nfs_server}:${nfs_path}" "$1" -v ${nfs_option:+-o ${nfs_option}}

  + sleep 12
}

archlinux efi netboot kernel “ip” does not work?; systemd “Failed to start Switch Root.” -- asked Dec 3 at 2:26 -- user212827

Error, problem, troubleshooting

Error Event Consequence Cause Remedy
:: mounting '/dev/nfs' on real root
mount.nfs: remote share not in 'host:dir' format
:: Triggering uevents... Drops to emergency shell. Unknown; the net_nfs4 hook is never executed? Unknown
:: mounting '/dev/nfs' on real root
mount: /new_root: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program
dmesg(1) may have more information after failed mount system call.
:: Triggering uevents... Drops to emergency shell. Unknown; the net_nfs4 hook is never executed? Unknown
ipconfig: eth1: SIOCGIFINDEX: No such device
ipconfig: no devices to configure
:: running hook [net_nfs4] mount.nfs4: Network is unreachable... ERROR: Failed to mount the real root device. Bailing out, you are on your own. Good luck. Missing module or drivers for network device. Assign the network device module to the mkinitcpio configuration MODULES.
ipconfig: eth1: SIOCGIFINDEX: No such device
ipconfig: no devices to configure
:: running hook [net_nfs4] mount.nfs4: Network is unreachable... ERROR: Failed to mount the real root device. Bailing out, you are on your own. Good luck. The network interface name is wrong. Adjust the name in the boot kernel parameter ip=:::::eth1:dhcp or let it attempt to identify the interface ip=::::::dhcp.
No error Starting systemd-udevd... :: running hook [udev] Nothing happens The network interface name is wrong. Adjust the name in the boot kernel parameter ip=:::::eth1:dhcp or let it attempt to identify the interface ip=::::::dhcp.
⚠️ **GitHub.com Fallback** ⚠️