slackware-current/source/a/mkinitrd/setup.01.mkinitrd
Patrick J Volkerding 9951f6a1a8 Fri Nov 8 22:17:50 UTC 2024
a/kernel-firmware-20241108_ad74054-noarch-1.txz:  Upgraded.
a/kernel-generic-6.11.7-x86_64-1.txz:  Upgraded.
  Unless disabled in /etc/default/geninitrd, automatically generate an initial
  ramdisk upon package installation or upgrade.
a/mkinitrd-1.4.11-x86_64-46.txz:  Rebuilt.
  geninitrd: also accept /opt/sbin/geninitrd as an override.
  Suggested by regdub.
  Since the installer sends different args to the setup scripts, we can't use
  $1 as the kernel file with setup.01.mkinitrd, so convert it into a variable
  in geninitrd instead (if needed).
  mkinitrd_command_generator.sh: pvdisplay will complain if there are any file
  descriptors besides stdin, stdout, and stderr, which will always be true when
  called from a package install script due to file locking. So send stderr from
  the two calls to pvdisplay to /dev/null.
d/kernel-headers-6.11.7-x86-1.txz:  Upgraded.
k/kernel-source-6.11.7-noarch-1.txz:  Upgraded.
l/python-packaging-24.2-x86_64-1.txz:  Upgraded.
n/iptables-1.8.11-x86_64-1.txz:  Upgraded.
n/lftp-4.9.3-x86_64-1.txz:  Upgraded.
x/ibus-m17n-1.4.34-x86_64-1.txz:  Upgraded.
x/xbacklight-1.2.4-x86_64-1.txz:  Upgraded.
x/xf86-video-nouveau-1.0.18-x86_64-1.txz:  Upgraded.
x/xrandr-1.5.3-x86_64-1.txz:  Upgraded.
xfce/xfce4-weather-plugin-0.11.3-x86_64-1.txz:  Upgraded.
extra/xf86-video-fbdev/xf86-video-fbdev-0.5.1-x86_64-1.txz:  Upgraded.
isolinux/initrd.img:  Rebuilt.
kernels/*:  Upgraded.
usb-and-pxe-installers/usbboot.img:  Rebuilt.
2024-11-09 00:53:08 +01:00

120 lines
4.2 KiB
Bash

#!/bin/sh
#BLURB="Generate an initrd for the kernel"
# If KERNEL_SYMLINK is defined and points to a kernel, we'll use that.
# Otherwise, if KERNEL is defined and points to a kernel, we'll use that.
# If none of these are true, we'll use the newest kernel we find in /boot.
# Load defaults:
if [ -r etc/default/geninitrd ]; then
. etc/default/geninitrd
fi
# If this is disabled, exit:
if [ "$KERNEL_DOINST" = "true" -a "$AUTOGENERATE_INITRD" = "false" ]; then
exit 0
fi
# 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)"
fi
# If we don't see $KERNEL, try looking in /boot:
if [ ! -r $KERNEL ]; then
if [ -r boot/$KERNEL ]; then
KERNEL=boot/$KERNEL
fi
fi
# In case this is a symlink, get the real file:
KERNEL="$(readlink -f $KERNEL)"
# Find the kernel version:
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
fi
# 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"
# Ditto on RAID:
RAID_OPTION="-R"
# This could be set to dracut in /etc/default/geninitrd:
GENERATOR=${GENERATOR:-mkinitrd}
# If we asked for mkinitrd, but do not have /etc/mkinitrd.conf, then fall
# back on mkinitrd_command_generator.sh instead:
if [ "$GENERATOR" = "mkinitrd" -a ! -r etc/mkinitrd.conf ]; then
GENERATOR=mkinitrd_command_generator.sh
fi
# If the GENERATOR does not exist, this is obviously a fatal error:
if [ "$GENERATOR" = "mkinitrd_command_generator.sh" -a ! -x /usr/share/mkinitrd/mkinitrd_command_generator.sh ]; then
echo "error: GENERATOR mkinitrd_command_generator.sh not found."
exit 1
elif [ "$GENERATOR" = "mkinitrd" -a ! -x /sbin/mkinitrd ]; then
echo "error: GENERATOR mkinitrd not found."
exit 1
elif [ "$GENERATOR" = "dracut" -a ! -x /usr/bin/dracut ]; then
echo "error: GENERATOR dracut not found."
exit 1
fi
# Generate the initrd:
if [ -z "$GENINITRD_SILENT" ]; then
dialog --title "GENERATING INITIAL RAMDISK" --infobox \
"Generating an initial ramdisk for use with the $KERNEL_VERSION kernel (using $GENERATOR). \
The initial ramdisk contains kernel modules needed to mount the \
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-${KERNEL_VERSION}.img) for the installed kernel." 0 0
fi
if [ "$GENERATOR" = "mkinitrd_command_generator.sh" ]; then
chroot . /usr/share/mkinitrd/mkinitrd_command_generator.sh -k $KERNEL_VERSION -a "$LVM_OPTION $RAID_OPTION -o /boot/initrd-${KERNEL_VERSION}.img" | chroot . bash 1> /dev/null 2> /dev/null
elif [ "$GENERATOR" = "mkinitrd" ]; then
chroot . /sbin/mkinitrd -F /etc/mkinitrd.conf -k $KERNEL_VERSION -o /boot/initrd-${KERNEL_VERSION}.img 1> /dev/null 2> /dev/null
elif [ "$GENERATOR" = "dracut" ]; then
# If no options were set, set basic ones:
if [ -z "$DRACUT_OPTS" ]; then
DRACUT_OPTS="--force --hostonly"
fi
chroot . /usr/bin/dracut $DRACUT_OPTS /boot/initrd-${KERNEL_VERSION}.img $KERNEL_VERSION 1> /dev/null 2> /dev/null
else
echo "error: no handler for GENERATOR=$GENERATOR"
echo "Unable to generate /boot/initrd-${KERNEL_VERSION}.img."
exit 1
fi
if [ "$GENINITRD_NAMED_SYMLINK" = "true" ]; then
# Make initrd symlinks for all matching kernel symlinks:
( cd boot
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
)
fi
if [ "$GENINITRD_INITRD_GZ_SYMLINK" = "true" ]; then
( cd boot
rm -f initrd.gz
ln -sf initrd-${KERNEL_VERSION}.img initrd.gz
)
fi