I’m using Ubuntu Server.
QEMU stands for Quick Emulator.
We are going to emulate with qemu a . img image from a real usb in x86_64 from another architecture.
installed on mac with homebrew or macports and linux with apt if it is not already installed by default.
First you need to locate the USB device:
lsblk
you will see something like this:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 4K 1 loop /snap/bare/5
loop1 7:1 0 73,9M 1 loop /snap/core22/1722
loop2 7:2 0 73,9M 1 loop /snap/core22/1748
loop3 7:3 0 258M 1 loop /snap/firefox/5701
loop4 7:4 0 258M 1 loop /snap/firefox/5751
loop5 7:5 0 505,1M 1 loop /snap/gnome-42-2204/176
loop6 7:6 0 516M 1 loop /snap/gnome-42-2204/202
loop7 7:7 0 91,7M 1 loop /snap/gtk-common-themes/1535
loop8 7:8 0 44,4M 1 loop /snap/snapd/23545
loop9 7:9 0 210,8M 1 loop /snap/thunderbird/631
loop10 7:10 0 210,8M 1 loop /snap/thunderbird/634
sda 8:0 0 447,1G 0 disk
├─sda1 8:1 0 1G 0 part /boot/efi
├─sda2 8:2 0 2G 0 part /boot
└─sda3 8:3 0 444,1G 0 part
└─ubuntu--vg-ubuntu--lv 252:0 0 100G 0 lvm /
sdb 8:16 1 0B 0 disk
In my case the USB is:
sdb
that is to say:
/dev/sdb
then to emulate with qemu the image it contains and in the same terminal:
sudo qemu-system-x86_64 -drive format=raw,file=/dev/sdb -boot order=d -m 512 -enable-kvm -nographic

In my case you can see ‘Hola Mundo’
was made:
a bootloader.asm file whose contents are:
BITS 16
org 0x7c00
start:
; Limpia la pantalla
xor ax, ax
mov ds, ax
mov es, ax
mov di, 0xb800
mov cx, 2000
mov al, ' '
mov ah, 0x07
rep stosw
; Configura el cursor en la esquina superior izquierda
mov ah, 0x02
xor bh, bh
xor dh, dh
xor dl, dl
int 0x10
; Imprimir "Hola Mundo" en la pantalla
mov si, msg
print_char:
lodsb
or al, al
jz hang
mov ah, 0x0e
int 0x10
jmp print_char
hang:
; Bucle infinito para evitar que el programa termine
jmp hang
msg db 'Hola Mundo', 0
times 510 - ($ - $$) db 0
dw 0xaa55
generate the .bin with the .asm:
nasm -f bin bootloader.asm -o bootloader.bin
then generate the .img:
dd if=/dev/zero of=bootloader.img bs=512 count=2880
dd if=bootloader.bin of=bootloader.img conv=notrunc
I copy the .img to the USB with dd:
sudo dd if=bootloader.img of=/dev/sdb bs=4M status=progress
then I synchronize the data:
sudo sync
after using the usb with qemu, i eject it:
sudo eject /dev/sdb