-
Notifications
You must be signed in to change notification settings - Fork 0
/
init
76 lines (66 loc) · 2.05 KB
/
init
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
#!/bin/sh
# Parse kernel command-line arguments
for param in $(cat /proc/cmdline); do
case $param in
kernel_url=*)
kernel_url="${param#kernel_url=}"
;;
initrd_url=*)
initrd_url="${param#initrd_url=}"
;;
kernel_sha=*)
kernel_sha="${param#kernel_sha=}"
;;
initrd_sha=*)
initrd_sha="${param#initrd_sha=}"
;;
next_kernel_params=*)
next_kernel_params="${param#next_kernel_params=}"
;;
esac
done
# Default values if not provided
kernel_url=${kernel_url:-"https://default.example.com/kernel"}
initrd_url=${initrd_url:-"https://default.example.com/initrd.img"}
kernel_sha=${kernel_sha:-""}
initrd_sha=${initrd_sha:-""}
next_kernel_params=${next_kernel_params:-"console=ttyS0"}
echo "Kernel URL: $kernel_url"
echo "Initrd URL: $initrd_url"
echo "Kernel SHA: $kernel_sha"
echo "Initrd SHA: $initrd_sha"
echo "Next Kernel Params: $next_kernel_params"
# Mount required filesystems
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev
# Set up networking (assumes DHCP)
busybox udhcpc -i eth0
# Download the kernel and initrd using aria2
aria2c --enable-dht --enable-peer-exchange \
--bt-seed-unverified=true \
--dir=/tmp \
--out=kernel "$kernel_url"
aria2c --enable-dht --enable-peer-exchange \
--bt-seed-unverified=true \
--dir=/tmp \
--out=initrd.img "$initrd_url"
# Verify SHA256 hashes if provided
if [ -n "$kernel_sha" ]; then
echo "$kernel_sha /tmp/kernel" | sha256sum -c -
if [ $? -ne 0 ]; then
echo "Kernel SHA256 verification failed!"
exit 1
fi
fi
if [ -n "$initrd_sha" ]; then
echo "$initrd_sha /tmp/initrd.img" | sha256sum -c -
if [ $? -ne 0 ]; then
echo "Initrd SHA256 verification failed!"
exit 1
fi
fi
echo "SHA256 verification passed for both kernel and initrd."
# Boot the downloaded kernel and initrd
kexec -l /tmp/kernel --initrd=/tmp/initrd.img --append="$next_kernel_params"
kexec -e