Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh -eu
- # find this at github, too: https://gist.github.com/LittleFox94/b3796794aa90f79828a2febed005d469
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement