-
Notifications
You must be signed in to change notification settings - Fork 10
/
build-iso
executable file
·100 lines (84 loc) · 2.83 KB
/
build-iso
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
#!/bin/bash
set -eu
echo ">>> Build env:"
env
# Some variables are assumed to be set by build/run args to docker:
# DEB_SUITE
# DEB_MIRROR
# BUILD_DIR
# OUTPUT_DIR
# ISO_NAME
# SOURCE_DIR
# The repo is assumed to be mounted in the container at SOURCE_DIR
mkdir -p ${BUILD_DIR}/{chroot,iso/live,scratch}
echo ">>> Creating chroot"
debootstrap --include="$(cat ${SOURCE_DIR}/install-packages.txt | tr '\n' ',')" --variant=minbase ${DEB_SUITE} ${BUILD_DIR}/chroot ${DEB_MIRROR}
echo ">>> Configuring chroot"
# Apply the overlay
# Copy the files from the overlay directory into the corresponding location in the chroot, merging with the existing files/dirs
echo ">>> Applying overlay"
rsync --verbose --archive --ignore-existing --one-file-system --chown root:root --exclude README.md ${SOURCE_DIR}/overlay/ ${BUILD_DIR}/chroot/
# Run the hooks
rsync --archive --one-file-system --quiet ${SOURCE_DIR}/hooks ${BUILD_DIR}/chroot/
for hook in $(find ${BUILD_DIR}/chroot/hooks -maxdepth 1 -executable -type f | sort); do
echo ">>> Executing configure hook ${hook}"
(
export DEBIAN_FRONTEND=noninteractive
chroot ${BUILD_DIR}/chroot hooks/$(basename ${hook})
)
done
rm -rf ${BUILD_DIR}/chroot/hooks
# Create squashfs
echo ">>> Creating squashfs"
mksquashfs \
${BUILD_DIR}/chroot \
${BUILD_DIR}/iso/live/filesystem.squashfs \
-e boot
ls -lh ${BUILD_DIR}/iso/live/filesystem.squashfs
# Get the kernel and initrd
cp ${BUILD_DIR}/chroot/boot/vmlinuz-* \
${BUILD_DIR}/iso/vmlinuz
cp ${BUILD_DIR}/chroot/boot/initrd.img-* \
${BUILD_DIR}/iso/initrd
# Create a grub image
echo ">>> Configuring grub"
cat <<'EOF' >${BUILD_DIR}/scratch/grub.cfg
search --set=root --file /DEBIAN_CUSTOM
insmod all_video
set default="0"
set timeout=5
menuentry "Docker Live" {
linux /vmlinuz boot=live quiet nomodeset
initrd /initrd
}
EOF
touch ${BUILD_DIR}/iso/DEBIAN_CUSTOM
grub-mkstandalone \
--format=i386-pc \
--output=${BUILD_DIR}/scratch/core.img \
--install-modules="linux normal iso9660 biosdisk memdisk search tar ls" \
--modules="linux normal iso9660 biosdisk search" \
--locales="" \
--fonts="" \
"boot/grub/grub.cfg=${BUILD_DIR}/scratch/grub.cfg"
cat /usr/lib/grub/i386-pc/cdboot.img ${BUILD_DIR}/scratch/core.img > ${BUILD_DIR}/scratch/bios.img
# Create the ISO
echo ">>> Creating ISO"
set -x
xorriso \
-as mkisofs \
-iso-level 3 \
-full-iso9660-filenames \
-volid "DEBIAN_CUSTOM" \
--grub2-boot-info \
--grub2-mbr /usr/lib/grub/i386-pc/boot_hybrid.img \
-eltorito-boot \
boot/grub/bios.img \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
--eltorito-catalog boot/grub/boot.cat \
-output "${OUTPUT_DIR}/${ISO_NAME}" \
-graft-points \
"${BUILD_DIR}/iso" \
/boot/grub/bios.img=${BUILD_DIR}/scratch/bios.img