forked from aweeraman/kernel-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mk-initrd
executable file
·88 lines (79 loc) · 1.81 KB
/
mk-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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
#
# SPDX-FileCopyrightText: 2020 Anuradha Weeraman <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later
set -e
basedir=$(dirname $(readlink -f $0))
. ${basedir}/config/env.sh
check_availability_of() {
prog=$1
if ! command -v ${prog} 2>&1 > /dev/null; then
echo "$prog not found"
exit 1
fi
}
recreate_initrd_dir() {
if [ -e "${initrd}" ]; then
echo -n "Deleting existing initrd... "
rm -rf ${initrd}
rm -f ${basedir}/initramfs.cpio.gz
echo "ok."
fi
echo -n "Creating initrd directory structure... "
mkdir ${initrd} && cd ${initrd}
mkdir -p bin sbin dev etc proc sys usr/bin usr/sbin
cp ${confdir}/init ${initrd}/init
chmod a+x ${initrd}/init
echo "ok"
}
build_and_install_busybox() {
if [ ! -e ${busyboxdir} ]; then
echo -n "Cloning busybox... "
mkdir -p ${busyboxdir}
(
cd ${depsdir}
git clone --depth 1 --branch ${busybox_tag} \
[email protected]:mirror/busybox.git >> ${basedir}/log 2>&1
if [ $? -ne 0 ]; then
echo "failed."
else
echo "ok."
fi
)
fi
cp ${confdir}/busybox.config ${busyboxdir}/.config
(
cd ${busyboxdir}
echo -n "Building busybox... "
make -j${procs} >> ${basedir}/log 2>&1
if [ $? -ne 0 ]; then
echo "failed."
exit 1
else
echo "ok."
fi
echo -n "Installing busybox... "
make CONFIG_PREFIX=${initrd} install >> ${basedir}/log 2>&1
if [ $? -ne 0 ]; then
echo "failed."
exit 1
else
echo "ok."
fi
)
}
check_availability_of git
check_availability_of make
recreate_initrd_dir
build_and_install_busybox
echo "Building initrd... "
(
cd ${initrd}
$(find . | cpio -oHnewc | gzip > ${basedir}/initramfs.cpio.gz) >> ${basedir}/log 2>&1
if [ $? -ne 0 ]; then
echo "failed."
exit 1
else
echo "ok."
fi
)