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
8 # Copyright 2008, Red Hat, Inc. Jeremy Katz <katzj@redhat.com>
13 # 80x25 linebreak here ^
14 echo "Usage: $0 [OPTION]... <initramfs> <kernel-version>
15 Creates initial ramdisk images for preloading modules
17 -f, --force Overwrite existing initramfs file.
18 -m, --modules [LIST] Specify a space-separated list of dracut modules to
19 call when building the initramfs. Modules are located
20 in /usr/lib/dracut/modules.d.
21 -o, --omit [LIST] Omit a space-separated list of dracut modules.
22 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
23 include in the initramfs.
24 -h, --help This message
25 --debug Output debug information of the build process
26 -v, --verbose Verbose output during the build process
27 -c, --conf [FILE] Specify configuration file to use.
28 Default: /etc/dracut.conf
29 -l, --local Local mode. Use modules from the current working
30 directory instead of the system-wide installed in
31 /usr/lib/dracut/modules.d.
32 Useful when running dracut from a git checkout.
33 -H, --hostonly Host-Only mode: Install only what is needed for
34 booting the local host instead of a generic host.
35 -i, --include [SOURCE] [TARGET]
36 Include the files in the SOURCE directory into the
37 Target directory in the final initramfs.
38 -I, --install [LIST] Install the space separated list of files into the
45 -f|
--force) force
=yes;;
46 -m|
--modules) dracutmodules_l
="$2"; shift;;
47 -o|
--omit) omit_dracutmodules_l
="$2"; shift;;
48 -d|
--drivers) drivers_l
="$2"; shift;;
49 -h|
--help) usage
; exit 1 ;;
50 --debug) debug
="yes";;
51 -v|
--verbose) beverbose
="yes";;
52 -c|
--conf) conffile
="$2"; shift;;
53 -l|
--local) allowlocal
="yes" ;;
54 -H|
--hostonly) hostonly
="-h" ;;
55 -i|
--include) include_src
="$2"; include_target
="$3"; shift 2;;
56 -I|
--install) install_items
="$2"; shift;;
63 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
67 # if we were not passed a config file, try the default one
68 [[ ! -f $conffile ]] && conffile
="/etc/dracut.conf"
70 # source our config file
71 [[ -f $conffile ]] && .
"$conffile"
73 # these options override the stuff in the config file
74 [[ $dracutmodules_l ]] && dracutmodules
=$dracutmodules_l
75 [[ $omit_dracutmodules_l ]] && omit_dracutmodules
=$omit_dracutmodules_l
76 [[ $drivers_l ]] && drivers
=$drivers_l
77 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
79 [[ $allowlocal && -f "$(dirname $0)/dracut-functions" ]] && dsrc
="$(dirname $0)" || dsrc
=$dracutbasedir
81 if [[ -f $dsrc/dracut-functions
]]; then
82 .
$dsrc/dracut-functions
84 echo "Cannot find $dsrc/dracut-functions. Are you running from a git checkout?"
85 echo "Try passing -l as an argument to $0"
89 dracutfunctions
=$dsrc/dracut-functions
90 export dracutfunctions
92 # This is kinda legacy -- eventually it should go away.
93 case $dracutmodules in
94 ""|auto
) dracutmodules
="all" ;;
97 [[ $2 ]] && kernel
=$2 || kernel
=$
(uname
-r)
98 [[ $1 ]] && outfile
=$
(readlink
-f $1) || outfile
="/boot/initrd-$kernel.img"
100 if [[ -f $outfile && ! $force ]]; then
101 echo "Will not override existing initramfs ($outfile) without --force"
105 hookdirs
="cmdline pre-udev pre-trigger netroot pre-mount pre-pivot mount emergency"
107 readonly initdir
=$
(mktemp
-d -t initramfs.XXXXXX
)
108 trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
110 # Need to be able to have non-root users read stuff (rpcbind etc)
113 export initdir hookdirs dsrc dracutmodules drivers debug beverbose
115 # Create some directory structure first
116 for d
in bin sbin usr
/bin usr
/sbin usr
/lib etc proc sys sysroot tmp dev
/pts var
/run
; do
117 mkdir
-p "$initdir/$d";
120 # check all our modules to see if they should be sourced.
121 # This builds a list of modules that we will install next.
125 for moddir
in "$dsrc/modules.d"/[0-9][0-9]*; do
126 mod
=${moddir##*/}; mod
=${mod#[0-9][0-9]}
127 if strstr
"$mods_to_load" " $mod "; then
129 mods_to_load
=${mods_to_load// $mod /}
135 ## final stuff that has to happen
137 # generate module dependencies for the initrd
138 if ! /sbin
/depmod
-a -b "$initdir" $kernel; then
139 echo "\"/sbin/depmod -a $kernel\" failed."
143 # make sure that library links are correct and up to date
144 ldconfig
-n -r "$initdir" /lib
* /usr
/lib
*
146 if [[ $include_src && $include_target ]]; then
147 mkdir
-p "$initdir$include_target"
148 cp -a -t "$initdir$include_target" "$include_src"/*
151 for item
in $install_items; do
152 dracut_install
"$item"
156 [[ "$beverbose" = "yes" ]] && (du
-c "$initdir" |
sort -n)
158 ( cd "$initdir"; find . |
cpio -H newc
-o |
gzip -9 > "$outfile"; )
160 [[ "$beverbose" = "yes" ]] && ls -lh "$outfile"