logo

bootstrap-initrd

Linux initrd to bootstrap from a small binary seed git clone https://anongit.hacktivis.me/git/bootstrap-initrd.git/
commit: 0228db0a73c2ee2923371459de5a95ae9fdf905b
parent 3cfcae8287eb4b6d47fce9d642164011e2c37e17
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed, 24 Dec 2025 00:46:31 +0100

make-img.sh: Add

Diffstat:

Amake-img.sh49+++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+), 0 deletions(-)

diff --git a/make-img.sh b/make-img.sh @@ -0,0 +1,49 @@ +#!/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