2019-01-23 22:02:34 +00:00
|
|
|
#!/bin/sh
|
2024-11-01 21:13:31 +00:00
|
|
|
#BLURB="Generate an initrd for the kernel"
|
2019-01-23 22:02:34 +00:00
|
|
|
|
2024-07-25 20:22:54 +00:00
|
|
|
# Load defaults:
|
|
|
|
if [ -r etc/default/geninitrd ]; then
|
|
|
|
. etc/default/geninitrd
|
2019-01-23 22:02:34 +00:00
|
|
|
fi
|
|
|
|
|
2024-11-01 21:13:31 +00:00
|
|
|
# This was the old name for $KERNEL, so allow it still:
|
|
|
|
KERNEL=$KERNEL_SYMLINK
|
|
|
|
|
|
|
|
if [ -z "$KERNEL" ]; then
|
|
|
|
# If we weren't told anything else, then use the newest kernel:
|
|
|
|
KERNEL="$(find /boot -name "vmlinuz-*" -type f | xargs ls -t | head -n 1)"
|
2019-01-23 22:02:34 +00:00
|
|
|
fi
|
|
|
|
|
2024-11-01 21:13:31 +00:00
|
|
|
# In case this is a symlink, get the real file:
|
|
|
|
KERNEL="$(readlink -f $KERNEL)"
|
|
|
|
|
2024-07-25 20:22:54 +00:00
|
|
|
# Find the kernel version:
|
2024-11-01 21:13:31 +00:00
|
|
|
if [ -r $KERNEL ]; then
|
|
|
|
if file $KERNEL | grep -wq "Linux kernel" ; then
|
|
|
|
KERNEL_VERSION=$(strings $KERNEL | grep '([^ ]*@[^ ]*) #' | cut -f1 -d' ')
|
|
|
|
else
|
|
|
|
echo "error: $KERNEL is not a Linux kernel."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "error: was not given a KERNEL to make an initrd."
|
|
|
|
exit 1
|
2019-03-03 22:03:39 +00:00
|
|
|
fi
|
|
|
|
|
2024-07-25 20:22:54 +00:00
|
|
|
# Sometimes mkinitrd_command_generator.sh does not detect LVM properly. Until I
|
|
|
|
# get to the bottom of that, it's safer to just always include LVM support.
|
|
|
|
LVM_OPTION="-L"
|
|
|
|
|
2019-03-03 22:03:39 +00:00
|
|
|
# Generate the initrd:
|
2024-11-01 21:13:31 +00:00
|
|
|
if [ -z "$GENINITRD_SILENT" ]; then
|
|
|
|
dialog --title "GENERATING INITIAL RAMDISK" --infobox \
|
|
|
|
"Generating an initial ramdisk for use with the $KERNEL_VERSION kernel. \
|
2024-07-25 20:22:54 +00:00
|
|
|
The initial ramdisk contains kernel modules needed to mount the \
|
2019-01-23 22:02:34 +00:00
|
|
|
root partition, and must be regenerated whenever the kernel is updated. To \
|
|
|
|
regenerate the initrd, select this setup script from within pkgtool, or run \
|
|
|
|
'geninitrd' which will produce an initial ramdisk (/boot/initrd.gz) for the \
|
2024-07-25 20:22:54 +00:00
|
|
|
installed kernel." 8 70
|
|
|
|
fi
|
2024-11-01 21:13:31 +00:00
|
|
|
chroot . /usr/share/mkinitrd/mkinitrd_command_generator.sh -k $KERNEL_VERSION -a "$LVM_OPTION -o /boot/initrd-${KERNEL_VERSION}.img" | chroot . bash 1> /dev/null 2> /dev/null
|
2024-07-25 20:22:54 +00:00
|
|
|
|
|
|
|
if [ "$GENINITRD_NAMED_SYMLINK" = "true" ]; then
|
2024-11-01 21:13:31 +00:00
|
|
|
# Make initrd symlinks for all matching kernel symlinks:
|
2024-07-25 20:22:54 +00:00
|
|
|
( cd boot
|
2024-11-01 21:13:31 +00:00
|
|
|
for symlink in $(find . -type l -name "vmlinuz-*") ; do
|
|
|
|
SYMLINK_VERSION=$(strings $symlink | grep '([^ ]*@[^ ]*) #' | cut -f1 -d' ')
|
|
|
|
if [ "$SYMLINK_VERSION" = "$KERNEL_VERSION" ]; then
|
|
|
|
KERNEL_NAME="$(echo $symlink | cut -f 2- -d -)"
|
|
|
|
rm -f initrd-${KERNEL_NAME}.img
|
|
|
|
ln -sf initrd-${KERNEL_VERSION}.img initrd-${KERNEL_NAME}.img
|
|
|
|
fi
|
|
|
|
done
|
2024-07-25 20:22:54 +00:00
|
|
|
)
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$GENINITRD_INITRD_GZ_SYMLINK" = "true" ]; then
|
|
|
|
( cd boot
|
|
|
|
rm -f initrd.gz
|
2024-11-01 21:13:31 +00:00
|
|
|
ln -sf initrd-${KERNEL_VERSION}.img initrd.gz
|
2024-07-25 20:22:54 +00:00
|
|
|
)
|
2019-01-23 22:02:34 +00:00
|
|
|
fi
|