Advertisement
LittleFox94

grub2-mkfloppy

Jun 11th, 2021 (edited)
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.93 KB | None | 0 0
  1. #!/bin/sh -eu
  2. # find this at github, too: https://gist.github.com/LittleFox94/b3796794aa90f79828a2febed005d469
  3.  
  4. keeptemporary=""
  5. outfile="floppy.img"
  6. modules=""
  7. modules_default="biosdisk part_msdos fat multiboot configfile ls cat help"
  8.  
  9. help() {
  10.     cat <<EOF
  11. Usage: $0 -o outfile.img -m vbe -m multiboot
  12.  
  13. OPTIONS
  14.     -h  Show help (this help you are reading right now)
  15.     -o  Set output file
  16.     -m  Add a module, if given, only the given modules (and their dependencies
  17.         are added, otherwise a default set of modules is installed)
  18.     -k  Keep temporary files
  19.  
  20. DEFAULT MODULES
  21.     $modules_default
  22.  
  23. Be gay, do crime
  24. EOF
  25. }
  26.  
  27. while getopts ko:m:h arg; do
  28.     case $arg in
  29.         o)
  30.             outfile=$OPTARG
  31.             ;;
  32.         m)
  33.             modules="$modules $OPTARG"
  34.             ;;
  35.         k)
  36.             keeptemporary=blacklivesmatter # we just need any string
  37.             ;;
  38.         *|h)
  39.             help
  40.             exit 0
  41.             ;;
  42.     esac
  43. done
  44.  
  45. if [ -z "$modules" ]; then
  46.     modules="$modules_default"
  47. fi
  48.  
  49. outdir="$(dirname "$outfile")"
  50. grub_img="$outdir/$(basename "$outfile" .img)-grub.img"
  51.  
  52. grub-mkimage -p /grub -C auto -O i386-pc -o "$grub_img" $modules
  53. size=$(ls --block-size=512 -s "$grub_img" | sed 's/\s.*$//')
  54.  
  55. dd if=/dev/zero of="$outfile" bs=512 count=2880
  56. dd if=/usr/lib/grub/i386-pc/boot.img of="$outfile" conv=notrunc
  57. dd if="$grub_img" of="$outfile" conv=notrunc seek=1
  58.  
  59. mformat -i "$outfile" -kR $(($size + 2))
  60. mmd -i "$outfile" grub
  61.  
  62. foxfile=$(mktemp -p "$outdir" README.foxXXXX)
  63. cat >"$foxfile" <<EOF
  64. Image built with grub2-mkfloppy. Be gay, do crimes, be you, be happy
  65.     (not all required, your choice)
  66.  
  67. Modules included: $modules
  68.  
  69. For help query LittleFox on libera/#osdev
  70. For comments about this being political, go talk to a tree.
  71. EOF
  72.  
  73. mcopy -i "$outfile" "$foxfile" ::/README.fox
  74.  
  75. if [ -z "$keeptemporary" ]; then
  76.     rm "$grub_img" "$foxfile"
  77. fi
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement