On Wed, 12 Jul 2023 09:25:15 +0800 Hongyi Zhao <[email protected]> wrote:
> On Wed, Jul 12, 2023 at 5:26 AM Glenn Washburn > <[email protected]> wrote: > > > > On Sat, 8 Jul 2023 19:58:29 +0800 > > Hongyi Zhao <[email protected]> wrote: > > > > > Hi here, > > > > > > Are there some convenient methods to debug grub scripts without > > > rebooting into grub shell? > > > > I would recommend running the GRUB EFI application in QEMU, as it will act > > more closely to when running on bare metal. Here's an example of a QEMU > > command that I use when doing development: > > > > qemu-system-x86_64 -name '[x86_64-efi] Test Grub' \ > > -m 2048 -bios OVMF.fd --enable-kvm -boot once=c,menu=on \ > > -nodefaults -rtc base=localtime -vga std -snapshot \ > > -drive file=/home/grub-tester/bootloader/efidisk.img,format=raw \ > > -device virtio-scsi-pci,id=scsi0,num_queues=4 \ > > -device > > scsi-hd,drive=drive0,id=systema,bus=scsi0.0,scsi-id=0,lun=0,channel=0 \ > > -drive file=/dev/sdc,format=raw,if=none,id=drive0,readonly=on \ > > -device > > scsi-hd,drive=drive1,id=systemb,bus=scsi0.0,scsi-id=0,lun=1,channel=0 \ > > -drive file=/home/user/disk.img,format=raw,if=none,id=drive1,readonly=on > > > > If you want to use a block device, then you'll need to run as root or > > otherwise have correct permissions to read from the device. But you can > > have everything in a disk image file and not need to run as root. > > I tried to adapt your approach to my case, but it didn't work: > > werner@X10DAi:/media/werner/a5d0e46f-aea7-43f0-9a3e-cfb6d517d214/EFI/grub-mkstandalone$ > sudo qemu-system-x86_64 -name '[x86_64-efi] Test Grub' -m 2048 -bios > OVMF.fd --enable-kvm -boot once=c,menu=on -nodefaults -rtc > base=localtime -vga std -snapshot -drive > file=./grubx64.efi,format=raw -device > virtio-scsi-pci,id=scsi0,num_queues=4 -device > scsi-hd,drive=drive0,id=systema,bus=scsi0.0,scsi-id=0,lun=0,channel=0 > -drive file=/dev/sdc,format=raw,if=none,id=drive0,readonly=on -device > scsi-hd,drive=drive1,id=systemb,bus=scsi0.0,scsi-id=0,lun=1,channel=0 > format=raw,if=none,id=drive1,readonly=on > qemu-system-x86_64: -drive > file=/dev/sdc,format=raw,if=none,id=drive0,readonly=on: Could not open > '/dev/sdc': No such file or directory The above arguments emulate two disks. One coming from grubx64.efi and one /dev/sdc. I think for your use case, you only need one drive. But it needs to be an EFI bootable disk image. The file grubx64.efi is just the EFI application, not the disk image, which contains grubx64.efi. Remember, the disk image file will show up as a scsi hard drive, so it needs to look like a bootable drive (ie has a GPT label and EFI System Partition correctly setup). This link[1] shows how to do it on a block device, but you can create everything in a file too (though you might need to learn how to use losetup). Glenn [1] https://old.nixaid.com/creating-uefi-bootable-usb-flash-drive-with-several-linux-distributions/ > > > Also You can add the options "--nographic -serial stdio" to have the > > interface > > be via serial, which allows text selection. In this case GRUB will need to > > be > > configured to output to serial. > > > > Glenn > > Zhao
