-
Notifications
You must be signed in to change notification settings - Fork 7
/
make_chroot_initrd
executable file
·59 lines (48 loc) · 1.63 KB
/
make_chroot_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
59
#!/bin/bash
usage()
{
echo "Usage: make_chroot_initrd [-o initrd.chroot] current_initrd"
echo " Make new initrd image supporting chroot= boot parameter from existing image."
echo " New image is written to 'current_initrd.chroot' unless -o is specified (no need to run as root then)."
echo " Supported Systems: debian, ubuntu and derivatives."
exit 1
}
die() { echo -e "make_chroot_initrd: $@"; exit 1; }
out=""
if [ "$1" = "-o" ]; then
shift; out="$1"; shift
fi
# create temp dir
cwd=`pwd`
tmp="/tmp/make_chroot_initrd"
rm -rf "$tmp" 2>/dev/null
mkdir $tmp || die "can't create dir $tmp"
# check input file
initrd="$1"
[ -f "$initrd" ] || usage
file "$initrd" | grep -q 'gzip compressed data' || die "expecting a gzipped initrd"
[ -z "$out" ] && out="${initrd}.chroot"
# script home dir
# script_dir=`pwd`
cd `dirname "$0"`; script_dir=`pwd`; cd - >/dev/null
[ -f "$script_dir/initrd.patch" ] || die "initrd.patch is missing"
echo "making new initrd: $out"
cp "$initrd" "$tmp/initrd.gz"
cd $tmp || die "can't access $tmp"
echo "extracting"
gunzip initrd.gz || die "gunzip failed"
mkdir tmp; cd tmp
cpio --quiet -i < ../initrd || die "cpio failed"
echo "patching"
patch --silent --dry-run -p1 < "$script_dir/initrd.patch" >/dev/null && \
patch --silent -p1 < "$script_dir/initrd.patch" || \
patch --silent -p1 < "$script_dir/initrd_1604.patch" || die "patch failed !"
rm *.orig */*.orig 2>/dev/null
echo "packing"
find . | cpio --quiet -o --format='newc' > ../initrd
cd ..
gzip initrd
cd "$cwd" || die "cd $cwd failed"
cp $tmp/initrd.gz "$out" || die "now run \n sudo cp $tmp/initrd.gz $out"
rm -rf $tmp
echo "done !"