GNU Linux-libre 4.9.337-gnu1
[releases.git] / tools / testing / selftests / rcutorture / bin / mkinitrd.sh
1 #!/bin/bash
2 #
3 # Create an initrd directory if one does not already exist.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, you can access it online at
17 # http://www.gnu.org/licenses/gpl-2.0.html.
18 #
19 # Copyright (C) IBM Corporation, 2013
20 #
21 # Author: Connor Shu <Connor.Shu@ibm.com>
22
23 D=tools/testing/selftests/rcutorture
24
25 # Prerequisite checks
26 [ -z "$D" ] && echo >&2 "No argument supplied" && exit 1
27 if [ ! -d "$D" ]; then
28     echo >&2 "$D does not exist: Malformed kernel source tree?"
29     exit 1
30 fi
31 if [ -d "$D/initrd" ]; then
32     echo "$D/initrd already exists, no need to create it"
33     exit 0
34 fi
35
36 T=${TMPDIR-/tmp}/mkinitrd.sh.$$
37 trap 'rm -rf $T' 0 2
38 mkdir $T
39
40 cat > $T/init << '__EOF___'
41 #!/bin/sh
42 while :
43 do
44         sleep 1000000
45 done
46 __EOF___
47
48 # Try using dracut to create initrd
49 command -v dracut >/dev/null 2>&1 || { echo >&2 "Dracut not installed"; exit 1; }
50 echo Creating $D/initrd using dracut.
51
52 # Filesystem creation
53 dracut --force --no-hostonly --no-hostonly-cmdline --module "base" $T/initramfs.img
54 cd $D
55 mkdir initrd
56 cd initrd
57 zcat $T/initramfs.img | cpio -id
58 cp $T/init init
59 echo Done creating $D/initrd using dracut
60 exit 0