We'll start off by using QEMU's qemu-img
binary tool to create a new blank raw disk image. The reason for the decision of RAW, rather than QCOW2, is that Copy-On-Write has a lot of latency, and if you know you're going to use 128GB of storage, there is no reason to not simply allocate it all at once, and provide VirtIO FS with a much better read/write experience.
qemu-img create -f raw OpenCore.img 2G
Where, OpenCore
can be replaced with any name and 2G
is the intended size for your OpenCore disk image.
Now that the disk image exists, we'll want to format it as FAT32 directly from our host. To do so, we'll need to mount this disk image. This requires the usage of QEMU's NBD
module that allows assigning disk images to virtual slots on the host via virtual nbd# devices. Start by ensuring that nbd is running. This will require modprobe or similar.
sudo modprobe nbd max_part=8
Then go ahead and mount the created disk image.
sudo qemu-nbd --connect=/dev/nbd0 -f raw OpenCore.img
If you have issues with NBD0, move onto NBD1, up until 8.
You can ensure the mount was successful by checking if nbd# was created and has the appropriate disk size reporting back.
lsblk -o NAME | grep "^nbd[0-9]\+$"
You'll now want to format said disk image as FAT32 if you intend this to be for OpenCore, for other disk images you can skip the formatting and mounting entirely! Simply add to the guest and use as you please.
sudo mkfs.fat -F 32 -n "OPENCORE" -I /dev/nbd0
Where, OPENCORE
can be replaced with any 8 character string. Adjust NBD# as needed.
As of right now, your disk image has now been formatted and is now FAT32. To continue, you'll want to presumably mount it, and edit its contents, i.e installing and configuring the OpenCore bootloader itself. To do this, you'll want to start off by creating a new directory, named mnt
which will be used to view the contents of the disk image once mounted.
mkdir mnt
Ensure you mount the disk image to the mnt
folder with the appropriate permissions so that you actually have read/write access to its contents.
sudo mount -o uid=$(id -u),gid=$(id -g) /dev/nbd0 mnt
Adjust NBD# as needed.
Later on when required to unmount, you can follow the instructions below to safely eject the disk image.
sudo umount mnt
sudo qemu-nbd --disconnect /dev/nbd0
rm -rf mnt
Adjust NBD# as needed.
You can now continue and populate the contents of this newly created disk image.