mount_nullfs can be used in FreeBSD to create ‘aliases’ of filesystem trees. These are similar to the effect that can be achieved with regular symlinks, like for instance:
# cd / # ln -s home/opt opt
The main difference of doing the same thing with mount_nullfs is that system functions like
realpath(3) will return the nullfs-aliased path instead of the real path. For example, if you create
/opt as a nullfs-alias of
# mkdir /opt # mount_nullfs /hugedisk/opt /opt
You will see something like this:
$ mount | fgrep /opt /hugedisk/opt on /opt (nullfs, local) $ cd /opt $ realpath . /opt $ stat . 151060228 2096128 drwxr-xr-x 4 root wheel 8373856 512 "Apr 2 03:06:26 2006" "Mar 31 14:17:13 2006" "Mar 31 14:17:13 2006" "Nov 14 17:46:16 2004" 4096 4 0 . $
Note how the ‘real’ path of
/opt is not
/hugedisk/opt and how the
stat(1) utility reports that
/opt is not a symbolic link but a directory (the first letter of file flags is ‘d’)!
One useful application of this, if you are running multiple chroot or jail environments is filesystem sharing between many chrooted or jailed environments. Mounting the common parts as read-only from parts of the host system of the chroot or jails is an easy and cool way to do this with mount_nullfs.