Populate MFS on FreeBSD
=======================

$HOME in MFS
------------
I have been running my $HOME in MFS (Memory File System, also
known as "RAM disk") for many years, probably more than two
decades.

Originally I started with $HOME in MFS to preserve the USB memory
stick my system was booting from.

At the time I used a VIA EPIA motherboard booting from an 128 MB
USB stick with a self made Linux system, based on a Linux kernel,
a home made initramfs, with XVesa, GNU screen, ssh, and an
terminal application on top of busybox. This way I had an
affordable, 100% silent workstation.

When 256 MB memory sticks became available and affordable, I
could also add Mozilla and a PDF viewer to it.

I got used to working with $HOME in MFS, and started to
appreciate it.


$HOME in MFS is not empty
-------------------------
Your home directory is where your configuration files live. Those
files are also known as dotfiles or rcfiles.

When setting up a home directory in MFS, there has to be a
mechanism that populates it with the dotfiles and anything else
you want to be there.

There has to be some kind of template directory, which contains
the files. At boot-time, the contents of this template directory
must be copied to the MFS.

Some methods that I have used over the years:

* Create a cpio archive and let a script unpack that in $HOME
* Create a tar archive and let a script unpack that in $HOME
* Don't pack the template but just run a script from rc.local
 that copies the template directory
* Mounting a MFS in OpenBSD with the -P flag, which automatically
 copies the template directory

NB: The dotfiles are called dotfiles, because their names tend to
start with a dot :) A simple "cp /dir-a/* /dir-b/" will not work.


Advantages of $HOME in MFS
--------------------------
When I moved to other systems as workstation (mostly laptops), I
kept the practice of running $HOME in MFS.

This has several advantages:

* When you run $HOME in MFS, your home directory is nice and
 clean after each and every boot. No files left over from
 previous sessions, no overloaded Downloads directory, but
 just essential files and directories.

* Changes to configuration file are never accidental. A
 configuration file in the MFS (RAM disk) can be changed, but it
 will return to its original content after a (re-)boot. To make
 a change persistent, it has to be done in the template
 directory.

* Cookies, and super cookies and other surveillance methods that
 rely on the browser cache, are gone after a (re-)boot.

* It hones the habit to always check in any work done into Git
 (or any other version management system). You know that
 everything will be gone after a shutdown or a reboot.


Disadvantages of $HOME in MFS
-----------------------------
Nothing has only advantages, everything has its pro's and con's.

Some disadvantages:

* Configuring your web browser and adding bookmarks to your web
 browser is more work, the changes have to be persistent.

* Work that is not saved to disk in one way or another, will be
 gone after a shutdown or a (re-)boot.

* Larger things are better placed outside the MFS, using a
 symbolic link to them.
 Some examples are the ~/quicklisp directory and the ~/.emacs.d
 directory. This of course depends on what software you are
 running and how much it wants to store in your home directory.


$HOME in MFS rocks!
-------------------
For me, the advantages outweigh the disadvantages.


Populating a MFS on FreeBSD
---------------------------
Yesterday I discovered the -k flag for mdmfs, the utility to set
up one or more MFS's on FreeBSD. Probably this option has been
there all the time.

The -k flag for mdmfs works the same as the -P flag in OpenBSD.

This is how I set it up in /etc/fstab on the X201 running
FreeBSD:

 md /home/matto mfs rw,late,-n,-s256m,-k/template-dir 2 0

Explanation:

* md:    mdmfs uses the md under the hood
* /home/matto: the directory to mount as MFS
* late:  this option is required because the ZFS datasets have
 to be mounted and available before the MFS can be mounted
* s256m: this is the maximum size the MFS can grow to
* /template-dir: the template-directory

Happy MFS-ing!


Last edited: $Date: 2023/12/23 13:56:20 $