/tmp Partition on Memory Filesystem

I have the /tmp partition of my OpenBSD system on a memory disk. Why? All of /tmp is cleared on a reboot anyway so I don’t store valuable data there. Besides that, it speeds up access (more on that later) and I have 12G of RAM to waste. So why not waste it on a memory filesystem.

Settings Things Up

Although OpenBSD has support for tmpfs it is disabled by default since it’s not properly maintained anymore. The other available memory filesystem is mfs - the memory filesystem (MFS) - that creates a RAM disk backed by your local swap partition.

I assume you have a swap partition, have you? If not, consider reinstalling and make sure that you have one. Find out your partition by using swapctl:

$ swapctl
Device      1M-blocks     Used    Avail Capacity  Priority
/dev/sd1b        2048        0     2048     0%    0

Creating a MFS is as easy as mounting a regular FFS partition. Just specify any flags you want and provide the name of your swap partition. Here is an example mount where I mount a 2G MFS:

# mount_mfs -o nodev,nosuid,async -s 2048m /dev/sd1b /mnt/
# mount | grep mnt
mfs:80942 on /mnt type mfs (asynchronous, local, nodev, nosuid, size=2048 1M-blocks)

Persist the MFS after the next Boot

Simply add an entry similar to the following to your /etc/fstab and make sure that the existing entry for /tmp is commented out. The maximum size is 2G and I use the usual mount flags. I also use async since the content will be lost upon reboot anyway.

#  cat /etc/fstab | grep tmp
swap    /tmp mfs rw,nodev,nosuid,async,-s=2048m 0 0

Set correct Permissions

Since MFS inherits the permissions from the root directory make sure that the permissions of the /tmp are 1777 (sticky bit). You can safely achieve this by rebooting into single user mode (reboot and type bsd -s at the loader prompt), fix the permissions and switch to multi-user mode.

Moving Firefox Cache to /tmp

One of my use cases to having /tmp on a MFS is to prevent that the Firefox disc cache ends up in $HOME/.cache. To set the non-standard location, start Firefox and navigate to about:config. Create a new string-based entry called browser.cache.disk.parent_directory and set the value to /tmp. Restart Firefox and you should see a new directory appearing. You can also check by navigating to about:cache.

Caution if you use multiple instances of Firefox running under different users. If you set the config value simply to /tmp the first running instance will create the cache directory and tighten the permissions so others cannot use it anymore. In this case, just set different path for each instance.

$Id: mfs.md,v 1.1 2019/02/21 13:31:01 cvs Exp $