2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 # Copyright 2009 Red Hat, Inc. All rights reserved.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 echo "Warning: $@" >&2
27 [[ $beverbose ]] && echo "$@" >&2
35 # 80x25 linebreak here ^
37 Usage: $0 [OPTION]... <initramfs> <base image> [<image>...]
38 Creates initial ramdisk image by concatenating several images from the command
39 line and /boot/dracut/
41 -f, --force Overwrite existing initramfs file.
42 -i, --imagedir Directory with additional images to add
43 (default: /boot/dracut/)
44 -o, --overlaydir Overlay directory, which contains files that
45 will be used to create an additional image
46 --nooverlay Do not use the overlay directory
47 --noimagedir Do not use the additional image directory
48 -h, --help This message
49 --debug Output debug information of the build process
50 -v, --verbose Verbose output during the build process
55 imagedir
=/boot
/dracut
/
56 overlay
=/var
/lib
/dracut
/overlay
60 -f|
--force) force
=yes;;
61 -i|
--imagedir) imagedir
=$2;shift;;
62 -o|
--overlaydir) overlay
=$2;shift;;
63 --nooverlay) no_overlay
=yes;shift;;
64 --noimagedir) no_imagedir
=yes;shift;;
65 -h|
--help) usage
; exit 1 ;;
66 --debug) debug
="yes";;
67 -v|
--verbose) beverbose
="yes";;
68 -*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage
; exit 1;;
76 if [[ -z $outfile ]]; then
77 derror
"No output file specified."
84 if [[ -z $baseimage ]]; then
85 derror
"No base image specified."
90 if [[ -f $outfile && ! $force ]]; then
91 derror
"Will not override existing initramfs ($outfile) without --force"
95 if [[ ! $no_imagedir && ! -d $imagedir ]]; then
96 derror
"Image directory $overlay is not a directory"
100 if [[ ! $no_overlay && ! -d $overlay ]]; then
101 derror
"Overlay $overlay is not a directory"
105 if [[ ! $no_overlay ]]; then
106 ofile
="$imagedir/90-overlay.img"
107 dinfo
"Creating image $ofile from directory $overlay"
108 type pigz
&>/dev
/null
&& gzip=pigz ||
gzip=gzip
109 ( cd "$overlay"; find . |
cpio --quiet -H newc
-o |
$gzip -9 > "$ofile"; )
112 if [[ ! $no_imagedir ]]; then
113 for i
in "$imagedir/"*.img
; do
114 [[ -f $i ]] && images
+=("$i")
120 dinfo
"Using base image $baseimage"
121 cat "$baseimage" > "$outfile"
123 for i
in "${images[@]}"; do
125 cat "$i" >> "$outfile"
128 dinfo
"Created $outfile"