basementhud/mkinitramfs.sh

38 lines
1.1 KiB
Bash

#!/bin/sh
set -eu
destdir="$(readlink -e "$1")"
kver=$(rpm --root "${destdir}" -q --qf '%{VERSION}-%{RELEASE}.%{ARCH}' kernel)
printf 'Building initramfs image for kernel %s\n' "${kver}"
cd "${destdir}"
mkdir -p boot dev proc sys tmp
mountpoint -q dev || mount -o bind /dev dev
mountpoint -q proc || mount -t proc proc proc
mountpoint -q sys || mount -t sysfs sysfs sys
mountpoint -q tmp || mount -t tmpfs tmpfs tmp
echo 'Copying kernel image to /boot/ ...' >&2
cp -a "${destdir}"/lib/modules/"${kver}"/vmlinuz \
"${destdir}"/boot/
echo 'Running depmod ...' >&2
chroot "${destdir}" depmod -a "${kver}"
echo 'Building initramfs image ...' 2>&1
chroot "${destdir}" dracut \
--no-hostonly \
--modules 'nbd udev-rules dracut-systemd shutdown' \
--drivers 'genet nbd squashfs' \
--force-drivers 'bcm2835_wdt i2c_bcm2835 rtc_pcf85063' \
--force \
/boot/initramfs.img \
"${kver}"
echo 'Fixing boot file pemissions ...' 2>&1
find "${destdir}"/boot \
-type d -exec chmod a+rx {} + \
-or \
-type f -exec chmod a+r {} +
umount tmp sys proc dev