Because real disks suck...
Oh wow, been a while since me last post here.
A'ight, wut dis iz?
There are many tools for working with disk images and each OS varies a bit.
In the BSD world, even the command that does so can vary.
In OpenBSD, the `vnconfig` utility is just for managing disk image files as physical devices.
In layman's terms, you can mount a disk image file and use it like a USB drive!
Creating Disk Image Files:
Normally you could use `dd if=/dev/zero of=disk.img` or `cat /dev/zero > disk.img` or any other method you like then interrupt with the `Ctrl`-`c` SIGINTERRUPT escape sequence or... do it with a simple:
dd if=/dev/zero of=disk.img bs=4M count=1
...where you can set the block-size with `bs=??`.
Just realize that you can't do `2.3G` as an option as the `.` is not read properly.
If you have to do fractional sizes, just move down the measurement like `2300M` or so.
The important part is the `count` argument, if you don't use it then it will go on forever, gradually filling up your entire disk...
Once done (expect a long wait for large files) you have a `disk.img` file initialized with a bunch of `0`s...
Attach a Disk Image:
Enter the protagonist, the `vnconfig` utility.
It's the beast of burden and works surprisingly well at managing virtual disk images.
In OpenBSD, it can even manage encrypted images and decrypt/mount the volumes.
However, it uses `blowfish` for encryption, and `bioctl` with `softraid0` is better and the recommended way but that's not for now.
You simply:
vnconfig disk.img
...to attach the disk image as a virtual volume.
It generally gives one of 4 options: `vnd0`, `vnd1`, `vnd2`, `vnd3`.
The number you get depends on the current number of attached volumes.
These volumes show up under `/dev` and can be managed like any other device.
If you have no other disk images vnconfig'd, then it will show up as `vnd0`.
Remember that number!
Filesystem on Image Files:
The volume will be mounted, but initialized with tons of 0s, no partitioning scheme, no filesystem info...
We have to do all but setting up the filesystem with:
disklabel -E /dev/vnd0c
...then add a new partition with `a` and set the size, offset, and filesystem type with it.
You can set up multiple partitions if you want to.
Heck, you could create a diy bootable USB image with it (though there are better-equipped utils for it)...
The `c` is prefixed because `sh MAKEDEV vnd0` was not run from `/dev`.
If you do `cd /dev; sh ./MAKEDEV` it will allow you to use the easier `vnd0` and not have to bother with these strange partitions.
Assuming you have the disk initialized, write with `w` then quit with `q`.
You still need to add the filesystem, so use:
newfs /dev/rvnd0a
...to initialize the virtual disk's raw partition with the 4.2BSD filesystem.
You could also specify other partitions and filesystems.
The `r` is prefixed to let it know to use the raw device, else it will throw an error about writing to a block device.
The `a` at the end is the partition that I added with `disklabel`.
Mounting Disk Image Files:
After this, mounting and unmounting the volumes and partitions is really simple:
mount /dev/vnd0a /mnt
...and...
umount /mnt
However, you will need to detach the volume when done, so:
vnconfig -u vnd0
...will unset the volume and not have it relate to the image file `disk.img`.
That way you can use it for other things, like for a `crypt.img`...
Difficult, yet simple enough I suppose.
OpenBSD is Openly BaSeD.
Lame pun, Linux users don't hate on mah poor joking skills.
Thanks for reading, and HattyHacking;