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 '{}' '+'
reboot
...
# 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
END
# 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
END
# 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

--

--

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