Automount systemd unit needs a restart to work on every boot

Hi,
I followed the two articles to set up both systemd-mount and systemd-automount unit for a samba share:

The content is like below:
mount unit:

[Unit]
Description=samba server

[Mount]
What=//sambaserver/esom
Where=/home/esom
Type=cifs
Options=_netdev,iocharset=utf8,rw,file_mode=0777,dir_mode=0777,credentials=/etc/samba/esom.credential
TimeoutSec=30

[Install]
WantedBy=multi-user.target

And the automount unit is like below:

[Unit]
Description=Automount samba server

[Automount]
Where=/home/esom
TimeoutIdleSec=600

[Install]
WantedBy=multi-user.target

I enabled the automount unit and it seems to work fine. Every time I access /home/esom, it will mount the samba share for me.
However, after the successful setup, the automount unit failed to work at the next time I turned on the computer. Entering /home/esom shows empty folder. I need to restart the automount unit by

sudo systemctl daemon-reload
sudo systemctl restart home-esom.automount

to make the automount works until the next boot.
Does anyone know what keeps the unit from working automatically? I check the unit status on a fresh boot and it shows the unit was loaded, active, and waiting, so I suppose it was successfully loaded, but didn’t work for some reason.
Any advice would be appreciated.

What does the log say about this unit?

Hi,
How do I check its log? I type

sudo journalctl -b 0 |grep home-esom

but it shows nothing.

The Where looks troubling.

I assume that esom is your username - essentially when mounting a share onto a folder with existing files you will hide the existing files with the content from the share.

There is another method which makes use of gvfs and thus does not require any system modifications to work.

Hi,
Thanks for your reply. I created a folder called /home/esom specifically, which doesn’t belong to any user. The reason is I want to keep my / tidy.

So you have the following files located in /etc/systemd/system

home-esom.mount

[Unit]
Description=samba server

[Mount]
What=//sambaserver/esom
Where=/home/esom
Type=cifs
Options=_netdev,iocharset=utf8,rw,file_mode=0777,dir_mode=0777,credentials=/etc/samba/esom.credential
TimeoutSec=30

[Install]
WantedBy=multi-user.target

home-esom.automount

[Unit]
Description=Automount samba server

[Automount]
Where=/home/esom
TimeoutIdleSec=600

[Install]
WantedBy=multi-user.target

And the only unit enabled is the autoumount unit?

Yes. That’s correct. It seems to work correctly but I need to restart the automount unit on every boot to make it work.

That shouldn’t be necessary - when you say restart I am thinking - permissions.

Only when you are logged onto the system you can restart the service - which would then mount correctly.

This could be an indications of the mount path not being available until you have logged in.

What is the permissions /home/esom when share is not mounted?

The permission of that folder is 755

ls -la /home/esom                                                                                                                                                                                                                                                           2 ✘ 
總用量 9
drwxr-xr-x 2 root root 2 Feb 28 15:01 .
drwxr-xr-x 7 root root 7 Feb 28 15:01 ..

As a mean to an end - troubleshoot this by copying your units - start with the mount unit

sudo cp /etc/systemd/system/home-esom.mount /etc/systemd/system/data-esom.mount

Edit the new file and change the mount point in the to be /data/esom

Where=/data/esom

Then start the mount

sudo systemctl start data-esom.mount

systemd should now have created the mountpoint in /data/esom and you should be able to navigate the share - verify the content.

Then stop the unit

sudo systemctl stop data-esom.mount

Now copy your automount unit

sudo cp /etc/systemd/system/home-esom.automount /etc/systemd/system/data-esom.automount

Make the same modification

Where=/data/esom

Then enable the unit

sudo systemctl enable data-esom.automount

And restart your system

reboot

When rebooted and you are logged in - navigate the folder - /data/esom

If your system behaves as expected - using the /data/esom mount point - then you know that your other choice of mountpoint is directly causing your malfunction.

I actually had the same problem, but i was doing it via fstab so i am not sure how much it is applicable to your issue.

SInce you seemingly want to run a homefolder over network i think the WantedBy is ok otherwise i would get rid of it. Also, since it is over network you should add

After=network.target
Requires=network.target

to the mount file under the [Unit] tag. I also added the vers under Options.

For reference here are the units that got generated by systemd from my fstab:
Mount Unit:

# Automatically generated by systemd-fstab-generator

[Unit]
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
SourcePath=/etc/fstab
After=network.target
Requires=network.target

[Mount]
What=//server/folder
Where=/mount/point
Type=cifs
Options=x-systemd.automount,vers=3.0,x-systemd.requires=network.target,uid=1000,credentials=/path/to/credentials,nofail,_netdev

Automount Unit

# Automatically generated by systemd-fstab-generator

[Unit]
SourcePath=/etc/fstab
Documentation=man:fstab(5) man:systemd-fstab-generator(8)

[Automount]
Where=/mount/point

If you still have trouble could you please post the systemctl status of the unit in question after booting?

1 Like

Something I learned the hard way - when adding _netdev to options you don’t need network.target as this is implied by _netdev

Normally you would not need even that, since systemd has a list of filesystems, that it automatically assumes for, that they need network access afaik. In any case there is no harm done by specifying either of it.

It was producing longer startup time and a lot of errors in the log.

It turned out that adding network.target to a mount unit created a dependency loop which would be removed by only using _netdev - which would cause systemd to create the correct dependency tree.

Hi,
I change the mount point to /data/esom and now it works without restarting the service. It’s really strange that things can happen like this even the permission of the two folders are the same.
@linux-aarhus maybe you can edit the tutorials about this notion.

If one wants to deviate and create another structure - it is your system - thus your decision.

The tutorials all uses the /data/ tree - and I can see no reasonable explanation to why your initial mountpoint didn’t work. I have explanation - I have an idea but it is far fetched.

This is purely guess work - I guess it didn’t work - could be because the /home tree is an important location for the system. Maybe systemd assumes that folders mounted in /home is a users home and it is entirely possible to have a networked home.

There is a service called systemd-homed which allows for portable home folders. If a folder is mounted inside /home - systemd may just think - this is a user’s home - but I have no user with them name - just to be safe I won’t allow mounts which is not a user’s home.

As there is no explicit rules as to which structure you can choose - although there is some locations which should be avoided due to they volatile nature or specific use.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.