You can mount a disk image and access the image just as you would a disk partition. This is very useful for those times you want to extract a few files from an ISO but don’t want to bother burning the image to physical media. The trick to mounting a disk image is attaching the image to a device node so that you can use the proper mount
command.
OpenBSD uses the vnconfig(8)
program to attach disk images to device nodes. (Remember that a vnode is an abstraction layer between the kernel and a filesystem.) Use vnconfig
to “wire” vnodes between a file and a device node, and then access them through OpenBSD’s /dev/svnd devices. Depending on the disk image type, the image might have MBR partitions, disklabel partitions, or just a filesystem.
The default kernel has four vnode devices. If you need to mount more than four disk images simultaneously, edit your kernel binary using config(8)
’s -e
option, as discussed in Chapter 18.
The vnconfig(8)
command takes two arguments: the device node you want to use and the disk image you want to mount.
# vnconfig /dev/svndXc /path/to/file
Note that this example uses the c partition of the device. This allows you to treat the disk image as a whole disk.
Suppose you have an ISO image named install52.iso that you would like to mount. First, use vnconfig
to attach this image to vnode device 0.
# vnconfig /dev/vnd0c install52.iso
You can then use mount
to attach the vnode to an /mnt directory.
# mount /dev/vnd0c /mnt/
OpenBSD’s mount(8)
is smart enough to recognize this as a CD filesystem and mount it as such. If you’re mounting a disk image that uses a less detectable filesystem, you need to use the specific mount
command for that filesystem.
Vnode devices attached to a file remain attached until specifically disconnected, and you can attach a vnode device to only one file at a time. To disconnect the vnode device from the file, use the -u
flag with vnconfig
. For example, to disconnect the vnode device located at vnd0c, run this command:
# vnconfig -u vnd0c
You can now attach this vnode device to another file.
Using the full path to the device is optional in vnconfig
. If you know the device name, you can use it without the leading /dev, as in the preceding example.