]> git.ipfire.org Git - thirdparty/dracut.git/blame - dracut
[PATCH 47/50] Split out the various things we load into their own modules.
[thirdparty/dracut.git] / dracut
CommitLineData
c0815e4e 1#!/bin/bash
641cc356
JK
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#
70c26b7f 7
641cc356
JK
8# Copyright 2008, Red Hat, Inc. Jeremy Katz <katzj@redhat.com>
9# GPLv2 header here
ec9315e5 10
f4fff04e 11
641cc356
JK
12[ -f /etc/dracut.conf ] && . /etc/dracut.conf
13
b368a5f3 14while (($# > 0)); do
641cc356 15 case $1 in
b368a5f3 16 -f|--force) force=yes;;
f4fff04e 17 -m|--modules) dracutmodules="$2"; shift;;
b368a5f3
VL
18 -h|--help) echo "Usage: $0 [-f] <initramfs> <kernel-version>"
19 exit 1 ;;
20 -v|--verbose) set -x;;
21 -l|--local) allowlocal="yes" ;;
22 --allow-missing) : ;;
23 *) break ;;
641cc356 24 esac
b368a5f3 25 shift
641cc356 26done
f4fff04e 27[[ $dracutmodules ]] || dracutmodules="all"
ec9315e5 28
c8937ec4 29[[ $2 ]] && kernel=$2 || kernel=$(uname -r)
95994c57 30[[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img"
ec9315e5 31
c8937ec4 32if [[ -f $outfile && ! $force ]]; then
641cc356 33 echo "Will not override existing initramfs ($outfile) without --force"
ec9315e5
JK
34 exit 1
35fi
36
f9d7779e
VL
37[[ $allowlocal && -f ./init ]] && dsrc="." || dsrc=/usr/libexec/dracut
38. $dsrc/dracut-functions
39initfile=$dsrc/init
40switchroot=$dsrc/switch_root
41rulesdir=$dsrc/rules.d
4b3f76db 42hookdirs="pre-udev pre-mount pre-pivot"
5c481d34 43
641cc356 44initdir=$(mktemp -d -t initramfs.XXXXXX)
2c6fc388 45trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
ec9315e5 46
f4fff04e
VL
47export initdir hookdirs rulesdir dsrc dracutmodules kmodules
48
0f86847d
VL
49# Create some directory structure first
50for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot dev/pts; do
51 mkdir -p "$initdir/$d";
52done
53
15136762
VL
54# source any third-party package provided modules
55for f in "$dsrc/modules"/*; do
56 [[ -x $f ]] && . "$f"
57done
aabc0553 58
0f86847d 59## final stuff that has to happen
bc6b0dec 60
0f86847d 61# generate module dependencies for the initrd
3c3e1e0c 62/sbin/depmod -a -b "$initdir" $kernel || {
641cc356
JK
63 error "\"/sbin/depmod -a $kernel\" failed."
64 exit 1
3c3e1e0c 65}
ec9315e5 66
0f86847d
VL
67# make sure that library links are correct and up to date
68ldconfig -r "$initdir"
69
3c3e1e0c 70( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )