#!/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