-
Notifications
You must be signed in to change notification settings - Fork 2
/
029-build-rootfs.sh
executable file
·106 lines (84 loc) · 1.86 KB
/
029-build-rootfs.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
######################################################
# 2.1. BUILD BUSYBOX
######################################################
ROOTFS=${PWD}/rootfs
DROPBEAR_BUILD=${PWD}/build/dropbear
BUSYBOX_SRC=${PWD}/busybox
BUSYBOX_CONFIG=${PWD}/configs/busybox.config
KERNEL=${PWD}/build/linux/arch/x86_64/boot/bzImage
export KBUILD_OUTPUT=${PWD}/build/busybox
cd $BUSYBOX_SRC
make mrproper
rm -rf $KBUILD_OUTPUT
mkdir -p $KBUILD_OUTPUT/_install
make defconfig
cp $BUSYBOX_CONFIG $KBUILD_OUTPUT/.config
make -j `nproc`
make -j `nproc` install
#####################################################
# 2.2. GENERATE ROOT FILESYSTEM
####################################################
cd $KBUILD_OUTPUT/_install
mkdir dev
mkdir etc
mkdir proc
mkdir root
mkdir src
mkdir sys
mkdir tmp
mkdir -p var/run
chmod 1777 tmp
# cat > init.c << EOF
#
# int _start()
# {
# for(;;)
# {
# asm volatile("pause");
# }
#
# return 0;
# }
#
# EOF
#gcc -o init -ffreestanding -nostdlib -nostdinc -no-pie init.c
cat > etc/bootscript.sh << EOF
#!/bin/sh
dmesg -n 7
mount -t devtmpfs none /dev
mount -t proc none /proc
mount -t sysfs none /sys
mount -o remount,rw /dev/root
sysctl -w kernel.core_pattern=core.%e.%p
sysctl -w kernel.core_pipe_limit=1
ulimit -c unlimited
ulimit -a
EOF
chmod +x etc/bootscript.sh
cat > etc/welcome.txt << EOF
Welcome to The No Name Linux!
EOF
cat > etc/inittab << EOF
::sysinit:/etc/bootscript.sh
::restart:/sbin/init
::ctrlaltdel:/sbin/reboot
::once:cat /etc/welcome.txt
::respawn:/bin/cttyhack /bin/sh
tty2::once:cat /etc/welcome.txt
tty2::respawn:/bin/sh
tty3::once:cat /etc/welcome.txt
tty3::respawn:/bin/sh
tty4::once:cat /etc/welcome.txt
tty4::respawn:/bin/sh
EOF
cat > etc/group << EOF
root:!:0:root
EOF
cat > etc/passwd << EOF
root::0:0::/root:/bin/sh
EOF
# Copy to the target dir
rm -rf ${ROOTFS}
mkdir ${ROOTFS}
cp -r ./* ${ROOTFS}