42

I am new to fuse. When I try to run a FUSE client program I get this error:

fuse: mountpoint is not empty
fuse: if you are sure this is safe, use the 'nonempty' mount option

I understand that a mountpoint is the directory where you will logically attach the FUSE filesystem. What will happen if I mount to this location? What are the dangers? Is it just that the directory will be overwritten? Basically: what will happen if you mount to a non empty directory?

bernie2436
  • 22,841
  • 49
  • 151
  • 244
  • 1
    This happened to me. I noticed that i had saved some files by mistake under the directory that i try to mount. I just deleted them and everything was fine again. – Redu Jan 12 '21 at 08:57

6 Answers6

31

You need to make sure that the files on the device mounted by fuse will not have the same paths and file names as files which already existing in the nonempty mountpoint. Otherwise this would lead to confusion. If you are sure, pass -o nonempty to the mount command.

You can try what is happening using the following commands.. (Linux rocks!) .. without destroying anything..

// create 10 MB file 
dd if=/dev/zero of=partition bs=1024 count=10240

// create loopdevice from that file
sudo losetup /dev/loop0 ./partition

// create  filesystem on it
sudo e2mkfs.ext3 /dev/loop0

// mount the partition to temporary folder and create a file
mkdir test
sudo mount -o loop /dev/loop0 test
echo "bar" | sudo tee test/foo

# unmount the device
sudo umount /dev/loop0

# create the file again
echo "bar2" > test/foo

# now mount the device (having file with same name on it) 
# and see what happens
sudo mount -o loop /dev/loop0 test
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • by the mount command do you mean this? FUSE(FuseHandler(a), b, foreground=True) Do I add -o nonempty to that call? – bernie2436 Nov 28 '13 at 17:02
  • Are you using a command line tool or a programming language to control fuse? – hek2mgl Nov 28 '13 at 17:04
  • I am calling a python file that imports pyfuse – bernie2436 Nov 28 '13 at 17:06
  • However, you might try the steps I've listed in order to see what is going on if there are files with the same name when mounting... and play around. at the end I assume it makes no difference if you are using fuse or a *regular* mount... Also it should make no difference when using a programming language or not.. The most portable and secure way will still being: "mount into empty folder" – hek2mgl Nov 28 '13 at 17:10
  • `google-drive-ocamlfuse -o nonempty ~/gdrive` worked. `google-drive-ocamlfuse` creates `~/.gdfuse/default`. In that dir is a `config` file. Can I add a `nonempty` setting to the `config` file? – noobninja Aug 22 '15 at 00:46
  • users should not *disconnect* gdrive in thunar. Instead, *unmount* like this: `fusermount -u ~/gdrive` https://github.com/astrada/google-drive-ocamlfuse – noobninja Aug 22 '15 at 01:13
  • @hek2mgl `sudo echo "bar" > test/foo` gives me `bash: test/foo: Permission denied`. Why? – patryk.beza Mar 12 '19 at 08:50
  • 1
    @patryk.beza That's because the redirection `> test/foo` will be executed by the current shell and with the permissions of the user who executes the script, not with sudo. You can use `tee` instead: `echo "bar" | sudo tee test/foo`. PS: Thanks for spotting this problem! – hek2mgl Mar 12 '19 at 09:47
  • @hek2mgl Two more things: (1) I don't know why `sudo umount /dev/loop0` (which is mounted in `test`) gives `umount: /dev/loop0: not mounted.` even though it's listed as mounted in `mount` output. `sudo umount test` works fine. (2) You assume that `/dev/loop0` is unused which was not true in my case – I needed to get first unused `loop` device by running `sudo losetup -f` as suggested [here](https://superuser.com/questions/1367742/losetup-does-not-find-first-unused-loop-device-and-fails-to-list-busy-devices). – patryk.beza Mar 12 '19 at 10:32
  • One more thing: I need to use [`mkfs.ext3`](https://linux.die.net/man/8/mkfs.ext3) instead of [`e2mkfs.ext3`](https://linux.die.net/man/8/mke2fs) (there is no such a package on my `Ubuntu` 18.04.2 LTS). It seems that this is the same software named differently on different Linux distros. – patryk.beza Mar 12 '19 at 11:20
  • That's fine, it was just an example to create a filesystem (of arbitrary type). – hek2mgl Mar 12 '19 at 11:55
  • is this only when writing to files? or will it also cause issues reading from files? for example say i mount my .ssh for different config files – Fuseteam Dec 13 '19 at 13:38
  • I am using fstab to mount this partition. How would I add the `-o nonempty` option? – Sathesh Dec 20 '20 at 22:17
14

Just add -o nonempty in command line, like this:

s3fs -o nonempty  <bucket-name> </mount/point/>
Roman Cheplyaka
  • 37,738
  • 7
  • 72
  • 121
Vaseem007
  • 2,401
  • 22
  • 20
7

Apparently nothing happens, it fails in a non-destructive way and gives you a warning.

I've had this happen as well very recently. One way you can solve this is by moving all the files in the non-empty mount point to somewhere else, e.g.:

mv /nonEmptyMountPoint/* ~/Desktop/mountPointDump/

This way your mount point is now empty, and your mount command will work.

KJdev
  • 723
  • 1
  • 9
  • 20
3

For me the error message goes away if I unmount the old mount before mounting it again:

fusermount -u /mnt/point

If it's not already mounted you get a non-critical error:

$ fusermount -u /mnt/point

fusermount: entry for /mnt/point not found in /etc/mtab

So in my script I just put unmount it before mounting it.

WinEunuuchs2Unix
  • 1,801
  • 1
  • 17
  • 34
1

Just set "nonempty" as an optional value in your /etc/fstab

For example:

## mount a bucket
/usr/local/bin/s3fs#{your_bucket_name}  {local_mounted_dir}  fuse _netdev,url={your_bucket_endpoint_url},allow_other,nonempty 0 0
 
## mount a sub-directory of bucket, Do like this:
/usr/local/bin/s3fs#{your_bucket_name}:{sub_dir}  {local_mounted_dir}  fuse _netdev,url={your_bucket_endpoint_url},allow_other,nonempty 0 0
 
NicoNing
  • 3,076
  • 12
  • 23
-3

force it with -l

    sudo umount -l ${HOME}/mount_dir
  • It'd be useful to explain what this does, and why you recommend it over the approaches proposed by previous answers. – Jeremy Caney May 14 '20 at 01:22