-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·91 lines (69 loc) · 2.37 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
#!/bin/bash
# https://gist.github.com/extremecoders-re/3ddddce9416fc8b293198cd13891b68c
#--------------------------------------------
# Require these packages.
echo "========================================================"
echo "sudo apt install qemu-system-mips qemu-utils"
sudo apt install qemu-system-mips qemu-utils -y
#--------------------------------------------
# Enable qcow mounter.
sudo modprobe nbd max_part=8
#--------------------------------------------
# Create staging directories.
if [ ! -d artifacts ]; then
mkdir artifacts
fi
if [ ! -d stage ]; then
mkdir stage
fi
if [ ! -d mnt ]; then
mkdir mnt
fi
#--------------------------------------------
# Download debian image.
cd artifacts
# Check if the Debian ISO file exists in the current directory; if not, download it.
if [ ! -f debian-*.iso ]; then
DEBISO=$(curl -s https://cdimage.debian.org/debian-cd/current/mipsel/iso-cd/SHA256SUMS | grep "debian" | awk '{print $2}')
wget http://cdimage.debian.org/cdimage/release/current/mipsel/iso-cd/$DEBISO
fi
cd ..
#--------------------------------------------
# Extract installer kernel image and root filesystem image.
sudo mount -r -t iso9660 artifacts/debian-*.iso mnt/
cp mnt/install/malta/netboot/vmlinuz* artifacts/vmlinuz-netinst
cp mnt/install/malta/netboot/initrd* artifacts/initrd-netinst.gz
sudo umount mnt/
#--------------------------------------------
# Create hard disk image.
cd stage
rm -f hda.qcow
qemu-img create -f qcow2 hda.qcow 16G
#--------------------------------------------
# Install debian.
qemu-system-mipsel \
-M malta \
-m 1024 \
-cdrom ../artifacts/debian-*.iso \
-hda hda.qcow \
-kernel ../artifacts/vmlinuz-netinst \
-initrd ../artifacts/initrd-netinst.gz \
-boot d \
-nographic \
-no-reboot \
-append "root=/dev/sda1 nokaslr" \
-netdev user,id=net0 \
-device e1000,netdev=net0,id=net0,mac=52:54:00:12:34:56
cd ..
#--------------------------------------------
# Extract bootable kernel image and root filesystem image.
echo "========================================================"
echo "sudo qemu-nbd --connect=/dev/nbd0 stage/hda.qcow"
sudo qemu-nbd --connect=/dev/nbd0 `pwd`/stage/hda.qcow
sudo mount -r /dev/nbd0p1 `pwd`/mnt
cp mnt/boot/vmlinuz* stage/vmlinuz
cp mnt/boot/initrd* stage/initrd.img
sudo umount /dev/nbd0p1
sudo qemu-nbd --disconnect /dev/nbd0
#--------------------------------------------
echo "Done."