简体   繁体   中英

How to create an image file for use with QEMU in Linux?

I have been following a tutorial online and have built a 512-Byte bootloader saved as boot.bin .

I also have a second stage bootloader compiled and saved as 2ndstage.bin .

My bootloader is written such that the second stage doesn't have to be located directly after the first stage in memory, as it searches for it by file name.

How would I, in Linux, combine both bin files into some sort of file (maybe an image) that I can use with QEMU in order to run my bootloader?

Create a raw disk image file using dd if=/dev/zero of=image.raw bs=1M count=50 That will make a 50 megabyte image file out of zeros.

If you want to operate on a block device instead of a file, you can loopback mount image.raw as a block device (read losetup man page)

You can partition the file or loopback device using regular fdisk or sfdisk utilities. Then you can either use other dd options (read the man page for it) or other options to put your bin files into the right places in the disk image.

After that, undo the loopback device if you made one, and start your qemu / qemu-kvm session using the image.raw file as your disk device. If you did your bootloader correctly the qemu bios will start it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM