There are a few ways of doing it (e.g. you could do it by booting a Linux OS and then partition/format it in there), but another good way (on Linux) is to use qemu-nbd:
Code: Select all
modprobe nbd
qemu-nbd -c /dev/nbd0 image_file
Then, interact with /dev/nbd0 like you would a normal disk. Once done:
This works over the network, too, but its faster on Linux. Don't forget to load the nbd module (or load it at boot). You could also create a loopback device pointing to your image file, but qemu-nbd is significantly easier. It also has the advantage that, by default, it creates 16 NBD devices for you, so you can have up to 16 disks mounted simultaneously. If you need more (or you want more than 16 partitions, the default maximum), you can specify the any or both of the nbds_max or max_part module parameters in the modprobe command.