$ qemu-img create -f qcow2 ./disk.img 2G
# Enable QEMU Disk Network Block Device Server
$ sudo modprobe nbd max_part=8
# Connect /dev/nbd0 to the image
$ sudo qemu-nbd -c /dev/nbd0 ./disk.img
/dev/nbd0
is now available for manipulation.
Create new partition and filesystem, then mount it.
# Create a new single partition
$ sudo sgdisk -n 1:0:0 -c 1:"Linux filesystem" -t 1:8300 /dev/nbd0
# Create a btrfs filesystem on the partition
$ sudo mkfs.btrfs /dev/nbd0p1 -L "Virtual Disk"
# Mount the partition on a mountpoint
$ sudo mkdir -p /mnt/vdisk
$ sudo mount -t btrfs /dev/nbd0p1 /mnt/vdisk
$ sudo umount /mnt/vdisk
$ sudo qemu-nbd -d /dev/nbd0