How do I create a mountable DOS/MBR boot sector?

Viewed 21

Is there a way to boot from a hard drive or usb? I'm trying to learn that, even going so far as to install qemu-system to boot virtually.

At first I tried to install alpine and run it, this is the command I use:

qemu-system-x86-64 -m 512 -smp 6 -cdrom alpine-virt.iso -hda alpine.img -boot d

And I immediately wrote the command setup-alpine and run it.

Actually this is not the problem I want to ask How do you do that (see this picture).

Let's say we use mkfs.ext4 maybe the output seen from the file command is

test.img: UUID="f5c1743c-e48d-46c3-bd14-e9c4f7ea89e2" BLOCK_SIZE="1024" TYPE="ext4"

So how do you check when you check using the 'file' command, the output looks like this:

0.img: DOS/MBR boot sector

I hope that even though my question may be difficult to understand, it can be answered in a short time.

1 Answers

You need to add partitions to your image file.
Use fdisk/sfdisk gdisk/sgdisk(apt install gdisk) for that.

Show your partion layout:

sfdisk -d test.img

To create an empty mbr-partition table use fdisk and "o"

Then add your partitions, for rootfs, data, etc.

To be able to boot you probably want to use something like the grub bootloader.
But to get this working with an image file is a bit nasty.

Related