3

I'm following the babystep bootloader guide writing the code on GAS as suggested here when I run the image with qemu-system-x86_64 -machine type=pc,accel=kvm -drive 'format=raw,file=boot.bin' it works as expected, but I'd like to change the machine type to q35.

Here is my code:

.global _start
.code16
.text
_start:
        cli
        jmp .
.org 510
.word 0xaa55

Compiled with:

gcc \
  -Wl,--oformat=binary \
  -Wl,-Ttext=0x7c00 \
  -Wl,--build-id=none \
  -nostartfiles \
  -nostdlib \
  -m32 \
  -o boot.bin \
  boot.s

It's supposed to hang, with type=pc I have the following result: If you try to type Ctrl-Alt-Delete here nothing happens, that is the expected behavior.

And with type=q35 the following result:

How can I achieve the same result as on type=pc using type=q35?

P.S.: partial solution:

qemu-img create -f qcow2 -o lazy_refcounts=on disk.qcow2 16G
sudo modprobe nbd max_part=8
sudo qemu-nbd --connect=/dev/nbd0 disk.qcow2
sudo dd if=boot.bin of=/dev/nbd0 status=progress
sudo qemu-nbd --disconnect /dev/nbd0
# ... -drive 'format=qcow2,l2-cache-size=2M,cache-clean-interval=900,file=disk.qcow2' ....

I'm not going to accept that yet until I understand why raw format is not working and if is really the only one possible way to fix that.

Tiago Pimenta
  • 736
  • 7
  • 20
  • I seem to recall soemthing similar. What happens if you use `qemu-system-x86_64 -machine type=q35 -drive format=raw,if=floppy,file=boot.bin` . I've added the `if=floppy` to the drive options. – Michael Petch Aug 11 '21 at 21:36
  • It works as floppy, I believe the default is `index=0,media=disk,if=ide`, is it somehow related to the q35's bus? How can we fix that? I mean, it's a weird restriction having to be floppy. – Tiago Pimenta Aug 11 '21 at 21:54
  • Ah didn't notice you were trying for a hard disk. Probably related to the fact that I think with q35 that the drives are SCSI and not IDE. – Michael Petch Aug 11 '21 at 22:27
  • 1
    I have some VMs with different versions of linux in `qcow2` format, when I run `info block` on monitor it replies as `ide0-hd0`. Now I tried to create a `qcow2` image, connect to a nbd device and copy the first sector then it worked as expected. I'm not sure why `raw` format is not working.... – Tiago Pimenta Aug 12 '21 at 00:05

1 Answers1

2

To fix that bug the image should have 515585 bytes or more, I don't know where this number comes from, I have tested several combinations until achieve this result, if you try one single byte less it doesn't work, but more bytes works fine.

truncate -s515585 boot.bin
Tiago Pimenta
  • 736
  • 7
  • 20