How to auto mount in Ubuntu 20.04

763 views
Skip to first unread message

Jaimala D

unread,
Nov 7, 2021, 11:18:19 AM11/7/21
to s3ql
Hello,
I am very new to linux(using for almost 15 days) and I am loving it.
I am stuck I am not able to find a guide how to auto mount s3ql after startup. I found few guides but they were of Upstart(which is discontinued).
If someone can help I will be really thankful.

Daniel Jagszent

unread,
Nov 7, 2021, 12:15:09 PM11/7/21
to s3ql
Hello Jaimala,

Ubuntu 20.04 uses systemd for startup scripts.
Normally mounting can be done via /etc/fstab or https://www.freedesktop.org/software/systemd/man/systemd.mount.html but both variants have problems when using them for S3QL.


So you should use a dedicated systemd service unit that has a Conflicts=shutdown.target property and an increased TimeoutStopSec property. With that it gets stopped before the system shuts down and does not get killed prematurely by systemd (otherwise the file system will get stopped while the system shuts down and you sometimes do not have enough time stop the file system – S3QL can take quite some time to stop since it needs to uploads all dirty blocks and its metadata to the cloud storage)

Here is the service unit I am using (for a backend "swiftks://my-backend-url" and a mount point /cloud/data):
/lib/systemd/system/cloud-data.service
[Unit]
Description=Mount s3ql file system
Requires=nss-lookup.target network.target time-sync.target
After=nss-lookup.target network.target network-online.target remote-fs-pre.target time-sync.target
Conflicts=shutdown.target
#ConditionPathIsDirectory=/cloud/data

[Service]
Type=notify
#Type=simple
ExecStartPre=/usr/local/sbin/pre-mount-cloud-data.sh
ExecStart=/usr/bin/mount.s3ql --fg --systemd --log none --allow-other --authfile /root/.s3ql/authinfo2 --keep-cache --backend-options=tcp-timeout=20,domain=default --compress zlib-6 --max-cache-entries 65536 "swiftks://my-backend-url" "/cloud/data"
ExecStop=/usr/bin/umount.s3ql "/cloud/data"
LimitNOFILE=65936
TimeoutStopSec=10min # <- increase when needed (big cache)
TimeoutStartSec=10min # <- increase when needed (big file system)

[Install]
WantedBy=multi-user.target


This unit file references pre-mount-cloud-data.sh. That is a little script that tries to repair the filesystem when it is needed. It is optional (just remove the ExecStartPre line) but quite useful.
/usr/local/sbin/pre-mount-cloud-data.sh
#!/bin/bash

# Check for a crashed S3QL
if ls "/cloud/data" 2>&1 | grep -Fq 'Transport endpoint is not connected'; then
  fusermount -u "/cloud/data"
fi

# Check and mount file system
echo executing fsck.s3ql --batch --log none --authfile /root/.s3ql/authinfo2 --keep-cache --backend-options=tcp-timeout=20,domain=default  "swiftks://my-backend-url"
/usr/bin/fsck.s3ql --batch --log none --authfile /root/.s3ql/authinfo2 --keep-cache --backend-options=tcp-timeout=20,domain=default  "swiftks://my-backend-url"
FSCK_RESULT=$?
if [[ $FSCK_RESULT != 0 && $FSCK_RESULT != 128 ]]; then
  echo "fsck.s3ql reported errors! exit code $FSCK_RESULT"
  exit $FSCK_RESULT
fi
exit 0




If you have a service that depend on the file system to be mounted, then create an overwrite file for its service unit and use "After=cloud-data.service" to start the service only when the file system was mounted.
E.g. for nginx execute "sudo systemctl edit nginx" paste the following in the editor and save&exit:
[Unit]
After=cloud-data.service


If your file system exits after the TimeoutStartSec then your system does not have the Python bindings for systemd installed. Either (a) try to install them with "apt-get install python3-systemd" or (b) use the Type=simple
line instead of the Type=notify line in the unit file. Variant (a) is preferred since only with it depending services (see above) work correctly.

You obviously need to change some arguments (e.g. the backend URL or the mount point) before you can use this unit file and its ExecPreStart helper script and you need to create the empty mount point directory once e.g. with "sudo mkdir -p /cloud/data".

Some pointers:
https://www.freedesktop.org/software/systemd/man/systemd.service.html
https://www.rath.org/s3ql-docs/mount.html#automatic-mounting
https://groups.google.com/g/s3ql/search?q=systemd%20mount
https://www.google.com/search?q=s3ql+systemd+mount
https://www.brightbox.com/docs/guides/s3ql/

Jaimala D

unread,
Nov 7, 2021, 12:37:49 PM11/7/21
to s3ql
Thank you so much. I really 💕 linux. Especially community.

Nikolaus Rath

unread,
Nov 9, 2021, 7:02:11 AM11/9/21
to s3...@googlegroups.com
Since you're new to Linux, I'd like to point out that what Daniel
described is "automatic mounting on system start". That's one definition
of "automatic", but not the only one. So it's good to me more exact.

For example, you could also attempt to automatically mount the
filesystem on access through https://linux.die.net/man/8/automount

(No idea if that works for S3QL, just pointing it out as an option).

Best,
-Nikolaus

--
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

»Time flies like an arrow, fruit flies like a Banana.«
Reply all
Reply to author
Forward
0 new messages