Sample Header Ad - 728x90

Can Qemu / OVMF boot from virtual drives with logical sector size 4096?

2 votes
1 answer
281 views
I am running Debian bookworm on a physical host and use Qemu / KVM to run a bunch of virtual machines there. Most of the VMs are UEFI-based, and most of the virtual drives have 512 bytes logical sector size for historical reasons: The respective VMs actually are backed by raw images of the 512n physical disks they were running on in former times. That is, I typically have sections like the following in the Qemu command lines:
-drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.ms.fd \
-drive if=pflash,format=raw,file=/root/qemu-kvm/OVMF_VARS_4M.ms.p8v.fd \
\
-object iothread,id=thread1 \
-blockdev driver=file,node-name=file03,aio=threads,cache.direct=on,cache.no-flush=off,discard=unmap,filename=/vm/vm-p8v.img \
-device virtio-blk-pci,iothread=thread1,write-cache=on,drive=file03,logical_block_size=512,physical_block_size=4096 \
All of these machines are starting up and running fine. However, yesterday I've decided to waste 12 h of my remaining lifetime by trying to run one of those VMs using a logical block size of 4096 bytes. That is, I'd like to have logical_block_size=4096 instead of logical_block_size=512 in the code shown above. The reason why I'd like to test this is complex and distracting, so let's put that aside for the moment. The sector size conversion for the virtual VM disk was quite tricky, but I knew that before. Among others, I had to move the GPT within the virtual HDD and had to manipulate it, as well as the protective MBR. I also had to "convert" the OS itself and the contents of the EFI system partition. Now I am nearly there, but for the life of me, I can't make OVMF recognize the EFI partition or boot from it. I have tried a bunch of things to find out what's going on: - Attach the guest OS installation ISO to the VM, fire up the VM, boot from the ISO, and from within the ISO, repair the OS bootloader. This works in that it creates a new UEFI boot menu entry. When entering the UEFI setup in the VM afterwards, that new entry shows up and can be selected for boot. However, booting fails with an obscure error message from the guest OS. - Fire up the VM, go into the OVMF UEFI setup before the guest OS starts, and try to create an appropriate new boot entry from there. The problem here is that OVMF does not find the EFI partition, and therefore, I can't create that boot entry. That's weird because I have verified a dozen of times that the EFI partition exists, is formatted as FAT32, and actually contains the bootloader. There is *definitely nothing wrong with the EFI partition*, except for the fact that the virtual disk where is resides on now reports a logical sector size of 4096 bytes instead of 512 bytes. - Fire up the VM, go into the UEFI shell and examine the mapping. Interestingly, I see only BLKx: devices there (if that's the right term), but none of the usual fsx: devices. Again, this means that the OVMF UEFI BIOS does not recognize the EFI system partition. Putting everything together, my current theory is that the OVMF version that Debian bookworm ships is not able to deal with disks that report a logical sector size of 4096 bytes. Of course, I have spent quite some time trying to find out whether that's the case, but I failed in doing so. I wasn't able to spot an answer, not even vague hints. Therefore, I am interested in answers to the following questions: - Is OVMF 2022.11-6+deb12u1 (the version that Debian bookworm ships) able to deal with logical 4096-byte sectors on the underlying virtual disk / EFI partition if used with Qemu 7.2+dfsg-7+deb12u7 (again, the version that Debian bookworm ships)? - If the answer to the above question is no, is there a newer version of the OVMF UEFI BIOS that is capable to to this, and where can I get that version? As a final note, I have not mentioned the guest OS in the respective VM by intention. Maybe the guest OS causes further problems at a later point, but as a matter of fact, the immediate problem to solve next is that OVMF does not recognize the EFI partition or its contents, which doesn't have anything to do with the guest OS. I'd like to emphasize again that the EFI partition definitely exists and contains all files needed. I can mount the EFI partition without any issues and can verify the existence of those files, and have done so a dozen of times. **Update #1** In the meantime, I have found the following document: https://www.linux-kvm.org/downloads/lersek/ovmf-whitepaper-c770f8c.txt In section "Motivation", it states: >Support for booting off disks (eg. pass-through physical SCSI devices) with a 4kB physical and logical sector size, i.e. which don't have 512-byte block emulation. Well, this kind of answers the question, but on the other hand, I don't know which part of the goals is actually implemented, and I still have to state that this doesn't work for me. I am not yet at the point where I give up, though.
Asked by Binarus (3891 rep)
Sep 9, 2024, 08:02 AM
Last activity: May 1, 2025, 01:22 AM