-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·67 lines (49 loc) · 1.4 KB
/
entrypoint.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
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-2.0
# Fail on Error !
set -e
export VIRTUAL_DISK=/tmp/disk.img
# container build ready - attach to interactive bash
if [ -f "/.buildready" ]; then
# just start bash
/bin/bash
exit 0
else
touch /.buildready
fi
# create mount point
mkdir -p /mnt/
# Create sparse file to represent our disk
truncate --size 512M $VIRTUAL_DISK
# Create partition layout
# set "Legacy BIOS bootable flag" for boot parition (tag required by gptmbr.bin)
sgdisk --clear \
--new 1::+10M --typecode=1:8300 --change-name=1:'boot' --attributes=1:set:2 \
--new 2::-0 --typecode=2:8300 --change-name=2:'conf' \
${VIRTUAL_DISK}
# show layout
gdisk -l ${VIRTUAL_DISK}
# show additional attributes
sgdisk ${VIRTUAL_DISK} --attributes=1:show
# add mbr code
dd bs=440 count=1 conv=notrunc if=/usr/lib/EXTLINUX/gptmbr.bin of=${VIRTUAL_DISK}
# mount disk
LOOPDEV=$(losetup --find --show --partscan ${VIRTUAL_DISK})
# create filesystems
mkfs.ext2 ${LOOPDEV}p1
mkfs.ext4 ${LOOPDEV}p2
# mount boot partition
mkdir -p /mnt/boot
mount ${LOOPDEV}p1 /mnt/boot
# create extlinux dir
mkdir -p /mnt/boot/extlinux
# initialize extlinux (stage2 volume boot record + files)
extlinux --install /mnt/boot/extlinux
# copy config files, ipxe
cp -R /opt/. /mnt/boot/extlinux
# unmount
sync && umount /mnt/boot
# detach loop device
losetup --detach $LOOPDEV
# compress image
gzip ${VIRTUAL_DISK}