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 @@
#/bin/bash #/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 # Generator script for a dracut initramfs
# of the sort. the important thing is working # 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

[ -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


source /usr/libexec/initrd-functions 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


INITRDOUT=$1 if [ -f "$outfile" -a -z "$force" ]; then
if [ -z "$INITRDOUT" ]; then echo "Will not override existing initramfs ($outfile) without --force"
echo "Please specify an initrd file to output"
exit 1 exit 1
fi fi


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


# executables that we have to have # 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" 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" lvmexe="/sbin/lvm"
cryptexe="/sbin/cryptsetup" cryptexe="/sbin/cryptsetup"
# and some things that are nice for debugging # 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 # udev things we care about
udevexe="/lib/udev/vol_id" udevexe="/lib/udev/vol_id"


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


# FIXME: would be nice if we didn't have to know which rules to grab.... # 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 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 done


# terminfo bits make things work better if you fall into interactive mode # 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 # install our files
cp -v init $tmpdir/init cp init $initdir/init
cp -v switch_root $tmpdir/sbin/switch_root cp switch_root $initdir/sbin/switch_root


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


# FIXME: module installation should be based on a couple of things # FIXME: hard-coded module list of doom.
# a) the modules for the kernel we're building an initrd for [ -z "$modules" ] && modules="=ata =block =drm dm-crypt aes sha256_generic aes_i586 cbc essiv"
# b) config list
# c) installed packages mkdir -p $initdir/lib/modules/$kernel
# but for now... everything wins! # expand out module deps, etc
if [ -d modules ]; then for mod in $(resolveAndExpandModules $modules) ; do
mkdir -p $tmpdir/lib/modules installmodule $mod $initdir
cp -r modules/* $tmpdir/lib/modules done
rm -rf $tmpdir/lib/modules/*/kernel/drivers/video
/sbin/depmod -a -b $initdir $kernel
if [ $? -ne 0 ]; then
error "\"/sbin/depmod -a $kernel\" failed."
exit 1
fi fi


# plymouth # plymouth
if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then 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 fi


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

2
init

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


# start plymouth if it's available # start plymouth if it's available
# arguably we need some of udev run first for fbmods and above devnodes :/ # 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 [ -x /bin/plymouth ] && /bin/plymouth --show-splash





Loading…
Cancel
Save