]> git.ipfire.org Git - thirdparty/dracut.git/blob - dracut
c974fb49f0032332c8cffa895bc22b7ec51d8d6e
[thirdparty/dracut.git] / dracut
1 #!/bin/bash
2 #
3 # Generator script for a dracut initramfs
4 # Tries to retain some degree of compatibility with the command line
5 # of the various mkinitrd implementations out there
6 #
7 # Copyright 2008, Red Hat, Inc. Jeremy Katz <katzj@redhat.com>
8 # GPLv2 header here
9
10 [ -f /etc/dracut.conf ] && . /etc/dracut.conf
11
12 while [ $# -gt 0 ]; do
13 case $1 in
14 -f|--force)
15 force=yes
16 shift
17 ;;
18 -h|--help)
19 echo "Usage: $0 [-f] <initramfs> <kernel-version>"
20 exit 1
21 ;;
22 -v|--verbose)
23 set -x
24 shift
25 ;;
26 -l|--local)
27 allowlocal="yes"
28 shift
29 ;;
30 --allow-missing)
31 shift
32 ;;
33 *)
34 break
35 esac
36 done
37
38 if [ -n "$2" ]; then
39 kernel=$2
40 else
41 kernel=$(uname -r)
42 fi
43 if [ -n "$1" ]; then
44 outfile=$(readlink -f $1)
45 else
46 outfile="/boot/initrd-$kernel.img"
47 fi
48
49 if [ -f "$outfile" -a -z "$force" ]; then
50 echo "Will not override existing initramfs ($outfile) without --force"
51 exit 1
52 fi
53
54 if [ -n "$allowlocal" -a -f ./init ]; then
55 source ./dracut-functions
56 initfile=./init
57 switchroot=./switch_root
58 rulesdir=./rules.d
59 else
60 source /usr/libexec/dracut/functions
61 initfile=/usr/libexec/dracut/init
62 switchroot=/usr/libexec/dracut/switch_root
63 rulesdir=/usr/libexec/dracut/rules.d
64 fi
65
66 initdir=$(mktemp -d -t initramfs.XXXXXX)
67
68 # executables that we have to have
69 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"
70 lvmexe="/sbin/lvm"
71 cryptexe="/sbin/cryptsetup"
72 # and some things that are nice for debugging
73 debugexe="/bin/ls /bin/cat /bin/ln /bin/ps /bin/grep /bin/more"
74 # udev things we care about
75 udevexe="/lib/udev/vol_id"
76
77 # install base files
78 for binary in $exe $debugexe $udevexe $lvmexe $cryptexe ; do
79 inst $binary $initdir
80 done
81
82 # FIXME: would be nice if we didn't have to know which rules to grab....
83 # ultimately, /lib/initramfs/rules.d or somesuch which includes links/copies
84 # of the rules we want so that we just copy those in would be best
85 mkdir -p $initdir/lib/udev/rules.d
86 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* $rulesdir/*.rules ; do
87 cp $rule $initdir/lib/udev/rules.d
88 done
89
90 # terminfo bits make things work better if you fall into interactive mode
91 for f in $(find /lib/terminfo -type f) ; do cp --parents $f "$initdir" ; done
92
93 # install our files
94 cp $initfile $initdir/init
95 cp $switchroot $initdir/sbin/switch_root
96
97 # and create some directory structure
98 mkdir -p $initdir/etc $initdir/proc $initdir/sys $initdir/sysroot $initdir/dev/pts
99
100 # FIXME: hard-coded module list of doom.
101 [ -z "$modules" ] && modules="=ata =block =drm dm-crypt aes sha256_generic aes_i586 cbc essiv"
102
103 mkdir -p $initdir/lib/modules/$kernel
104 # expand out module deps, etc
105 for mod in $(resolveAndExpandModules $modules) ; do
106 installmodule $mod $initdir
107 done
108
109 /sbin/depmod -a -b $initdir $kernel
110 if [ $? -ne 0 ]; then
111 error "\"/sbin/depmod -a $kernel\" failed."
112 exit 1
113 fi
114
115 # plymouth
116 if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
117 /usr/libexec/plymouth/plymouth-populate-initrd -t "$initdir" || :
118 fi
119
120 pushd $initdir >/dev/null
121 find . |cpio -H newc -o |gzip -9 > $outfile
122 popd >/dev/null