[PATCH 1/1] boot: try one disk after another until system boots successfully
SeaBIOS relies on the "bootorder" provided by QEMU to determine the boot device order. If QEMU does not configure "bootorder", SeaBIOS may instead prioritize disks based on the order in which they are probed. In that case, only the first disk may be tried. If booting from it fails, SeaBIOS may move on to other media rather than attempting the remaining disks. As a result, if QEMU provides an incorrect "bootorder", or if SeaBIOS's probe-based ordering does not place the boot disk first, SeaBIOS may fail to boot from the intended boot disk. Below is an example demonstrating how SeaBIOS can fail to boot due to a QEMU bug. 1. Create a QEMU instance with a virtio-scsi HBA and keep it in the prelaunch state. Use SeaBIOS rather than UEFI. -device virtio-scsi-pci,id=scsi0,num_queues=4 \ -S \ 2. First, attach the boot disk, then attach the secondary disk. (qemu) drive_add 0 file=boot.qcow2,if=none,id=drive0 (qemu) device_add scsi-hd,drive=drive0,bus=scsi0.0,channel=0,scsi-id=0,lun=1,bootindex=1 (qemu) drive_add 0 file=secondary.qcow2,if=none,id=drive1 (qemu) device_add scsi-hd,drive=drive1,bus=scsi0.0,channel=0,scsi-id=0,lun=2,bootindex=-1 3. Start the VM from the prelaunch state. QEMU doesn't update "bootorder" due to a QEMU bug. SeaBIOS attempts to boot from the secondary disk only once and then stops. As a result, the VM fails to boot. The symptom is not reproducible with EDK2/UEFI boot. While this issue needs to be fixed in QEMU, enhance SeaBIOS to try each disk in turn until the system boots successfully. Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com> --- The QEMU bugfix has been sent to: https://lore.kernel.org/qemu-devel/20260225220556.11049-1-dongli.zhang@oracl... src/boot.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/boot.c b/src/boot.c index 5c37daf..84743a6 100644 --- a/src/boot.c +++ b/src/boot.c @@ -1000,8 +1000,14 @@ do_boot(int seq_nr) boot_disk(0x00, CheckFloppySig); break; case IPL_TYPE_HARDDISK: + struct bios_data_area_s *bda = MAKE_FLATPTR(SEG_BDA, 0); + int i; printf("Booting from Hard Disk...\n"); - boot_disk(0x80, 1); + if (bda) { + for (i = 0; i < bda->hdcount; i++) + boot_disk(0x80 + i, 1); + } else + boot_disk(0x80, 1); break; case IPL_TYPE_CDROM: boot_cdrom((void*)ie->vector); -- 2.39.3
Hi,
As a result, if QEMU provides an incorrect "bootorder", or if SeaBIOS's probe-based ordering does not place the boot disk first, SeaBIOS may fail to boot from the intended boot disk.
Well, fix the boot order then? The point of having the boot order is to tell the firmware which device is the intended boot disk so the firmware does not have to play guessing games.
2. First, attach the boot disk, then attach the secondary disk.
(qemu) drive_add 0 file=boot.qcow2,if=none,id=drive0 (qemu) device_add scsi-hd,drive=drive0,bus=scsi0.0,channel=0,scsi-id=0,lun=1,bootindex=1 (qemu) drive_add 0 file=secondary.qcow2,if=none,id=drive1 (qemu) device_add scsi-hd,drive=drive1,bus=scsi0.0,channel=0,scsi-id=0,lun=2,bootindex=-1
3. Start the VM from the prelaunch state.
(qemu) system_reset (qemu) continue take care, Gerd
participants (2)
-
Dongli Zhang -
Gerd Hoffmann