forked from ivandavidov/minimal-linux-script
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·277 lines (238 loc) · 5.08 KB
/
build.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/bin/sh
set -ex
KERNEL_VERSION=4.17.3
MUSL_VERSION=1.1.19
BUSYBOX_VERSION=1.28.4
DROPBEAR_VERSION=2018.76
SYSLINUX_VERSION=6.03
IPTABLES_VERSION=1.6.2
DOCKER_VERSION=18.03.1-ce
build=/build
rootfs=$build/rootfs/
isoimage=$build/isoimage/
debug() { echo "Dropping into a shell for debugging ..."; /bin/sh; }
config() {
if grep "CONFIG_$2" .config; then
sed -i "s|.*CONFIG_$2.*|CONFIG_$2=$1|" .config
else
echo "CONFIG_$2=$1" >> .config
fi
}
download_syslinux() {
wget -q -O syslinux.tar.xz \
http://kernel.org/pub/linux/utils/boot/syslinux/syslinux-$SYSLINUX_VERSION.tar.xz
tar -xf syslinux.tar.xz
}
download_kernel() {
wget -q -O kernel.tar.xz \
http://kernel.org/pub/linux/kernel/v4.x/linux-$KERNEL_VERSION.tar.xz
tar -xf kernel.tar.xz
}
download_musl() {
wget -q -O musl.tar.gz \
http://www.musl-libc.org/releases/musl-$MUSL_VERSION.tar.gz
tar -xf musl.tar.gz
}
download_busybox() {
wget -q -O busybox.tar.bz2 \
http://busybox.net/downloads/busybox-$BUSYBOX_VERSION.tar.bz2
tar -xf busybox.tar.bz2
}
download_dropbear() {
wget -q -O dropbear.tar.bz2 \
https://matt.ucc.asn.au/dropbear/dropbear-$DROPBEAR_VERSION.tar.bz2
tar -xf dropbear.tar.bz2
}
download_iptables() {
wget -q -O iptables.tar.bz2 \
https://netfilter.org/projects/iptables/files/iptables-$IPTABLES_VERSION.tar.bz2
tar -xf iptables.tar.bz2
}
download_docker() {
wget -O docker.tgz \
https://download.docker.com/linux/static/stable/x86_64/docker-$DOCKER_VERSION.tgz
tar -xf docker.tgz
}
build_musl() {
(
cd musl-$MUSL_VERSION
./configure \
--prefix=/usr
make
make DESTDIR=$rootfs install
)
}
build_busybox() {
(
cd busybox-$BUSYBOX_VERSION
make distclean defconfig
config y STATIC
config n INCLUDE_SUSv2
config y INSTALL_NO_USR
config "\"$rootfs\"" PREFIX
config y FEATURE_EDITING_VI
config y TUNE2FS
config n BOOTCHARTD
config n INIT
config n LINUXRC
config y FEATURE_GPT_LABEL
config n LPD
config n LPR
config n LPQ
config n RUNSV
config n RUNSVDIR
config n SV
config n SVC
config n SVLOGD
config n HUSH
config n CHAT
config n CONSPY
config n RUNLEVEL
config n PIPE_PROGRESS
config n RUN_PARTS
config n START_STOP_DAEMON
yes "" | make oldconfig
make busybox install
)
}
build_dropbear() {
(
cd dropbear-$DROPBEAR_VERSION
./configure \
--prefix=/usr \
--mandir=/usr/man \
--enable-static \
--disable-zlib \
--disable-wtmp \
--disable-syslog
make PROGRAMS="dropbear dbclient dropbearkey scp" strip
make DESTDIR=$rootfs PROGRAMS="dropbear dbclient dropbearkey scp" install
ln -sf /usr/bin/dbclient $rootfs/usr/bin/ssh
)
}
build_iptables() {
(
cd iptables-$IPTABLES_VERSION
./configure \
--prefix=/usr \
--enable-libipq \
--disable-nftables \
--enable-static
make
make DESTDIR=$rootfs install
)
}
install_docker() {
mv docker/* $rootfs/usr/bin/
}
build_rootfs() {
(
cd rootfs
find . | cpio -R root:root -H newc -o | gzip > ../rootfs.gz
)
}
sync_rootfs() {
(
mkdir rootfs.old
cd rootfs.old
zcat $build/rootfs.gz | cpio -idm
rsync -aru . $rootfs
)
}
build_kernel() {
(
cd linux-$KERNEL_VERSION
make mrproper defconfig kvmconfig
# Basic Config
config y BLK_DEV_INITRD
config y IKCONFIG
config y IKCONFIG_PROC
config y DEVTMPFS
config minimal DEFAULT_HOSTNAME
# Docker Basics
config y NAMESPACES
config y NET_NS
config y PID_NS
config y IPC_NS
config y UTS_NS
config y CGROUPS
config y CGROUP_CPUACCT
config y CGROUP_DEVICE
config y CGROUP_FREEZER
config y CGROUP_SCHED
config y CPUSETS
config y MEMCG
config y KEYS
config y VETH
config y BRIDGE
config y BRIDGE_NETFILTER
config y NF_NAT_IPV4
config y IP_NF_FILTER
config y IP_NF_TARGET_MASQUERADE
config y NETFILTER_XT_MATCH_ADDRTYPE
config y NETFILTER_XT_MATCH_CONNTRACK
config y NETFILTER_XT_MATCH_IPVS
config y IP_NF_NAT
config y NF_NAT
config y NF_NAT_NEEDED
config y POSIX_MQUEUE
config y DEVPTS_MULTIPLE_INSTANCES
# Docker Storage
config y BLK_DEV_DM
config y DM_THIN_PROVISIONING
config y OVERLAY_FS
yes "" | make oldconfig
make bzImage
cp arch/x86/boot/bzImage ../kernel.gz
)
}
build_iso() {
test -d "$isoimage" || mkdir "$isoimage"
cp rootfs.gz "$isoimage"
cp kernel.gz "$isoimage"
cp syslinux-$SYSLINUX_VERSION/bios/core/isolinux.bin "$isoimage"
cp syslinux-$SYSLINUX_VERSION/bios/com32/elflink/ldlinux/ldlinux.c32 "$isoimage"
echo 'default kernel.gz initrd=rootfs.gz append quiet' > "$isoimage/isolinux.cfg"
(
cd "$isoimage"
xorriso \
-as mkisofs \
-o ../minimal.iso \
-b isolinux.bin \
-c boot.cat \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
./
)
}
build_all() {
download_musl
build_musl
download_busybox
build_busybox
download_dropbear
build_dropbear
download_iptables
build_iptables
download_docker
install_docker
download_kernel
build_kernel
build_rootfs
build_iso
}
repack() {
download_syslinux
sync_rootfs
build_rootfs
build_iso
}
case "${1}" in
repack)
repack
;;
*)
build_all
;;
esac