Nextcloud mount bind
The good news is there’s an excellent Linux-specific workaround for this exact problem: using a bind mount.
What is a Bind Mount?
A symbolic link is a pointer to another directory. The Nextcloud client sees this pointer and ignores it.
A bind mount, on the other hand, is a kernel-level feature that makes the contents of one directory appear as if they are physically located in another. To the Nextcloud client, the bind-mounted directory looks and behaves exactly like a normal directory, so it will sync all of its contents.
Step-by-Step Instructions for a Bind Mount
This method requires you to use the terminal on your Ubuntu machine. You’ll need to use sudo to run the mount command.
Step 1: Create a Destination Folder
First, create an empty directory inside your Nextcloud sync folder. This will be the “mount point” for your external directory.
For example, let’s say your Nextcloud sync folder is at ~/Nextcloud and your external directory is at ~/Documents/Music.
mkdir ~/Nextcloud/Music
Step 2: Create the Bind Mount
Now, use the mount --bind command to link the external directory to the new folder you just created.
sudo mount --bind ~/Music ~/Nextcloud/Music
After you run this command, the contents of ~/Documents/Music will immediately appear inside ~/Nextcloud/Music. The Nextcloud desktop client will now see these files as if they were a normal part of your sync folder and begin uploading them to the server.
You can verify the mount was successful by running ls ~/Nextcloud/Music.
Step 3: Make it Persistent (Optional but Recommended)
The bind mount from the previous step is temporary and will be lost after a reboot. To make it permanent, you need to add an entry to your /etc/fstab file.
-
Open the file with a text editor with
sudo:sudo vim /etc/fstab -
Add the following line to the end of the file, replacing the paths with your own:
/home/wga/Music /home/wga/Nextcloud/Music none bind,x-gvfs-hide 0 0- Note: You must use the full, absolute path, not the
~shortcut. - ,x-gvfs-hide —> results in no mount icon appearing on your desktop
- Note: You must use the full, absolute path, not the
-
Save the file and exit the editor (Ctrl+X, then Y, then Enter in
nano).
Now, the bind mount will be automatically re-established every time you start your computer.
How to Unmount
If you ever need to remove the bind mount, you can use the umount command:
sudo umount ~/Nextcloud/Music
This will not delete any files, but it will sever the connection and the folder will return to being empty. You can then safely delete the ~/Nextcloud/Music directory if you wish.
Why Bind Mounts Work Better
You’re absolutely right about the key difference:
- Symbolic links: The Nextcloud client sees them as pointers and typically ignores them
- Bind mounts: The kernel makes the directory contents appear as if they’re physically there, so Nextcloud treats them as normal directories
A Few Additional Tips
Verification: After creating the bind mount, you can verify it’s working with:
# Check if the mount is active
mount | grep bind
# Or specifically check your mount point
findmnt ~/Nextcloud/Music
Safety consideration: Before setting up the bind mount, make sure the destination directory in your Nextcloud folder is empty. If it contains files, they’ll be “hidden” by the bind mount (not deleted, just inaccessible until you unmount).
Testing the fstab entry: After adding the line to /etc/fstab, you can test it without rebooting:
sudo umount ~/Nextcloud/Music # Unmount the manual bind mount
sudo mount -a # Mount all entries in fstab
Permissions: Since bind mounts preserve the original directory’s permissions, make sure your user has read/write access to the source directory.
Alternative fstab syntax
Some users prefer this slightly more explicit fstab syntax:
/home/your_username/Documents/Music /home/your_username/Nextcloud/Music none defaults,bind 0 0
This approach gives you all the benefits of having your files accessible through Nextcloud while keeping them in their original location - perfect for saving disk space!