Created
June 11, 2021 22:41
-
-
Save LittleFox94/b3796794aa90f79828a2febed005d469 to your computer and use it in GitHub Desktop.
Create grub2 floppy images with ease - opinionated, paths for debian-installed grub hard-coded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -eu | |
keeptemporary="" | |
outfile="floppy.img" | |
modules="" | |
modules_default="biosdisk part_msdos fat multiboot configfile ls cat help" | |
help() { | |
cat <<EOF | |
Usage: $0 -o outfile.img -m vbe -m multiboot | |
OPTIONS | |
-h Show help (this help you are reading right now) | |
-o Set output file | |
-m Add a module, if given, only the given modules (and their dependencies | |
are added, otherwise a default set of modules is installed) | |
-k Keep temporary files | |
DEFAULT MODULES | |
$modules_default | |
Be gay, do crime | |
EOF | |
} | |
while getopts ko:m:h arg; do | |
case $arg in | |
o) | |
outfile=$OPTARG | |
;; | |
m) | |
modules="$modules $OPTARG" | |
;; | |
k) | |
keeptemporary=blacklivesmatter # we just need any string | |
;; | |
*|h) | |
help | |
exit 0 | |
;; | |
esac | |
done | |
if [ -z "$modules" ]; then | |
modules="$modules_default" | |
fi | |
outdir="$(dirname "$outfile")" | |
grub_img="$outdir/$(basename "$outfile" .img)-grub.img" | |
grub-mkimage -p /grub -C auto -O i386-pc -o "$grub_img" $modules | |
size=$(ls --block-size=512 -s "$grub_img" | sed 's/\s.*$//') | |
dd if=/dev/zero of="$outfile" bs=512 count=2880 | |
dd if=/usr/lib/grub/i386-pc/boot.img of="$outfile" conv=notrunc | |
dd if="$grub_img" of="$outfile" conv=notrunc seek=1 | |
mformat -i "$outfile" -kR $(($size + 2)) | |
mmd -i "$outfile" grub | |
foxfile=$(mktemp -p "$outdir" README.foxXXXX) | |
cat >"$foxfile" <<EOF | |
Image built with grub2-mkfloppy. Be gay, do crimes, be you, be happy | |
(not all required, your choice) | |
Modules included: $modules | |
For help query LittleFox on libera/#osdev | |
For comments about this being political, go talk to a tree. | |
EOF | |
mcopy -i "$outfile" "$foxfile" ::/README.fox | |
if [ -z "$keeptemporary" ]; then | |
rm "$grub_img" "$foxfile" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment