Dropbox on Linux with encrypted home directory

Dropbox dropped support for all files systems except ext4 on Linux. This is a problem for everybody using an encrypted home directory since those are usually mounted via ecryptfs or similar. The following workaround makes use of an ext4 formatted file system image that is mounted via a loopback device upon login.

Step 1: create a mount point and make it read-only if not mounted

mkdir remote/Dropbox
sudo chattr +i remote/Dropbox

Change the “remote” part of the paths if you prefer to place your Dropbox folder at a different location.

Step 2: create an image file and format it

Change 10G to something that corresponds to the space that you need in order to sync your Dropbox files:

truncate -s 10G remote/.Dropbox.ext4

Alternative way of creating the image using dd:

dd if=/dev/zero of=remote/.Dropbox.ext4 count=10240 bs=1048576

Format the image with ext4:

mkfs.ext4 -F remote/.Dropbox.ext4

Step 3: create an entry in /etc/fstab

/home/<username>/remote/.Dropbox.ext4 /home/<username>/remote/Dropbox ext4 user,noauto,rw,loop,x-gvfs-hide 0 0

We use the parameter x-gvfs-hide to avoid showing the folder in sidebar of the file manager.

Step 4: use a systemd user service to mount the Dropbox image upon user login

Create the file .config/systemd/user/mountdropbox.service with the following content:

Description=Mounts a Dropbox ext4 image in the home directory of a user

ExecStart=/bin/mount %h/remote/Dropbox
ExecStop=/bin/umount %h/remote/Dropbox


Now lets enable and start the service. Slashes must be replaced by dashes if used as systemd parameters.

systemctl --user enable mountdropbox.service
systemctl --user start mountdropbox.service

After executing the commands above the service will be started (i.e., the Dropbox folder will be mounted) automatically upon user login.

Note for Ubuntu 18.04 or newer: for some reason systemd seems to “forget” the user service after reboot. Please check the comments of this blog post for a solution to this.

We also make sure that we own the mounted folder:

sudo chown <username>:<username> remote/Dropbox

Step 5: tell Dropbox to move your files to the new location

You can use the Dropbox GUI to move the Dropbox folder location to the newly created one.

The way how Dropbox detects the file system in use is a bit awkward as it does not let you choose the mount point itself as Dropbox folder location, instead you need to sync to a subfolder. So if you mount point is remote/Dropbox you need to sync to remote/Dropbox/<username> or something like that as Dropbox does not believe that the mount point is an ext4 file system.

Optional: grow the Dropbox image if you need more space

On the command line run the following commands (change 15G to something appropriate for your needs, but never change it to a lower size than your existing image as this cuts of the image which may lead to data loss):

dropbox stop
systemctl --user stop mountdropbox.service
truncate -s 15G remote/.Dropbox.ext4
fsck.ext4 -f remote/.Dropbox.ext4
resize2fs remote/.Dropbox.ext4
systemctl --user start mountdropbox.service
dropbox start

9 thoughts on “Dropbox on Linux with encrypted home directory

  1. Tom Celuszak

    Many thanks for this. A first attempt following someone else’s recipe failed. This – in combo with Dropbox instructions (ignoring their error therein…) to reset the local Dropbox folder path – got the daemon up and running and it’s now busy syncing.

  2. Matt

    Thank you. Dropbox works again!

    One Issue:
    After reboot the service is not started automatically. I have to enable and start it manually every time after boot.

    Any idea? I’m on ubuntu 18.10

    1. Hannes Post author

      You are right, this seems to be a problem starting with 18.04 (or perhaps even earlier) since this seems to work with 16.04. I need to investigate what exactly has changed in systemd that causes this. Until then you could mount the Dropbox image via a script that you call from “Startup Applications”.

      1. Matt

        In Startup Applications I modified the Dropbox Command to this script. Works fine.

        systemctl --user enable mountdropbox.service
        systemctl --user start mountdropbox.service
        dropbox start -i
      2. Matt

        One more thing: Dropbox kept overwriting the startup entry.

        1. rename the file ~/.config/autostart/dropbox.desktop into: start_dropbox.desktop
        2. in Dropbox preferences, untick “Start Dropbox on startup”
        3. restart Dropbox
        3. In the folder ~/.config/autostart, remove the original dropbox.desktop if it is still there.

  3. Tom C

    Hey, you’ve solved my problem. Was going to get back to this, especially since my old laptop has started losing track of its wireless card and keep needing a restart! Thanks to you both.

  4. Tom C

    A few more details on applying Matt’s fix. I finally created a script in ~/.config/autostart, file extension “.sh” as it’s a bash script. As “.desktop”, it kept getting overwritten with startup app “desktop” details. Gave the script execute permission. Using Startup Applications app, added the script to the list of startup apps, and saw a file with “.sh.desktop” extension get added to the autostart folder. This file points to the script as an executable. Had earlier switched off “Start Dropbox on startup”, as advised. It now has worked through a few restarts, so I think it’s time to apply the whole fix to my other Ubuntu computer.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.