Browse Source

Make the generator start to be functional on a "real" system

Start to pull in modules from the system rather than the crude hack of
everything in a tree and explicitly list some classes of modules
including what's needed for dm-crypt

With this, I am now running a dracut initramfs on my laptop
master
Jeremy Katz 16 years ago
parent
commit
641cc35629
  1. 106
      dracut
  2. 2
      init

106
dracut

@ -1,65 +1,109 @@ @@ -1,65 +1,109 @@
#/bin/bash
# Simple script that creates the tree to use for a new initrd
# note that this is not intended to be pretty, nice or anything
# of the sort. the important thing is working

#
# 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 <katzj@redhat.com>
# GPLv2 header here

if [ -f ./initrd-functions ]; then
source ./initrd-functions
else
source /usr/libexec/initrd-functions
fi

INITRDOUT=$1
if [ -z "$INITRDOUT" ]; then
echo "Please specify an initrd file to output"
[ -f /etc/dracut.conf ] && . /etc/dracut.conf

while [ $# -gt 0 ]; do
case $1 in
-f|--force)
force=yes
shift
;;
-h|--help)
echo "Usage: $0 [-f] <initramfs> <kernel-version>"
exit 1
;;
-v|--verbose)
set -x
shift
;;
*)
break
esac
done

if [ -n "$2" ]; then
kernel=$2
else
kernel=$(uname -r)
fi
if [ -n "$1" ]; then
outfile=$(readlink -f $1)
else
outfile="/boot/initrd-$kernel.img"
fi

tmpdir=$(mktemp -d)
if [ -f "$outfile" -a -z "$force" ]; then
echo "Will not override existing initramfs ($outfile) without --force"
exit 1
fi

initdir=$(mktemp -d -t initramfs.XXXXXX)

# executables that we have to have
exe="/bin/bash /bin/mount /bin/mknod /bin/mkdir /sbin/modprobe /sbin/udevd /sbin/udevadm /sbin/nash /bin/kill /sbin/pidof /bin/sleep /bin/echo"
lvmexe="/sbin/lvm"
cryptexe="/sbin/cryptsetup"
# and some things that are nice for debugging
debugexe="/bin/ls /bin/cat /bin/ln /bin/ps /bin/grep /usr/bin/less"
debugexe="/bin/ls /bin/cat /bin/ln /bin/ps /bin/grep /bin/more"
# udev things we care about
udevexe="/lib/udev/vol_id"

# install base files
for binary in $exe $debugexe $udevexe $lvmexe $cryptexe ; do
inst $binary $tmpdir
inst $binary $initdir
done

# FIXME: would be nice if we didn't have to know which rules to grab....
mkdir -p $tmpdir/lib/udev/rules.d
# ultimately, /lib/initramfs/rules.d or somesuch which includes links/copies
# of the rules we want so that we just copy those in would be best
mkdir -p $initdir/lib/udev/rules.d
for rule in /lib/udev/rules.d/40-redhat* /lib/udev/rules.d/50* /lib/udev/rules.d/60-persistent-storage.rules /lib/udev/rules.d/61*edd* /lib/udev/rules.d/64* /lib/udev/rules.d/80* /lib/udev/rules.d/95* rules.d/*.rules ; do
cp -v $rule $tmpdir/lib/udev/rules.d
cp $rule $initdir/lib/udev/rules.d
done

# terminfo bits make things work better if you fall into interactive mode
for f in $(find /lib/terminfo -type f) ; do cp -v --parents $f "$tmpdir" ; done
for f in $(find /lib/terminfo -type f) ; do cp --parents $f "$initdir" ; done

# install our files
cp -v init $tmpdir/init
cp -v switch_root $tmpdir/sbin/switch_root

# FIXME: and some directory structure
mkdir -p $tmpdir/etc $tmpdir/proc $tmpdir/sys $tmpdir/sysroot

# FIXME: module installation should be based on a couple of things
# a) the modules for the kernel we're building an initrd for
# b) config list
# c) installed packages
# but for now... everything wins!
if [ -d modules ]; then
mkdir -p $tmpdir/lib/modules
cp -r modules/* $tmpdir/lib/modules
rm -rf $tmpdir/lib/modules/*/kernel/drivers/video
cp init $initdir/init
cp switch_root $initdir/sbin/switch_root

# and create some directory structure
mkdir -p $initdir/etc $initdir/proc $initdir/sys $initdir/sysroot $initdir/dev/pts

# FIXME: hard-coded module list of doom.
[ -z "$modules" ] && modules="=ata =block =drm dm-crypt aes sha256_generic aes_i586 cbc essiv"

mkdir -p $initdir/lib/modules/$kernel
# expand out module deps, etc
for mod in $(resolveAndExpandModules $modules) ; do
installmodule $mod $initdir
done

/sbin/depmod -a -b $initdir $kernel
if [ $? -ne 0 ]; then
error "\"/sbin/depmod -a $kernel\" failed."
exit 1
fi

# plymouth
if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
/usr/libexec/plymouth/plymouth-populate-initrd -t "$tmpdir" || :
/usr/libexec/plymouth/plymouth-populate-initrd -t "$initdir" || :
fi

pushd $tmpdir >/dev/null
find . |cpio -H newc -o |gzip -9 > $INITRDOUT
pushd $initdir >/dev/null
find . |cpio -H newc -o |gzip -9 > $outfile
popd >/dev/null

2
init

@ -38,7 +38,7 @@ mknod /dev/tty1 c 4 1 @@ -38,7 +38,7 @@ mknod /dev/tty1 c 4 1

# start plymouth if it's available
# arguably we need some of udev run first for fbmods and above devnodes :/
[ -x /sbin/plymouthd ] && /sbin/plymouthd --attach-to-session
[ -x /bin/plymouthd ] && /bin/plymouthd --attach-to-session
[ -x /bin/plymouth ] && /bin/plymouth --show-splash



Loading…
Cancel
Save