$Id: ramdisk,v 1.3 2021/11/23 02:53:38 nanons Exp $

Mounting filesystems in memory
==============================

OpenBSD allows using a portion of memory as a temporary filesystem.
Data on this filesystem is lost on shutdown or unmount, which only
makes it suitable for directories like /tmp or ~/.cache.

The advantages of mounting a filesystem in RAM are better filesystem
performance and reducing wear and tear on physical drives.

Currently, OpenBSD doesn't support tmpfs which uses more RAM as needed.
Instead, it provides mfs which reserves a set amount of RAM upfront
that cannot be used by other processes even if that space is not in use
by files.

To set up /tmp to automatically mount as an mfs, it must first be
unmounted because we need to change its permissions:

	# umount /tmp

If that fails, there are files in use in /tmp.  To fix this, either:
a) Manually terminate all processes using the files.  To print the list
of processes with open files in /tmp:

	$ fstat | grep /tmp

b) Boot into single-user mode.  At the boot(8) prompt, enter:

	boot> boot -s

c) Force unmount (not recommended as it makes programs misbehave):

	# umount -f /tmp

To allocate 300 megabytes of memory for the filesystem, replace the old
/tmp entry from /etc/fstab with:

	swap /tmp mfs rw,nodev,nosuid,-s=300m 0 0

Then change the directory's permissions (mfs inherits them) and remount:

	# chmod 1777 /tmp
	# mount /tmp

Live system
===========

OpenBSD does not currently support booting the system in memory (but it
does support booting over the network, see diskless(8) for a tutorial).

However this can be done with FuguIta, a live system based on OpenBSD.
It closely follows OpenBSD-stable (errata included) and supports
persistent storage.  See more: http://fuguita.org
