forked from arjuncr/acrlinux_x86_64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_x86_64.sh
executable file
·449 lines (363 loc) · 8.89 KB
/
build_x86_64.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
# @author ARJUN C R (arjuncr00@acrlinux.com)
#
# web site https://www.acrlinux.com
#
#!/bin/bash
init_build_env()
{
echo "init build env...."
export VERSION="1.0"
export SCRIPT_NAME="ACR LINUX BUILD SCRIPT"
export SCRIPT_VERSION="1.0"
export LINUX_NAME="acrlinux"
export DISTRIBUTION_VERSION="2021.1"
# BASE
export KERNEL_BRANCH="5.x"
export KERNEL_VERSION="5.6.14"
export BUSYBOX_VERSION="1.30.1"
export SYSLINUX_VERSION="6.03"
export BASEDIR=`realpath --no-symlinks $PWD`
export SOURCEDIR=${BASEDIR}/light-os
export ROOTFSDIR=${BASEDIR}/rootfs
export ISODIR=${BASEDIR}/iso
export TARGETDIR=${BASEDIR}/debian-target/rootfs_x86_64
export BASE_ROOTFS=${BASEDIR}/base-rootfs
export BUILD_OTHER_DIR="build_script_for_other"
export BOOT_SCRIPT_DIR="boot_script"
export NET_SCRIPT="network"
export CONFIG_ETC_DIR="${BASEDIR}/os-configs/etc"
export WORKSPACE="${BASEDIR}/workspace"
export BASE_SYSTEM=${BASEDIR}/acrlinux-bases-root/basesystem/
#cross compile
CROSS_COMPILE64=$BASEDIR/cross_gcc/x86_64-linux/bin/x86_64-linux-
ARCH64="x86_64"
CROSS_COMPILEi386=$BASEDIR/cross_gcc/i386-linux/bin/i386-linux-
ARCHi386="i386"
if [ "$2" == "64" ]
then
export ARCH=$ARCH64
export CROSS_COMPILE=$CROSS_COMPILE64
elif [ "$2" == "32" ]
then
export ARCH=$ARCHi386
export CROSS_COMPILE=$CROSS_COMPILEi386
else
export ARCH=$ARCH64
export CROSS_COMPILE=$CROSS_COMPILE64
fi
export ISO_FILENAME="acrlinux-${ARCH}-${VERSION}.iso"
#Dir and mode
export ETCDIR="etc"
export MODE="754"
export DIRMODE="755"
export CONFMODE="644"
#configs
export LIGHT_OS_KCONFIG="$BASEDIR/configs/kernel/light_os_kconfig"
export LIGHT_OS_BUSYBOX_CONFIG="$BASEDIR/configs/busybox/light_os_busybox_config"
#cflags
export CFLAGS=-m64
export CXXFLAGS=-m64
#setting JFLAG
if [ -z "$1" ]
then
export JFLAG=4
else
export JFLAG=$1
fi
}
prepare_dirs () {
cd ${BASEDIR}
if [ ! -d ${SOURCEDIR} ];
then
mkdir ${SOURCEDIR}
fi
if [ ! -d ${ROOTFSDIR} ];
then
mkdir ${ROOTFSDIR}
fi
if [ ! -d ${ISODIR} ];
then
mkdir ${ISODIR}
fi
if [ ! -d ${WORKSPACE} ];
then
mkdir ${WORKSPACE}
fi
}
build_kernel () {
cd ${SOURCEDIR}
if [ ! -d ${WORKSPACE}/linux-${KERNEL_VERSION} ];
then
echo "copying kernel src to workspace"
cp -r linux-${KERNEL_VERSION} ${WORKSPACE}
echo "copying kernel patch to workspace"
cp -r kernel-patch ${WORKSPACE}
cd ${WORKSPACE}/linux-${KERNEL_VERSION}
for patch in $(ls ../kernel-patch | grep '^[000-999]*_.*.patch'); do
echo "applying patch .... '$patch'."
patch -p1 < ../kernel-patch/${patch}
done
fi
cd ${WORKSPACE}/linux-${KERNEL_VERSION}
if [ "$1" == "-c" ]
then
make clean -j$JFLAG ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE
elif [ "$1" == "-b" ]
then
cp $LIGHT_OS_KCONFIG .config
echo "building $ARCH acrlinux kernel"
make oldconfig CROSS_COMPILE=$CROSS_COMPILE ARCH=$ARCH bzImage \
-j ${JFLAG}
cp arch/x86/boot/bzImage ${ISODIR}/vmlinuz-$KERNEL_VERSION-amd64
fi
}
build_busybox () {
cd ${SOURCEDIR}
if [ ! -d ${WORKSPACE}/busybox-${BUSYBOX_VERSION} ];
then
cp -r busybox-${BUSYBOX_VERSION} ${WORKSPACE}
echo "copying busybox patch to workspace"
cp -r busybox-patch ${WORKSPACE}
cd ${WORKSPACE}/busybox-${BUSYBOX_VERSION}
for patch in $(ls ../busybox-patch | grep '^[000-999]*_.*.patch'); do
echo "applying patch .... '$patch'."
patch -p1 < ../busybox-patch/${patch}
done
fi
cd ${WORKSPACE}/busybox-${BUSYBOX_VERSION}
if [ "$1" == "-c" ]
then
make -j$JFLAG ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE clean
elif [ "$1" == "-b" ]
then
cp $LIGHT_OS_BUSYBOX_CONFIG .config
echo "building $ARCH acrlinux busybox"
make -j$JFLAG ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE oldconfig
sed -i 's|.*CONFIG_STATIC.*|CONFIG_STATIC=y|' .config
make ARCH=$arm CROSS_COMPILE=$CROSS_COMPILE busybox \
-j ${JFLAG}
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE install \
-j ${JFLAG}
rm -rf ${ROOTFSDIR} && mkdir ${ROOTFSDIR}
cd _install
cp -R . ${ROOTFSDIR}
rm ${ROOTFSDIR}/linuxrc
fi
}
build_extras () {
#Build extra soft
cd ${BASEDIR}/${BUILD_OTHER_DIR}
if [ "$1" == "-c" ]
then
./build_other_main.sh --clean
elif [ "$1" == "-b" ]
then
./build_other_main.sh --build
fi
}
generate_rootfs () {
echo "generating rootfs..."
cd ${ROOTFSDIR}
cp -r ${BASE_SYSTEM}/* .
cp ${ISODIR}/vmlinuz-$KERNEL_VERSION-amd64 ${ROOTFSDIR}/
cd etc
cp $BASE_ROOTFS/etc/motd .
cp $BASE_ROOTFS/etc/hosts .
cp $BASE_ROOTFS/etc/fstab .
cp $BASE_ROOTFS/etc/mdev.conf .
cp $BASE_ROOTFS/etc/profile .
# install -m ${MODE} ${BASEDIR}/${BOOT_SCRIPT_DIR}/rc.d/startup rcS.d/startup
# install -m ${MODE} ${BASEDIR}/${BOOT_SCRIPT_DIR}/rc.d/shutdown init.d/shutdown
cp $BASE_ROOTFS/etc/inittab .
cd ${ROOTFSDIR}
#creating initial device node
mknod -m 622 dev/console c 5 1
mknod -m 666 dev/null c 1 3
mknod -m 666 dev/zero c 1 5
mknod -m 666 dev/ptmx c 5 2
mknod -m 666 dev/tty c 5 0
mknod -m 666 dev/tty1 c 4 1
mknod -m 666 dev/tty2 c 4 2
mknod -m 666 dev/tty3 c 4 3
mknod -m 666 dev/tty4 c 4 4
mknod -m 444 dev/random c 1 8
mknod -m 444 dev/urandom c 1 9
mknod -m 666 dev/ram b 1 1
mknod -m 666 dev/mem c 1 1
mknod -m 666 dev/kmem c 1 2
chown root:tty dev/{console,ptmx,tty,tty1,tty2,tty3,tty4}
}
generate_image () {
echo "generateting iso image..."
if [ -f ${BASEDIR}/image/${ISO_FILENAME} ]
then
rm ${BASEDIR}/image/${ISO_FILENAME}
fi
grub-mkrescue -o ${BASEDIR}/image/${ISO_FILENAME} ${ROOTFSDIR}
}
test_qemu () {
cd ${BASEDIR}
if [ -f ${BASEDIR}/image/${ISO_FILENAME} ];
then
qemu-system-x86_64 -m 128M -cdrom ${BASEDIR}/image/${ISO_FILENAME} -boot d -vga std
fi
}
clean_files () {
rm -rf ${SOURCEDIR}
rm -rf ${ROOTFSDIR}
rm -rf ${ISODIR}
rm -rf ${WORKSPACE}
}
init_work_dir()
{
prepare_dirs
}
clean_work_dir()
{
clean_files
}
build_all()
{
build_kernel -b
# build_busybox -b
build_extras -b
}
rebuild_all()
{
clean_all
build_all
}
clean_all()
{
build_kernel -c
# build_busybox -c
build_extras -c
}
wipe_rebuild()
{
clean_work_dir
init_work_dir
rebuild_all
}
build_img ()
{
build_all
generate_rootfs
generate_image
}
help_msg()
{
echo -e "###################################################################################################\n"
echo -e "#####################################Utility-${SCRIPT_VERSION} to Build x86_64 OS####################################\n"
echo -e "###################################################################################################\n"
echo -e "Help message --help\n"
echo -e "Build and create iso: --build-img\n"
echo -e "Build All: --build-all\n"
echo -e "Rebuild All: --rebuild-all\n"
echo -e "Clean All: --clean-all\n"
echo -e "Wipe and rebuild --wipe-rebuild\n"
echo -e "Building kernel: --build-kernel --rebuild-kernel --clean-kernel\n"
#echo -e "Building busybx: --build-busybox --rebuild-busybox --clean-busybox\n"
echo -e "Building other soft: --build-other --rebuild-other --clean-other\n"
echo -e "Creating root-fs: --create-rootfs\n"
echo -e "Create ISO Image: --create-img\n"
echo -e "Cleaning work dir: --clean-work-dir\n"
echo -e "Test with Qemu --Run-qemu\n"
echo "######################################################################################################"
}
option()
{
if [ -z "$1" ]
then
help_msg
exit 1
fi
if [ "$1" == "--build-all" ]
then
build_all
fi
if [ "$1" == "--rebuild-all" ]
then
rebuild_all
fi
if [ "$1" == "--clean-all" ]
then
clean_all
fi
if [ "$1" == "--wipe-rebuild" ]
then
wipe_rebuild
fi
if [ "$1" == "--build-kernel" ]
then
build_kernel -b
elif [ "$1" == "--rebuild-kernel" ]
then
build_kernel -c
build_kernel -b
elif [ "$1" == "--clean-kernel" ]
then
build_kernel -c
fi
if [ "$1" == "--build-busybox" ]
then
build_busybox -b
elif [ "$1" == "--rebuild-busybox" ]
then
build_busybox -c
build_busybox -b
elif [ "$1" == "--clean-busybox" ]
then
build_busybox -c
fi
if [ "$1" == "--build-uboot" ]
then
build_uboot -b
elif [ "$1" == "--rebuild-uboot" ]
then
build_uboot -c
build_uboot -b
elif [ "$1" == "--clean-uboot" ]
then
build_uboot -c
fi
if [ "$1" == "--build-other" ]
then
build_extras -b
elif [ "$1" == "--rebuild-other" ]
then
build_extras -c
build_extras -b
elif [ "$1" == "--clean-other" ]
then
build_extras -c
fi
if [ "$1" == "--create-rootfs" ]
then
generate_rootfs
fi
if [ "$1" == "--create-img" ]
then
generate_image
fi
if [ "$1" == "--clean-work-dir" ]
then
clean_work_dir
fi
if [ "$1" == "--Run-qemu" ]
then
test_qemu
fi
if [ "$1" == "--build-img" ]
then
build_img
fi
}
main()
{
init_build_env $2 $3
init_work_dir
option $1
}
#starting of script
main $1 $2 $3