If you need to present a directory as if it was a separate file system, you can use an AIX Name File System (NameFS). A NameFS is a pseudo-file system that lets you access a directory through two different path names. It also allows you to tweak the mount attributes of the NameFS mount.
With a NameFS you can create a second path and you don't have to change permissions, copy, move, rename or even touch the original file system.
When would you use this? Whenever it's helpful to have a separate mount point. Use a Name File System when you want to create a soft-mount to a directory so you can group files for logical reasons or modify their mount attributes. You could use a Name File System to set up a directory with:
- an alternate path (so it’s like a shortcut)
- different permissions (e.g. when some applications or users should have read-only access)
- other mount attributes such as Direct I/O (dio) or Concurrent I/O (cio)
Or you can use a combination of these. For example, if you want to grant read-only access to a file system's sub-directory, you could use a Name File System.
How to Create a NameFS
Setting up a NameFS is easy. First create a directory which will be the mount point for the new Name File System:
And then mount the first path onto the second path:
mount –v namefs /some/very/long/path /shortcut
You've now got access to the files via two paths. To remove the NameFS, simply unmount it with the umount command:
Change Mount Attributes
You can use a NameFS to mount a directory with different attributes to the original file system. For example, you can make a read-only mount of a directory:
mount -v namefs -o ro /data/ACME/reports /acme_rpt
Or you can mount a directory with Concurrent I/O (CIO) to improve I/O performance for database files. When you need to use CIO for database files or redo logs, for instance, but they aren't in their own file system, a NameFS will help:
mount -v namefs -o cio /db2/C01/redo /db2redo
For more about the performance benefits of using CIO, see Resources below.
Uses for Alternate Paths
Even if you don't change permissions or mount attributes, just having an alternate path can be very handy. Here are some possible uses:
Software releases. Set the user or application environments to point to /beta, and when you're ready to release the new beta code, you just create a new NameFS mount:
mount -v namefs /apps/v6 /beta
That's easier than changing the user environment for all users to point to the new version.
Branch shortcuts. A file system may contain data for several branch offices. If each branch has a unique identifier, the users can view only their branch's data using a NameFS:
mount -v namefs /report/region8/branch81 /br81
Scratch area. If you need to use some free space in a file system, and don't want to hard-code the full path name of the directory that has the space in it, you could create a NameFS.
mount -v namefs /dir/with/lots/of/space /scratch
Duplicate directory structure. A NameFS lets you duplicate a directory structure without doubling up on disk space. True, you could use a link with the ln command, but a NameFS gives you control over the mount attributes.
Mount a Single File
If you want to get more granular than mounting an entire sub-directory of a file system, you can mount a single file using a file-over-file mount. The target file needs to exist. You can use the touch command to create it:
And then do the mount:
mount /usr/local/scripts/software_v7.tar /beta.tar
df | grep beta
/usr/local/scripts/software_v7.tar 1048576 422824 60% 164 1% /beta.tar
This has all sorts of uses, such as making a backup file available read-only, or creating a standard file name for an archive or log file that has a sequential number as part of its name. When you're finished with the additional mount, unmount it:
Summary
With Name File Systems you can present a logical view to a sub-tree of a file system, and have more control over permissions and mount attributes. A file-over-file mount can let you create a quick logical alternate file view.
Resources:
Anthony English is an AIX / Power Systems engineer working in Sydney. Follow him on Twitter @AIXDownUnder.