parted -s "${diskpath}" mklabel gpt
parted -s "${diskpath}" mkpart primary 1MiB 2MiB
parted -s "${diskpath}" set 1 bios_grub on
parted -s "${diskpath}" mkpart primary 2Mib 202MiB
parted -s "${diskpath}" set 2 esp on
sleep 1
mkfs.fat -F 32 -n "boot" "${diskpath}2"
mount "/dev/disk/by-label/boot" "/boot"
grub-install --target=i386-pc "${diskpath}"
grub-install --target=x86_64-efi --efi-directory=/boot --removable --no-uefi-secure-boot
grub-mkconfig > "/boot/grub/grub.cfg"
This makes two partitions, one for GRUB to inject legacy BIOS boot code into and one for the ESP. ESP gets mounted to /boot, grub gets setup to support both. Only bug is Debian complains about symlinking .bak files for initrd, no biggie.(This is part of a larger Debian imaging script I made)