make-img.sh (1445B)
- #!/bin/sh
- set -ex -o pipefail || exit 1
- SYSLINUX=/usr/share/syslinux
- KERNEL=/mnt/alpine/boot/vmlinuz-lts
- INITRD=bootstrap-initrd/x86_64+extras.cpio.gz
- ALPINE_ARCH=x86_64 ./make-initrd.sh
- FAT_PARTSZ=$(wc -c "$INITRD" "$KERNEL" | grep total | cut -f1 -d' ')
- # Add 25% for inodes, syslinux, …
- FAT_PARTSZ="$(printf '%s 1.25 * 512 / 512 * p\n' "${FAT_PARTSZ}" | dc)"
- rm -f bootstrap-initrd/x86_64.fat
- truncate -s "${FAT_PARTSZ}" bootstrap-initrd/x86_64.fat
- # FAT16 because otherwise syslinux throws an error:
- # + syslinux -i bootstrap-initrd/x86_64.fat
- # syslinux: zero FAT sectors (FAT12/16)
- mkfs.fat -D 0x80 -F16 bootstrap-initrd/x86_64.fat
- mcopy -i bootstrap-initrd/x86_64.fat "$KERNEL" ::vmlinuz
- mcopy -i bootstrap-initrd/x86_64.fat "$INITRD" ::x86_64.cpio.gz
- cat >bootstrap-initrd/x86_64.syslinux.cfg <<'EOF'
- DEFAULT linux
- LABEL linux
- KERNEL vmlinuz
- INITRD x86_64.cpio.gz
- EOF
- mcopy -i bootstrap-initrd/x86_64.fat bootstrap-initrd/x86_64.syslinux.cfg ::syslinux.cfg
- syslinux -i bootstrap-initrd/x86_64.fat
- mdir -i bootstrap-initrd/x86_64.fat -a
- rm -f bootstrap-initrd/x86_64.img
- truncate -s "$((2048 + ${FAT_PARTSZ}))" bootstrap-initrd/x86_64.img
- sfdisk bootstrap-initrd/x86_64.img <<'EOF'
- label: mbr
- start=2048, size=+, type=0x06, bootable
- EOF
- dd if="${SYSLINUX}/mbr.bin" conv=notrunc of=bootstrap-initrd/x86_64.img
- dd if=bootstrap-initrd/x86_64.fat conv=notrunc of=bootstrap-initrd/x86_64.img seek=2048 status=progress