Kaptain.
Telegram /
LinkedIn /
Email /
GIT /
RSS /
GPG /
Заказ печатных плат

№ 12688 В разделе
Sysadmin
от November 11th, 2025,
В подшивках: Linux, Virtualbox, Virtualization
Let’s say you need to create an image for your virtual machine where you’ll write some files or even create a special partition from an existing disk image. In Linux, you can mount this virtual disk image and use it like a regular block device!
The first step is to create your new virtual disk. This can be done directly in VirtualBox’s disk manager.
The next step is to install the necessary utilities and kernel modules from the Qemu distribution.
sudo apt install qemu-utils qemu-block-extra sudo modprobe nbd max_part=8 qemu-nbd --version
All preparations are complete; now you can specify the new block device.
sudo qemu-nbd -c /dev/nbd0 /tmp/New-disk-image.vdi
Finally, the final step is to create a partition table and a new partition on the new block device. As an example, I’ll create an EXT4 filesystem and mount it on my host system. You can also write special images using the dd utility.
cfdisk /dev/nbd0 mkfs.ext4 /dev/nbd0p1 tune2fs -L VDIPART1 /dev/nbd0p1
Just in case, let’s check the partition table.
vlad@turtle:/$ fdisk -l /dev/nbd0 Disk /dev/nbd0: 256 GiB, 274877906944 bytes, 536870912 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x10b50298 Device Boot Start End Sectors Size Id Type /dev/nbd0p1 2048 536870911 536868864 256G 83 Linux
Now you can mount this partition as usual and then unmount it after you’re done.
sudo mount /dev/nbd0p1 /mnt/ sudo rsync -avz /my/special/files/ /mnt/ sudo umount /mnt
Disconnect. Required before use in VirtualBox!
qemu-nbd -d /dev/nbd0
You’re awesome.
Fortune cookie: Today's spam: Taking black dong in her mouth.
Leave a Reply