Skip to content

Instantly share code, notes, and snippets.

@Zerophase
Created May 30, 2019 03:44
Show Gist options
  • Save Zerophase/7a3657ce0a6eefa64dfb41cd36a9a841 to your computer and use it in GitHub Desktop.
Save Zerophase/7a3657ce0a6eefa64dfb41cd36a9a841 to your computer and use it in GitHub Desktop.
minimal initramfs without udev
# mkinitcpio preset file for the 'linux-ck' package
ALL_config="/etc/mkinitcpio.conf"
ALL_kver="/boot/vmlinuz-linux-ck"
PRESETS=('default' 'fallback')
#default_config="/etc/mkinitcpio.conf"
default_image="/boot/initramfs-linux-ck.img"
default_options="-S udev,block,mdadm_udev,filesystems,keyboard,fsck,consolefont"
#fallback_config="/etc/mkinitcpio.conf"
fallback_image="/boot/initramfs-linux-ck-fallback.img"
fallback_options="-S autodetect,without-udev"
# vim:set ft=sh
# MODULES
# The following modules are loaded before any boot hooks are
# run. Advanced users may wish to specify all system modules
# in this array. For instance:
# MODULES=(piix ide_disk reiserfs)
MODULES=(ext4 sd_mod ahci ehci_pci xhci_pci nvidia nvidia_modeset nvidia_uvm nvidia_drm nvme crc32c_intel lz4 lz4_compress)
# BINARIES
# This setting includes any additional binaries a given user may
# wish into the CPIO image. This is run last, so it may be used to
# override the actual binaries included by a given hook
# BINARIES are dependency parsed, so you may safely ignore libraries
BINARIES=(fsck fsck.ext4 e2fsck)
# FILES
# This setting is similar to BINARIES above, however, files are added
# as-is and are not parsed in any way. This is useful for config files.
FILES=()
# HOOKS
# This is the most important setting in this file. The HOOKS control the
# modules and scripts added to the image, and what happens at boot time.
# Order is important, and it is recommended that you do not change the
# order in which HOOKS are added. Run 'mkinitcpio -H <hook name>' for
# help on a given hook.
# 'base' is _required_ unless you know precisely what you are doing.
# 'udev' is _required_ in order to automatically load modules
# 'filesystems' is _required_ unless you specify your fs modules in MODULES
# Examples:
## This setup specifies all modules in the MODULES setting above.
## No raid, lvm2, or encrypted root is needed.
# HOOKS=(base)
#
## This setup will autodetect all modules for your system and should
## work as a sane default
# HOOKS=(base udev autodetect block filesystems)
#
## This setup will generate a 'full' image which supports most systems.
## No autodetection is done.
# HOOKS=(base udev block filesystems)
#
## This setup assembles a pata mdadm array with an encrypted root FS.
## Note: See 'mkinitcpio -H mdadm' for more information on raid devices.
# HOOKS=(base udev block mdadm encrypt filesystems)
#
## This setup loads an lvm2 volume group on a usb device.
# HOOKS=(base udev block lvm2 filesystems)
#
## NOTE: If you have /usr on a separate partition, you MUST include the
# usr, fsck and shutdown hooks.
HOOKS=(base without-udev udev autodetect modconf block filesystems keyboard)
# COMPRESSION
# Use this to compress the initramfs image. By default, gzip compression
# is used. Use 'cat' to create an uncompressed image.
#COMPRESSION="gzip"
#COMPRESSION="bzip2"
#COMPRESSION="lzma"
# COMPRESSION="xz"
#COMPRESSION="lzop"
COMPRESSION="lz4"
# COMPRESSION_OPTIONS
# Additional options for the compressor
# COMPRESSION_OPTIONS=(--threads=0)
#!/bin/ash
# minimal initramfs files are created wihtout udev.
# This hooks provices a polling disk mount replacement for udev.
# udev hook can be removed, resulting in smaller initramfs files.
run_hook () {
local dev timeout sleepval device=$root
# if udev is running then exit
[ "$udevd_running" -eq 1 ] && return
# try for (timeout * sleepval =) 10 second to handle slow (USB) devices
timeout=1000
sleepval=0.01
case $device in
# label to resolve, when resolved the kernel block device also exists
UUID=*|LABEL=*|PARTUUID=*|PARTLABEL=*)
while [ $timeout -gt 0 ]; do
timeout=$((timeout - 1))
dev=$(blkid -lt "$device" -o device)
[ -n "$dev" ] && timeout=0 || sleep $sleepval
done
;;
# kernel named block device, poll for existence
/dev/*)
while [ $timeout -gt 0 ]; do
timeout=$((timeout -1))
if [ -b "$device" ]; then
dev=$device
timout=0
else
sleep $sleepval
fi
done
;;
esac
}
# vim:set syntax=sh:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment