The following is the GNU All-permissive License as recommended in https://www.gnu.org/licenses/license-recommendations.en.html

Copyright (C) 2024 Free Software Foundation sysadmin@fsf.org

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.

Contributions are welcome. See https://savannah.gnu.org/maintenance/fsf/.

Booting kvm without grub

cat << EOF > /tmp/grub.cfg
linux (hd0)/vmlinuz root=/dev/sda ro elevator=noop console=tty0 console=ttyS0,115200
initrd (hd0)/initrd.img
boot
EOF

grub-mkimage -v -C xz -c /tmp/grub.cfg  -O i386-pc  -o /var/lib/libvirt/images/grub-i386.bin  biosdisk ext2 linux xfs

Then use grub-i386.bin as the kernel for that vm. A kernel needs to be installed in the vm, and symlinked as /vmlinuz /initrd.img No need to install grub in the vm, or have /boot/grub/grub.cfg|menu.lst

With LUKS automount

This requires patches to grub2 from http://grub.johnlane.ie/ They are already applied to Trisquel's grub starting on 8.0

cat << EOF > /tmp/grub.cfg
cryptomount -f (memdisk)/keyfile (hd0)
linux (hd0)/vmlinuz root=/dev/sda ro elevator=noop console=tty0 console=ttyS0,115200
initrd (hd0)/initrd.img
boot
EOF

dd if=/dev/zero of=/dev/shm/memdisk bs=1M count=1
mkdir /dev/shm/memdiskmount
mkfs.ext2 /dev/shm/memdisk
mount /dev/shm/memdisk /dev/shm/memdiskmount
echo -n "password" > /dev/shm/memdiskmount/keyfile
umount /dev/shm/memdiskmount

grub-mkimage -v -C xz -c /tmp/grub.cfg  -O i386-pc  -o /var/lib/libvirt/images/grub-i386.bin  biosdisk ext2 linux xfs normal luks help crypto cryptodisk zfscrypt gcry_sha512 echo cat memdisk -m /dev/shm/memdisk

rm /dev/shm/memdisk

Extract password from grub image

If for some reason you don't have the password that's inside a grub image, use this script: https://github.com/msuhanov/grub-unlzma/blob/master/grub-guess and then run "strings" on the output. The password should be near the end of the output.