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"; set -x;;
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;;
62 # if we were not passed a config file, try the default one
63 [[ ! -f $conffile ]] && conffile
="/etc/dracut.conf"
65 # source our config file
66 [[ -f $conffile ]] && .
"$conffile"
68 # these options override the stuff in the config file
69 [[ $dracutmodules_l ]] && dracutmodules
=$dracutmodules_l
70 [[ $omit_dracutmodules_l ]] && omit_dracutmodules
=$omit_dracutmodules_l
71 [[ $drivers_l ]] && drivers
=$drivers_l
73 [[ $allowlocal && -f "$(dirname $0)/dracut-functions" ]] && dsrc
="$(dirname $0)" || dsrc
=/usr
/lib
/dracut
75 if [[ -f $dsrc/dracut-functions
]]; then
76 .
$dsrc/dracut-functions
78 echo "Cannot find $dsrc/dracut-functions. Are you running from a git checkout?"
79 echo "Try passing -l as an argument to $0"
83 dracutfunctions
=$dsrc/dracut-functions
84 export dracutfunctions
86 # This is kinda legacy -- eventually it should go away.
87 case $dracutmodules in
88 ""|auto
) dracutmodules
="all" ;;
91 [[ $2 ]] && kernel
=$2 || kernel
=$
(uname
-r)
92 [[ $1 ]] && outfile
=$
(readlink
-f $1) || outfile
="/boot/initrd-$kernel.img"
94 if [[ -f $outfile && ! $force ]]; then
95 echo "Will not override existing initramfs ($outfile) without --force"
99 hookdirs
="pre-udev pre-mount pre-pivot mount emergency"
101 readonly initdir
=$
(mktemp
-d -t initramfs.XXXXXX
)
102 trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
104 # Need to be able to have non-root users read stuff (rpcbind etc)
107 export initdir hookdirs dsrc dracutmodules drivers debug beverbose
109 # Create some directory structure first
110 for d
in bin sbin usr
/bin usr
/sbin usr
/lib etc proc sys sysroot tmp dev
/pts var
/run
; do
111 mkdir
-p "$initdir/$d";
114 # check all our modules to see if they should be sourced.
115 # This builds a list of modules that we will install next.
119 for moddir
in "$dsrc/modules.d"/[0-9][0-9]*; do
120 mod
=${moddir##*/}; mod
=${mod#[0-9][0-9]}
121 if strstr
"$mods_to_load" " $mod "; then
123 mods_to_load
=${mods_to_load// $mod /}
129 ## final stuff that has to happen
131 # generate module dependencies for the initrd
132 if ! /sbin
/depmod
-a -b "$initdir" $kernel; then
133 echo "\"/sbin/depmod -a $kernel\" failed."
137 # make sure that library links are correct and up to date
138 ldconfig
-n -r "$initdir" /lib
* /usr
/lib
*
140 if [[ $include_src && $include_target ]]; then
141 mkdir
-p "$initdir$include_target"
142 cp -a -t "$initdir$include_target" "$include_src"/*
145 for item
in $install_items; do
146 dracut_install
"$item"
150 [[ "$beverbose" = "yes" ]] && (du
-c "$initdir" |
sort -n)
152 ( cd "$initdir"; find . |
cpio -H newc
-o |
gzip -9 > "$outfile"; )
154 [[ "$beverbose" = "yes" ]] && ls -lh "$outfile"