Experimenting with 9P, the Plan 9 file protocol
Lately I’ve been interested in 9P, the file protocol used by the Plan 9 operating system. Although Plan 9 is mostly a historical curiosity at this point, 9P is still in use outside of Plan 9. It seems especially popular for sharing files between guest and host operating systems when using virtualization. (Such as VirtFS or Windows Subsystem for Linux.)
My interest in 9P is that it’s fairly simple, and easier to implement than competing file protocols such as SMB, NFS, and WebDAV. For example, I’m thinking of having some of my embedded projects serve up their SD card via 9P, to make them easier to configure.
Linux comes with a 9P client (more on that below). There is a third-party client for MacOS, Mac9P, although I haven’t been able to get it to work on my Mac. And although Windows must have a built-in 9P client to support WSL, I haven’t seen any information about how to use that client to connect to external 9P servers.
Discounting older versions of the protocol that are no longer in use, there are basically three variants of 9P:
- 9P2000 - The original variant of 9P, used by Plan 9. A “lowest common denominator” that clients can fall back on.
- 9P2000.u - A variant which gives 9P more “UNIX-like” semantics, rather than Plan 9 semantics. Not clear if this is still in use much.
- 9P2000.L - A variant which changes 9P to pretty much exactly match the semantics of Linux.
The client that comes with Linux (v9fs) supports 9P2000 and 9P200.L.
Let’s take a look at how easy it is to get up and running on Linux. First, install the 9mount command:
$ sudo apt-get install 9mount
Then mount the public 9P server which is provided by 9p.io:
$ mkdir $HOME/9
$ 9mount 'tcp!9p.io' $HOME/9
Voila! Now take a look:
$ cd $HOME/9
$ ls -l
total 8929
drwxrwxr-x 1 4294967294 4294967294 0 Jul 15 2018 9grid
drwxrwxr-x 1 4294967294 4294967294 0 Jul 15 2018 adm
drwxrwxr-x 1 4294967294 4294967294 0 May 23 02:02 contrib
drwxrwxr-x 1 4294967294 4294967294 0 Jul 15 2018 dist
drwxrwxr-x 1 4294967294 4294967294 0 Jul 20 00:38 extra
-rw-rw-r-- 1 4294967294 4294967294 9142602 Jan 22 2015 lsr
drwxrwxr-x 1 4294967294 4294967294 0 Jul 15 2018 nix
drwxrwxrwx 1 4294967294 4294967294 0 Jun 5 00:31 patch
drwxrwxr-x 1 4294967294 4294967294 0 Jul 15 2018 plan9
-rw-rw-r-- 1 4294967294 4294967294 0 Jun 23 2013 _sources
drwxrwxr-x 1 4294967294 4294967294 0 Jul 15 2018 wiki
drwxrwxr-x 1 4294967294 4294967294 0 Jul 15 2018 xen
To unmount the filesystem when you’re done:
$ cd $HOME
$ 9umount $HOME/9