]> git.ipfire.org Git - thirdparty/dracut.git/blame - dracut
Some minor formatting fixups in the main dracut script
[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
b368a5f3 11while (($# > 0)); do
641cc356 12 case $1 in
b368a5f3 13 -f|--force) force=yes;;
f4fff04e 14 -m|--modules) dracutmodules="$2"; shift;;
b368a5f3
VL
15 -h|--help) echo "Usage: $0 [-f] <initramfs> <kernel-version>"
16 exit 1 ;;
17 -v|--verbose) set -x;;
18 -l|--local) allowlocal="yes" ;;
19 --allow-missing) : ;;
20 *) break ;;
641cc356 21 esac
b368a5f3 22 shift
641cc356 23done
9a8a00cf
VL
24conffile="/etc/dracut.conf"
25[[ $allowlocal && -f dracut.conf ]] && conffile="dracut.conf"
26. "$conffile"
27
28[[ $allowlocal && -f dracut-functions ]] && dsrc="." || dsrc=/usr/lib/dracut
29. $dsrc/dracut-functions
30
f4fff04e 31[[ $dracutmodules ]] || dracutmodules="all"
ec9315e5 32
c8937ec4 33[[ $2 ]] && kernel=$2 || kernel=$(uname -r)
95994c57 34[[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img"
ec9315e5 35
c8937ec4 36if [[ -f $outfile && ! $force ]]; then
641cc356 37 echo "Will not override existing initramfs ($outfile) without --force"
ec9315e5
JK
38 exit 1
39fi
40
49c68fa4
VL
41hookdirs="pre-udev pre-mount pre-pivot mount"
42
43readonly initdir=$(mktemp -d -t initramfs.XXXXXX)
2c6fc388 44trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
ec9315e5 45
49c68fa4 46export initdir hookdirs dsrc dracutmodules modules
f4fff04e 47
0f86847d
VL
48# Create some directory structure first
49for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot dev/pts; do
50 mkdir -p "$initdir/$d";
51done
52
f04dc5f3 53# source all our modules
20abd914
VL
54for moddir in "$dsrc/modules.d"/*; do
55 [[ -d $moddir || -L $moddir ]] || continue
56 mod=${moddir##*/}; mod=${mod#[0-9][0-9]};
743c38d8
HH
57 if [[ $dracutmodules = all ]] || strstr "$dracutmodules " "$mod "; then
58 echo "== Module $moddir == "
20abd914 59 [[ -x $moddir/install ]] && . "$moddir/install"
f04dc5f3 60 fi
15136762 61done
20abd914 62unset moddir
aabc0553 63
0f86847d 64## final stuff that has to happen
bc6b0dec 65
0f86847d 66# generate module dependencies for the initrd
3c3e1e0c 67/sbin/depmod -a -b "$initdir" $kernel || {
3f746592 68 echo "\"/sbin/depmod -a $kernel\" failed."
641cc356 69 exit 1
3c3e1e0c 70}
ec9315e5 71
0f86847d 72# make sure that library links are correct and up to date
7702658f 73ldconfig -n -r "$initdir" /lib* /usr/lib*
0f86847d 74
3c3e1e0c 75( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )