41

I've written a small FUSE-based filesystem and now the only part's missing is that I want to register it with fstab(5) to auto-mount it on system startup and/or manually mount it with just mount /srv/virtual-db. How can I achieve this?

I know, I can just run /usr/bin/vdbfs.py /srv/virtual-db from some init script, but that's not exactly pretty.

I'm sorry because this may be not exactly a programming question, but it's highly related, as the packaging and deployment is still the programmer's job.

3
  • Good question, but not programming related and there is serverfault.com now.
    – ypnos
    Oct 12, 2009 at 12:53
  • 3
    If that's only administrative problem (like adding an entry to some file), then, yes, probably. But registering in-kernel filesystems are certainly a programming problem (the only admin part is adding module to modprobe.conf), and I don't know about FUSE... So, I don't know where this really belongs.
    – drdaeman
    Oct 12, 2009 at 14:26
  • 9
    Oh this belongs on SO, definitely! Sep 2, 2010 at 15:52

5 Answers 5

38

In general, one "registers" a new mount filesystem type by creating an executable mount.fstype.

$ ln -s /usr/bin/vdbfs.py /usr/sbin/mount.vdbfs

If vdbfs.py takes mount-ish arguments (i.e. dev path [-o opts]), then mount -t vdbfs and using vdbfs as the 3rd field in fstab will work. If it doesn't, you can create a wrapper which does take arguments of that form and maps them to whatever your vdbfs.py takes.

FUSE should also install a mount.fuse executable; mount.fuse 'vdbfs.py#dev' path -o opts will go on and call vdbfs.py dev path -o opts. In that case, you can use fuse as your filesystem type and prefix your device with vdbfs.py#.

1
  • 5
    Note that FUSE's author – Miklos Szeredideprecated encoding the real filesystem type in the mount source. Quote from mount manual: The programs mount and umount support filesystem subtypes. The subtype is defined by a '.subtype' suffix. For example 'fuse.sshfs'. It's recommended to use subtype notation rather than add any prefix to the mount source (for example 'sshfs#example.com' is deprecated). Apr 26, 2019 at 12:30
26

So to clarify ephemient's answer, there are two options:

  1. Edit /etc/fstab like this:

    # <file system>   <mount point>      <type>  <options>         <dump>  <pass>
    # ...
    vdbfs.py#<dev>    /srv/virtual-db    fuse    user,<other-opts>    0    0
    

    Or,

  2. Create an executable prefixed with "mount." (ensuring it can be used with mount-like options):

    $ ln -s /usr/bin/vdbfs.py /usr/sbin/mount.vdbfs
    

    And edit /etc/fstab like this:

    # <file system> <mount point> <type>    <options>         <dump>  <pass>
    # ...
    <dev>    /srv/virtual-db    vdbfs.py    user,<other-opts>    0    0
    

With regards to auto-mounting at start up and manually mounting with mount, the user and noauto options are relevant and fully supported by fuse itself so you don't have to implement them yourself. The user option lets a non-priveleged user who is a member of the "fuse" group mount your filesystem with the mount command, and noauto directs your filesystem not to automatically mount at startup. If you don't specify noauto, it will automatically mount.

6

To clarify @patryk.beza comment on the accepted answer, the correct way to mount a FUSE file system is by setting the file system type to fuse.<subtype>.

For example, to mount an s3fs-fuse implementation, which does not provide a specific /sbin/mount.* wrapper and uses normally the s3fs user command to mount S3 buckets, one can use this command as root:

mount -t fuse.s3fs bucket-name /path/to/dir -o <some,options>

or this line in /etc/fstab:

bucket-name /path/to/dir fuse.s3fs <some,options> 0 0

or this SystemD mount unit (for example, /etc/systemd/system/path-to-dir.mount):

[Unit]
Description=S3 Storage
After=network.target

[Mount]
What=bucket-name
Where=/path/to/dir
Type=fuse.s3fs
Options=<some,options>

[Install]
WantedBy=multi-user.target

How this works: mount recognizes the concept of "filesystem subtypes" when the type is formatted with a period (i.e. <type>.<subtype>), so that a type with the format fuse.someimpl is recognized to be the responsibility of the FUSE mount helper /sbin/mount.fuse. The FUSE mount helper then resolves the someimpl part to the FUSE implementation, in the same way as the # format is used in the original answer (I think this is just a path search for a program named <subtype>, but I'm not 100% sure about it).

2

You could just use fuse filesystem type. The following works on my system:

smbnetfs    /media/netbios    fuse    defaults,allow_other    0    0

Another example:

sshfs#[email protected]:/    /mnt    fuse    user,noauto    0    0
2
0

After researching a lot found this solution to mount fuse filesystem suing fstab entry. I was using fuse for s3bucket to mount on local linux machine.

  • .passwd-s3fs : Is containing credentials to access your aws account 1] Secret key and 2] Access Key .
  • uid : User Id. You can type linux command id and you can get uid

Syntax:

s3fs#<Bucket_Name> <Mounted_Direcotry_Path> fuse _netdev,allow_other,passwd_file=/home/ubuntu/.passwd-s3fs,use_cache=/tmp,umask=002,uid=<User_Id> 0 0

Example:

s3fs#myawsbucket /home/ubuntu/s3bucket/mys3bucket fuse _netdev,allow_other,passwd_file=/home/ubuntu/.passwd-s3fs,use_cache=/tmp,umask=002,uid=1000 0 0

To mount you need run following command.

mount -a

To check your bucket is mounted properly or not use following command to check which shows all mounted points.

df -h

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.