#!/bin/bash # # Generator script for a dracut initramfs # Tries to retain some degree of compatibility with the command line # of the various mkinitrd implementations out there # # Copyright 2008, Red Hat, Inc. Jeremy Katz # GPLv2 header here [ -f /etc/dracut.conf ] && . /etc/dracut.conf while (($# > 0)); do case $1 in -f|--force) force=yes;; -m|--modules) dracutmodules="$2"; shift;; -h|--help) echo "Usage: $0 [-f] " exit 1 ;; -v|--verbose) set -x;; -l|--local) allowlocal="yes" ;; --allow-missing) : ;; *) break ;; esac shift done [[ $dracutmodules ]] || dracutmodules="all" [[ $2 ]] && kernel=$2 || kernel=$(uname -r) [[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img" if [[ -f $outfile && ! $force ]]; then echo "Will not override existing initramfs ($outfile) without --force" exit 1 fi [[ $allowlocal && -f dracut-functions ]] && dsrc="." || dsrc=/usr/libexec/dracut . $dsrc/dracut-functions hookdirs="pre-udev pre-mount pre-pivot mount" readonly initdir=$(mktemp -d -t initramfs.XXXXXX) trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die. export initdir hookdirs dsrc dracutmodules modules # Create some directory structure first for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot dev/pts; do mkdir -p "$initdir/$d"; done # source all our modules for moddir in "$dsrc/modules.d"/*; do [[ -d $moddir || -L $moddir ]] || continue mod=${moddir##*/}; mod=${mod#[0-9][0-9]}; if [[ $dracutmodules = all ]] || strstr "$dracutmodules" "$mod"; then [[ -x $moddir/install ]] && . "$moddir/install" fi done unset moddir ## final stuff that has to happen # generate module dependencies for the initrd /sbin/depmod -a -b "$initdir" $kernel || { error "\"/sbin/depmod -a $kernel\" failed." exit 1 } # make sure that library links are correct and up to date ldconfig -r "$initdir" ( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )