...making Linux just a little more fun!

<-- prev | next -->

Fun with FUSE

By Kumar Appaiah

Filesystem in Userspace (FUSE) is a very neat innovation in the Linux kernel which allows users to homogeneously mount almost anything as a directory with files, and opens up a new and fun way of handling various operations. For example, imagine being able to use your space in GMail as a disk, or mounting your Flickr photo page as a directory in your machine. Moving files to and from the service boils down to simple copying of files to and from the mounted directory. Sounds fun, right? So lets get our hands dirty with FUSE!

FUSE is available for the Linux kernel, as well as for FreeBSD and OpenSolaris. It acts as a layer between the service you wish to "mount" as a file system and the kernel, thus acting as a convenient means to access the service as an ordinary directory/file structure. There is an API which allows one to program the file system behaviour, so FUSE can be extended to any situation where it is useful to represent objects as files.

Getting FUSE

If you are running Linux kernel 2.6.14 or higher, in all likelihood, you already have FUSE in the kernel as a module. Otherwise, just get the sources from the FUSE home page and compile it for your kernel. Once you are done, you can test whether the module got loaded using:

sudo modprobe fuse
(Or modprobe fuse as root).

If you don't get errors, then we are ready to make FUSE dance. You might want to automate the process of loading the FUSE module every time you start your computer. This is usually accomplished by adding a line containing fuse to the /etc/modules file.

Also, ensure you have the userspace files as well, which come with the FUSE tarball, or get the fuse-utils package for your distribution. I would strongly recommend that you use FUSE using an ordinary user account and not as root. To do this, just adding yourself to the fuse group should be sufficient on most distributions. This is usually done with:

adduser <username> fuse

(Depending on your distribution, your "/dev/fuse" may belong to another group. Check with ls -l /dev/fuse. In that case, add yourself to group that you see when you run the latter command.)

I have used Debian GNU/Linux for trying things out, but I can assure you that things won't vary much in any other distribution.

Now, we'll look at two of the interesting FUSE file systems I use often.

Category: File systems
... imagine being able to use your space in GMail as a disk, or mounting your Flickr photo page as a directory in your machine. Moving files to and from the service boils down to simple copying of files to and from the mounted directory.

Flickrfs

Flickrfs is available from the author's home page. It is written in Python and uses the FUSE API. As the name suggests, it provides a convenient interface to most of the things you can do on the Flickr service's website through a convenient file system interface.

To start using it, extract the flickrfs tarball, edit config.txt there to set the preferred resolution, browser and timeout values. Create a directory called .flickrfs in your home directory, and place the config.txt file there. Create a mount point for your Flickr account; I chose ~/Flickr, but you can choose any directory. If you use a proxy server to access internet, set your HTTP proxy by doing export http_proxy="http://proxyserver:port" with appropriate proxy server and port. Then, it is just a matter of doing

python flickrfs.py ~/Flickr

Now, your sets are automatically loaded. To see all your photos, create a directory called stream, and cd to it or load it in your file or photo manager (Konqueror, nautilus, gwenview, F-spot, to name a few). The directory will be populated with all your Flickr images. Similarly, there exist two subdirectories in the tags directory, namely public and personal. Now, to see all of your images which you tagged with tag1 and tag2 and tag3, merely create a directory called tag1:tag2:tag3 in personal, and cd to it or view it in a file manager. A similar subdirectory in public would show everyone's public images with those tags. Just copy photos from the directories to your hard disk folders. Nice?

Many more features, like uploading being a simply copy, editing metadata, changing date, time, permissions, license etc. are available. See http://manishrjain.googlepages.com/flickrfs for information.

To unmount when you are done using the Flickr account, just use fusermount like this:

fusermount -u ~/Flickr

Replace ~/Flickr with your mount point.

curlftpfs: Mount FTP servers

This is something that I really love! Accessing a FTP server as though it's contents were on directories on your own computer! Just get curlftpfs from the curlftpfs page, install it using the standard ./configure; make; make install, or install the package available for you distribution, and just do something like this:

[kumar@debian ~] mkdir IITM_Mirror
[kumar@debian ~] curlftpfs ftp.iitm.ac.in IITM_Mirror/
[kumar@debian ~] cd IITM_Mirror/
[kumar@debian ~/IITM_Mirror] ls
...
README          debian...

That's it! I have used IITM_Mirror as the mount point for the mirror. You can now mount FTP servers, even with password login, so that you can do uploads as well. Do curlftpfs -h for learning how to mount servers with login for write access and using proxies. To unmount, use fusermount -u ~/IITM_Mirror.

Also you can add

curlftpfs#ftp.iitm.ac.in /home/<youruser>/IITM_Mirror fuse rw,uid=1000,user,noauto      0   0
to your /etc/fstab and then use mount /home/<youruser>/IITM_Mirror to mount and umount /home/<youruser>/IITM_Mirror: to unmount the FTP directory

(Change uid of 1000 to the userid you get when you type id on your console).

Is that all?

So, do you think this is cool? Don't say no before you have seen the other possibilities at the FUSE file system list. There are some very useful file systems to be explored; do try them out. Also, FUSE is not restricted to just network based services; it acts as a layer for using various filesystems and external devices as well. For example, gphotofs mounts a GPhoto compatible camera as a file system. DVDfs allows a DVD video structure to be recreated on another disk. A filesystem for mounting iPods is also available. The possibilities with FUSE are endless!

A Tip

Before signing off, I'll give you one tip which might be useful. Sometimes, especially when you have an erratic network connection, the network based FUSE filesystems might not respond well, and cause a bit of trouble. Under those situations, you may not be able to do a clean unmount using fusermount -u. Under those situations, you can force a lazy unmount using fusermount -u -z and try mounting the file system again.

Although I know that I haven't written much in this article, I hope that it was sufficient to provide you with a glimpse of how powerful and convenient FUSE can be, with two sample file systems. Please try it out, and enjoy the benefits of mounting almost anything as a file system; be sure to try out other file systems, especially the popular gmailfs, smbnetfs and the like.

Talkback: Discuss this article with The Answer Gang


Bio picture

Kumar Appaiah is studying to earn a B.Tech in Electrical Engineering and M.Tech in Communication Engineering (Dual-degree) at the Indian Institute of Technology Madras. He has been using GNU/Linux for the past five years, and believes that Free Software has helped him do work more neatly, quickly and efficiently.

He is a fan of Debian GNU/Linux. He loves using Mutt, GNU Emacs, XCircuit, GNU Octave, SciPy, Matplotlib and ConTeXt.


Copyright © 2007, Kumar Appaiah. Released under the Open Publication License unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 134 of Linux Gazette, January 2007

<-- prev | next -->
Tux