-
Notifications
You must be signed in to change notification settings - Fork 13
/
mnt-initrd
executable file
·58 lines (49 loc) · 957 Bytes
/
mnt-initrd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
set -e
if [[ "$OSTYPE" != linux* ]]; then
echo "Not on a Linux box; aborting." >&2
exit 1
fi
if [[ `id -u` != 0 ]]; then
echo "Not root; aborting." >&2
exit 1
fi
if [[ $# != 1 ]]; then
echo "Usage: $0 <initrd image>"
echo " $0 <floppy image>"
exit 1
fi
if ! [[ -f $1 ]]; then
echo "$1 isn't a valid file; aborting." >&2
exit 1
fi
case "`file $1`" in
*SYSLINUX*)
echo "$1 is a floppy image" # e.g. bootnet.img
floppy=$1
floppy_base=${1##*/}
mnt-image $floppy
img=mnt:$floppy_base/initrd.img
imgbase=initrd.img
;;
*)
img=$1
imgbase=${img##*/}
;;
esac
tmpimg=/tmp/$imgbase
cp $img $tmpimg.gz
gunzip $tmpimg.gz
case "`file $tmpimg`" in
*cpio*)
echo "$tmpimg is a cpio archive"
mv $tmpimg $tmpimg.cpio
mkdir $tmpimg
cd $tmpimg
cpio -idv < $tmpimg.cpio
rm $tmpimg.cpio
echo "$img unpacked into $tmpimg"
exit 0
;;
esac
mnt-image $tmpimg