#!/bin/sh set -e scriptloc=${BASH_SOURCE:-$0} scriptdir=${scriptloc%/*} gen_cpio_list() { cat << EOF dir /dev 0755 0 0 dir /mnt 0755 0 0 dir /proc 0755 0 0 dir /run 0755 0 0 dir /run/cryptsetup 0755 0 0 dir /sys 0755 0 0 nod /dev/console 0600 0 0 c 5 1 slink /bin/sh busybox 0755 0 0 slink /etc/mtab /proc/self/mounts 0755 0 0 slink /usr/lib64/libgcc_s.so libgcc_s.so.1 0755 0 0 file /usr/lib64/libgcc_s.so.1 /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/libgcc_s.so.1 0755 0 0 file /bin/busybox /bin/busybox 0755 0 0 file /etc/passwd $scriptdir/passwd 0644 0 0 file /etc/dropbear/dropbear_rsa_host_key $scriptdir/dropbear_rsa_host_key 0600 0 0 file /etc/dropbear/dropbear_ecdsa_host_key $scriptdir/dropbear_ecdsa_host_key 0600 0 0 file /init $scriptdir/init 0755 0 0 file /lib/firmware/radeon/CAYMAN_mc.bin /lib/firmware/radeon/CAYMAN_mc.bin 0644 0 0 file /lib/firmware/radeon/CAYMAN_me.bin /lib/firmware/radeon/CAYMAN_me.bin 0644 0 0 file /lib/firmware/radeon/CAYMAN_pfp.bin /lib/firmware/radeon/CAYMAN_pfp.bin 0644 0 0 file /lib/firmware/radeon/CAYMAN_rlc.bin /lib/firmware/radeon/CAYMAN_rlc.bin 0644 0 0 file /lib/firmware/radeon/CAYMAN_smc.bin /lib/firmware/radeon/CAYMAN_smc.bin 0644 0 0 file /lib/firmware/radeon/SUMO_uvd.bin /lib/firmware/radeon/SUMO_uvd.bin 0644 0 0 file /lib/firmware/rtl_nic/rtl8168h-2.fw /lib/firmware/rtl_nic/rtl8168h-2.fw 0644 0 0 file /lib64/libnss_files.so.2 /lib64/libnss_files.so.2 0755 0 0 file /root/.ssh/authorized_keys $scriptdir/authorized_keys 0600 0 0 file /unlock $scriptdir/unlock 0755 0 0 EOF for cmd in cryptsetup e2fsck dropbear; do cmdp="$(command -v "$cmd")" # builtin if [ "$cmd" = "$cmdp" ]; then continue fi ldd "$cmdp" | while read a b c d; do if [ "$b" = '=>' ]; then printf 'file /lib64/%s %s 0755 0 0\n' "${c##*/}" "$c" else # interpreter case "$a" in /*) printf 'file %s %s 0755 0 0\n' "$a" "$a" ;; esac fi done printf 'file %s %s 0755 0 0\n' "$cmdp" "$cmdp" done } gen_dir_ents() { while read type target args; do printf '%s %s %s\n' "$type" "$target" "$args" while [ "${target%/*}" != '' ]; do target=${target%/*} printf 'dir %s 0755 0 0\n' "$target" done done } gen_depfile() { deps='make' while read type target source args; do printf '%s %s %s %s\n' "$type" "$target" "$source" "$args" if [ "$type" = file ]; then deps="$deps $source" echo "$source:" >&3 fi done echo "initramfs.img: $deps" >&3 } gen_cpio_list | gen_dir_ents | sort -u | gen_depfile 3>initramfs.d | "${scriptdir}"/gen_init_cpio -t 0 - | xz --x86 --lzma2=preset=9e --check=crc32 -c > initramfs.img # vim:ft=sh: