logo

bootstrap-initrd

Linux initrd to bootstrap from a small binary seed git clone https://anongit.hacktivis.me/git/bootstrap-initrd.git/

make-img.sh (1445B)


  1. #!/bin/sh
  2. set -ex -o pipefail || exit 1
  3. SYSLINUX=/usr/share/syslinux
  4. KERNEL=/mnt/alpine/boot/vmlinuz-lts
  5. INITRD=bootstrap-initrd/x86_64+extras.cpio.gz
  6. ALPINE_ARCH=x86_64 ./make-initrd.sh
  7. FAT_PARTSZ=$(wc -c "$INITRD" "$KERNEL" | grep total | cut -f1 -d' ')
  8. # Add 25% for inodes, syslinux, …
  9. FAT_PARTSZ="$(printf '%s 1.25 * 512 / 512 * p\n' "${FAT_PARTSZ}" | dc)"
  10. rm -f bootstrap-initrd/x86_64.fat
  11. truncate -s "${FAT_PARTSZ}" bootstrap-initrd/x86_64.fat
  12. # FAT16 because otherwise syslinux throws an error:
  13. # + syslinux -i bootstrap-initrd/x86_64.fat
  14. # syslinux: zero FAT sectors (FAT12/16)
  15. mkfs.fat -D 0x80 -F16 bootstrap-initrd/x86_64.fat
  16. mcopy -i bootstrap-initrd/x86_64.fat "$KERNEL" ::vmlinuz
  17. mcopy -i bootstrap-initrd/x86_64.fat "$INITRD" ::x86_64.cpio.gz
  18. cat >bootstrap-initrd/x86_64.syslinux.cfg <<'EOF'
  19. DEFAULT linux
  20. LABEL linux
  21. KERNEL vmlinuz
  22. INITRD x86_64.cpio.gz
  23. EOF
  24. mcopy -i bootstrap-initrd/x86_64.fat bootstrap-initrd/x86_64.syslinux.cfg ::syslinux.cfg
  25. syslinux -i bootstrap-initrd/x86_64.fat
  26. mdir -i bootstrap-initrd/x86_64.fat -a
  27. rm -f bootstrap-initrd/x86_64.img
  28. truncate -s "$((2048 + ${FAT_PARTSZ}))" bootstrap-initrd/x86_64.img
  29. sfdisk bootstrap-initrd/x86_64.img <<'EOF'
  30. label: mbr
  31. start=2048, size=+, type=0x06, bootable
  32. EOF
  33. dd if="${SYSLINUX}/mbr.bin" conv=notrunc of=bootstrap-initrd/x86_64.img
  34. dd if=bootstrap-initrd/x86_64.fat conv=notrunc of=bootstrap-initrd/x86_64.img seek=2048 status=progress