You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
4.8 KiB
176 lines
4.8 KiB
#!/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 <katzj@redhat.com> |
|
# GPLv2 header here |
|
|
|
[ -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 |
|
;; |
|
-l|--local) |
|
allowlocal="yes" |
|
shift |
|
;; |
|
--allow-missing) |
|
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 |
|
|
|
if [ -f "$outfile" -a -z "$force" ]; then |
|
echo "Will not override existing initramfs ($outfile) without --force" |
|
exit 1 |
|
fi |
|
|
|
if [ -n "$allowlocal" -a -f ./init ]; then |
|
source ./dracut-functions |
|
initfile=./init |
|
switchroot=./switch_root |
|
rulesdir=./rules.d |
|
else |
|
source /usr/libexec/dracut/functions |
|
initfile=/usr/libexec/dracut/init |
|
switchroot=/usr/libexec/dracut/switch_root |
|
rulesdir=/usr/libexec/dracut/rules.d |
|
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 /usr/sbin/chroot" |
|
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 /bin/more" |
|
# udev things we care about |
|
udevexe="/lib/udev/vol_id /lib/udev/console_init" |
|
|
|
# install base files |
|
for binary in $exe $debugexe $udevexe $lvmexe $cryptexe ; do |
|
inst $binary $initdir |
|
done |
|
|
|
# FIXME: would be nice if we didn't have to know which rules to grab.... |
|
# 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/10-console* /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* $rulesdir/*.rules ; do |
|
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 --parents $f "$initdir" ; done |
|
|
|
# FIXME: i18n stuff isn't really distro-independent :/ |
|
if [ -f /etc/sysconfig/keyboard ] || [ -f /etc/sysconfig/console/default.kmap ]; then |
|
if [ -f /etc/sysconfig/console/default.kmap ]; then |
|
KEYMAP=/etc/sysconfig/console/default.kmap |
|
else |
|
. /etc/sysconfig/keyboard |
|
if [ -n "$KEYTABLE" -a -d "/lib/kbd/keymaps" ]; then |
|
KEYMAP="$KEYTABLE.map" |
|
fi |
|
fi |
|
if [ -n "$KEYMAP" ]; then |
|
[ -f /etc/sysconfig/keyboard ] && inst /etc/sysconfig/keyboard "$initdir" |
|
inst /bin/loadkeys "$initdir" |
|
findkeymap $KEYMAP |
|
|
|
for FN in $KEYMAPS; do |
|
inst $FN "$initdir" |
|
case "$FN" in |
|
*.gz) |
|
gzip -d "$initdir$FN" |
|
;; |
|
*.bz2) |
|
bzip2 -d "$initdir$FN" |
|
;; |
|
esac |
|
done |
|
fi |
|
fi |
|
|
|
if [ -f /etc/sysconfig/i18n ]; then |
|
. /etc/sysconfig/i18n |
|
inst /etc/sysconfig/i18n "$initdir" |
|
[ -z "$SYSFONT" ] && SYSFONT=latarcyrheb-sun16 |
|
inst /bin/setfont "$initdir" |
|
|
|
for FN in /lib/kbd/consolefonts/$SYSFONT.* ; do |
|
inst $FN "$initdir" |
|
case "$FN" in |
|
*.gz) |
|
gzip -d "$MNTIMAGE$FN" |
|
;; |
|
*.bz2) |
|
bzip2 -d "$MNTIMAGE$FN" |
|
;; |
|
esac |
|
done |
|
if [ -n "$SYSFONTACM" ]; then |
|
inst /lib/kbd/consoletrans/$SYSFONTACM "$initdir" |
|
fi |
|
if [ -n "$UNIMAP" ]; then |
|
inst /lib/kbd/unimaps/$UNIMAP "$initdir" |
|
fi |
|
fi |
|
|
|
# install our files |
|
cp $initfile $initdir/init |
|
cp $switchroot $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 cbc" |
|
|
|
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 "$initdir" || : |
|
fi |
|
|
|
pushd $initdir >/dev/null |
|
find . |cpio -H newc -o |gzip -9 > $outfile |
|
popd >/dev/null
|
|
|