-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-minimal.sh
87 lines (71 loc) · 2.77 KB
/
build-minimal.sh
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
#!/bin/bash
# Define variables for the Linux kernel version and BusyBox version
LINUX_KERNEL_VERSION="5.14.6"
BUSYBOX_VERSION="1.34.1"
# Extract the major kernel version (e.g., "5" from "5.14.6")
KERNEL_MAJOR=$(echo $LINUX_KERNEL_VERSION | cut -d '.' -f 1)
# Create the src directory and the subdirectories for kernel and busybox
SRC_DIR="src"
KERNEL_DIR="${SRC_DIR}/linux-${LINUX_KERNEL_VERSION}"
BUSYBOX_DIR="${SRC_DIR}/busybox-${BUSYBOX_VERSION}"
# Construct the URLs
KERNEL_URL="https://mirrors.edge.kernel.org/pub/linux/kernel/v${KERNEL_MAJOR}.x/linux-${LINUX_KERNEL_VERSION}.tar.xz"
BUSYBOX_URL="https://www.busybox.net/downloads/busybox-${BUSYBOX_VERSION}.tar.bz2"
WORKSPACE_DIRS=("initrd/bin" "initrd/sbin" "initrd/dev" "initrd/dev/pts" "initrd/tmp" "initrd/proc" "initrd/sys")
mkdir initrd
mkdir -p $SRC_DIR
cd $SRC_DIR
if [ ! -d "linux-$LINUX_KERNEL_VERSION" ]; then #linux-$LINUX_KERNEL_VERSION does not exists
wget $KERNEL_URL
tar -xf linux-$LINUX_KERNEL_VERSION.tar.xz
cd linux-$LINUX_KERNEL_VERSION
make defconfig
make -j$(nproc) || exit
cd ..
fi
# wget $BUSYBOX_URL
# tar -xf busybox-$BUSYBOX_VERSION.tar.bz2
# cd busybox-$BUSYBOX_VERSION
# make defconfig
# sed 's/^.*CONFIG_STATIC[^_].*$/CONFIG_STATIC=y/g' -i .config
# # sed -i "s|.*CONFIG_STATIC.*|CONFIG_STATIC=y|" .config # this also works
# make CC=musl-gcc -j$(nproc) busybox
# cd ..
if [ ! -d "busybox-$BUSYBOX_VERSION" ]; then #busybox-$BUSYBOX_VERSION does not exists
wget $BUSYBOX_URL
tar -xf busybox-$BUSYBOX_VERSION.tar.bz2
cd busybox-$BUSYBOX_VERSION
make defconfig
sed -i "s|.*CONFIG_STATIC.*|CONFIG_STATIC=y|" .config
make -j$(nproc)
make CONFIG_PREFIX=../../initrd -j$(nproc) install
cd ..
fi
cd ..
cp $KERNEL_DIR/arch/x86/boot/bzImage ./
for DIR in "${WORKSPACE_DIRS[@]}"; do
mkdir -p $DIR
done
cd initrd
# cd bin
# cd ../../$BUSYBOX_DIR/busybox ./
# for cmd in $(./busybox --list); do
# ln -s /bin/busybox ./$cmd;
# done
# cd ..
########## GENERATE INIT FILE ##########
echo '#!/bin/sh' > init
echo 'mount -t sysfs sysfs /sys' >> init
echo 'mount -t proc proc /proc' >> init
echo 'mount -t tmpfs none /tmp -o mode=1777' >> init
echo 'mount -t devtmpfs udev /dev' >> init
echo 'mount -t devpts none /dev/pts' >> init
echo 'sysctl -w kernel.printk="2 4 1 7"' >> init
echo 'clear' >> init
echo 'echo -e "Welcome to \\e[34mWave \\e[32mLinux \\e[31mLive\\e[0m (/init)"' >> init
echo '/bin/sh' >> init
echo 'poweroff -f' >> init
########## GENERATE INIT FILE ##########
chmod -R 777 .
find . | cpio -o -H newc > ../initrd.img
cd ..