Minimal OpenBSD Virtual Machine

  1. CD: using CD as root is a bad idea because it is read-only while kernel needs to write something (more accurately because I couldn’t do that)
  2. network: OpenBSD supports NFS on root, but you need a network accessible server with distinct disk spaces for virtual machines
  3. ramdisk: ramdisk is the best alternative to real disk for /; however it is limited (in my experience up to about 100 MB)
# set access time to an old date
find / -exec touch -a -t 197001010000 '{}' '+'
# do whatever you might need to do
# (login, ping, traceroute, ...)
# remove files that aren't accessed recently
find / -atime 1 -prune -exec rm -f '{}' '+'
# remove empty directories
find / -type d -exec rmdir '{}' '+'
# extract sys.tar.gz into /usr/src
# change kernel config
cd /usr/src/sys/arch/$(machine)/compile/GENERIC
sed -i -Ee'/(^conf|vmm|drm|gpu|agp)/d' ../../conf/GENERIC
cat <<-END >>../../conf/GENERIC
option MINIROOTSIZE=204800
config bsd root on rd0a
pseudo-device rd 1
# now build kernel
make obj
make config
make -j4
# extract ramdisk
mv /usr/obj/sys/arch/$(machine)/compile/GENERIC/bsd mybsd
rdsetroot -x mybsd rd.img
# disklabel
vnconfig vnd0 rd.img
dd if=/dev/zero of=/dev/rvnd0c count=8
print 'X\na a\n0\n*\n\n512\n\nn\n1\nw\nq\n' | disklabel -E vnd0
newfs -i 16384 -m 0 vnd0a
mount /dev/vnd0a /mnt
# now copy files
# now change fstab
cat <<-END >/mnt/etc/fstab
/dev/rd0a / ffs rw
swap /tmp mfs rw,nodev,nosuid,-s=64M
# insert ramdisk
umount /mnt
vnconfig -u vnd0
rdsetroot mybsd rd.img
vmctl start -L -b mybsd vm1
vmctl start -L -b mybsd vm2
vmctl start -L -b mybsd vm3
vmctl start -L -b mybsd vm4




UNIX and C lover

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

First Steps with Pulumi

What Should You Look For In A Job As A Developer?

Deep dive into the world of illegal streaming

Flask: Pass parameters between blueprints with url_for

Mapping the journey to Mars

Configure Self-signed Server Certificate in git bash for a Particular HTTPS Remote.

Google App Engine: The In-Between Cloud

Oracle Magento 2 Cloud on ARM instance Performance.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ali Farzanrad

Ali Farzanrad

UNIX and C lover

More from Medium

GameCI 1: Intro to GitHub Actions for Unity

Test, Build, and Deploy with GameCI

Simulation of Arduino Projects Using Proteus Design Suite


Spearmint, Refreshed.