Skip to content

qemu-img create fails on loop device with sector size 4096

On current master the following fails:

dd if=/dev/zero of=blockfile bs=1M count=1024
sudo losetup --sector-size 4096 /dev/loop0 blockfile

$ sudo qemu-img create -f raw /dev/loop0 1G
Formatting '/dev/loop0', fmt=raw size=1073741824
qemu-img: /dev/loop0: Failed to clear the new image's first sector: Invalid argument

I did a bisect on this, and seems like 5634622b is the cause of this. Most likely because before that commit it did not write zeroes to the device and therefor never hit this bug.

I was able to fix it by getting the real sector size in create_file_fallback_zero_first_sector instead of using BDRV_SECTOR_SIZE.

Question is of course if this is the good fix or we should fix the issue somewhere else in the code 😄

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information