You are not logged in.

#1 2014-06-23 20:51:36

Varemenos
Member
From: Greece
Registered: 2011-09-01
Posts: 24
Website

[Solved] sshfs can't mount via fstab on startup

I have an HDD mounted in my RPI which I've mounted as a filesystem in my desktop via sshfs (through fstab).
If I do "sudo mount -a", it seems to mount just fine, so I researched a bit (even though I'm still an newbie in Arch and Linux distros in general) and found out that it's most probably is caused due to the network not being initialized fast enough for the sshfs fstab entry to be discovered (due to having no network and therefore no access to it).

I'm really not sure how to provide any info which would help you guyz help me so I'm just gonna provide the sshfs entry from my fstab file and the journalctl logs that seem to be relevant.

...
Jun 23 22:32:00 home systemd[1]: home-username-media-downloads-mydrive.mount mount process exited, code=exited status=1
Jun 23 22:32:00 home systemd-udevd[168]: renamed network interface eth0 to enp0s25
Jun 23 22:32:00 home systemd[1]: Failed to mount /home/username/media/downloads/mydrive.
Jun 23 22:32:00 home systemd[1]: Dependency failed for Remote File Systems.
Jun 23 22:32:00 home systemd[1]: Unit home-username-media-downloads-mydrive.mount entered failed state.
Jun 23 22:32:00 home dhcpcd[236]: eth0: waiting for carrier
Jun 23 22:32:00 home dhcpcd[236]: eth0: removing interface
...
sshfs#pi@192.168.2.86:/media/mydrive/     /home/username/media/downloads/mydrive    fuse    IdentityFile=/home/username/.ssh/mykey,uid=1000,gid=1000,reconnect,_netdev,allow_other,transform_symlinks,user,idmap=user,BatchMode=yes 0 0

ps: This issue might be related to a recent attempt I've had to enable? the Gnome NetworkManager service, I'm not sure if it's related but I've first noticed the issue the same day I tried to enable that service (which I've later disabled because I couldn't get my network connected).

Last edited by Varemenos (2014-06-27 23:44:00)

Offline

#2 2014-06-25 07:21:56

catalin
Member
From: Romania
Registered: 2014-06-25
Posts: 18
Website

Re: [Solved] sshfs can't mount via fstab on startup

I believe that you sshfs cannot be mounted at boot because when /etc/fstab is mounted you have no network connectivity , as a workaround you can create a service using systemd and mount it after your network is up  .


___________________
Adevarul se afla dincolo de noi ...
IT Engineer

Offline

#3 2014-06-25 08:00:08

Varemenos
Member
From: Greece
Registered: 2011-09-01
Posts: 24
Website

Re: [Solved] sshfs can't mount via fstab on startup

Can i make the systemd service run after the network is connected?

Offline

#4 2014-06-25 08:34:42

catalin
Member
From: Romania
Registered: 2014-06-25
Posts: 18
Website

Re: [Solved] sshfs can't mount via fstab on startup

of course , take a look on this thread : https://bbs.archlinux.org/viewtopic.php?id=171496


something like this

[Unit]
Description=Mount file for /mnt/media sshfs mount
Requires=network-online.target
After=netctl@eth0.service

[Mount]
What=user@hostname:/mnt/media
Where=/mnt/media
Type=fuse.sshfs
Options=noauto,user,idmap=user,allow_other,Port=5000,IdentityFile=/home/firecat53/.ssh/test_rsa

Last edited by catalin (2014-06-25 08:42:30)


___________________
Adevarul se afla dincolo de noi ...
IT Engineer

Offline

#5 2014-06-25 09:19:05

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,624
Website

Re: [Solved] sshfs can't mount via fstab on startup

'sshfs#...' and similar fuse-related syntax has been depreciated for a while now, and systemd doesn't treat it as a valid line.

See 'man mount' for details on how to correctly specify subtypes in fstab (sshfs is a subtype of fuse).

Of course, writing a mount unit is a perfectly valid solution too.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#6 2014-06-25 10:05:08

Varemenos
Member
From: Greece
Registered: 2011-09-01
Posts: 24
Website

Re: [Solved] sshfs can't mount via fstab on startup

Hey, WorMzy I've tried what you suggest but it's still not mounting at boot.

pi@192.168.2.86:/media/mydrive/    /home/username/media/mydrive    fuse.sshfs    IdentityFile=/home/username/.ssh/mykey,uid=1000,gid=1000,reconnect,_netdev,allow_other,transform_symlinks,user,idmap=user,BatchMode=yes    0 0

So for systemd, I just create a systemd mountdrive.service and place it in `/etc/systemd/system` and then `# systemctl enable mountdrive.service`?

Sorry but I'm not familiar with systemd.

Offline

#7 2014-06-26 07:30:24

catalin
Member
From: Romania
Registered: 2014-06-25
Posts: 18
Website

Re: [Solved] sshfs can't mount via fstab on startup

place mountdrive.service file in /lib/usr/systemd/system/
then
systemctl enable mountdrive.service
also you can add

[Service]
.......
Restart=on-failure
RestartSec=10
.......

to try remound if network goes down (for any reason)


___________________
Adevarul se afla dincolo de noi ...
IT Engineer

Offline

#8 2014-06-26 08:30:56

Varemenos
Member
From: Greece
Registered: 2011-09-01
Posts: 24
Website

Re: [Solved] sshfs can't mount via fstab on startup

It doesn't seem to work...

Jun 26 11:30:32 home systemd[1]: [/etc/systemd/system/mydrive.service:5] Unknown section 'Mount'. Ignoring.
Jun 26 11:30:32 home systemd[1]: mydrive.service lacks ExecStart setting. Refusing.

Here is the service file:

[Unit]
Description=mydrive Sshfs mount
Requires=network-online.target
After=netctl@eth0.service
[Mount]
What=pi@192.168.1.86:/media/mydrive/
Where=/home/username/media/downloads/mydrive
Type=fuse.sshfs
Options=IdentityFile=/home/username/.ssh/mykey,uid=1000,gid=1000,reconnect,_netdev,allow_other,transform_symlinks,user,idmap=user,BatchMode=yes
[Service]
Restart=on-failure
RestartSec=10

Last edited by Varemenos (2014-06-26 08:32:24)

Offline

#9 2014-06-26 08:41:07

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,624
Website

Re: [Solved] sshfs can't mount via fstab on startup

You're want to write a mount file, not a service.

See 'man systemd.mount' for details, and /run/systemd/generator/ for real-life examples generated based on your fstab.

You might also want to check why the fstab entry you wrote above doesn't work.

systemctl status home-username-media-mydrive.mount

Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#10 2014-06-26 08:45:28

Varemenos
Member
From: Greece
Registered: 2011-09-01
Posts: 24
Website

Re: [Solved] sshfs can't mount via fstab on startup

Ok great, thanks.

It seems like the remote rejects the connection request:

Jun 26 10:37:31 home mount[263]: read: Connection reset by peer
Jun 26 10:37:31 home systemd[1]: home-username-media-mydrive.mount mount process exited, code=exited status=1

Offline

#11 2014-06-26 08:57:07

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,624
Website

Re: [Solved] sshfs can't mount via fstab on startup

Odd. Does 'mount -a' still work?


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#12 2014-06-26 09:36:57

Varemenos
Member
From: Greece
Registered: 2011-09-01
Posts: 24
Website

Re: [Solved] sshfs can't mount via fstab on startup

Ya, mount -a works just fine.
Could this be caused by the ssh-key being added to the ssh-agent after the initial connection?

Offline

#13 2014-06-26 10:48:37

catalin
Member
From: Romania
Registered: 2014-06-25
Posts: 18
Website

Re: [Solved] sshfs can't mount via fstab on startup

according http://www.freedesktop.org/software/sys … mount.html try rename /lib/usr/systemd/system/mydrive.service to /lib/usr/systemd/system/mydrive.mount


___________________
Adevarul se afla dincolo de noi ...
IT Engineer

Offline

#14 2014-06-26 11:26:19

Varemenos
Member
From: Greece
Registered: 2011-09-01
Posts: 24
Website

Re: [Solved] sshfs can't mount via fstab on startup

The '/lib/usr/' directory doesn't exist. I've put them in /etc/systemd/system

Also, it seems like the issue was related to the filename, I've renamed it to home-username-media-mydrive.mount (WorMzy mentioned it but I didn't seem to notice before) and it starts successfully, now Im gonna see if it mounts in reboot and edit this post with the results.

Offline

#15 2014-06-26 11:28:27

catalin
Member
From: Romania
Registered: 2014-06-25
Posts: 18
Website

Re: [Solved] sshfs can't mount via fstab on startup

sry , there was a misspell in the other posts , the correct path will be /usr/lib/systemd/system/ , let me know if will auto mount on boot .

Last edited by catalin (2014-06-26 11:28:38)


___________________
Adevarul se afla dincolo de noi ...
IT Engineer

Offline

#16 2014-06-26 12:27:55

catalin
Member
From: Romania
Registered: 2014-06-25
Posts: 18
Website

Re: [Solved] sshfs can't mount via fstab on startup

hi

just try this scenario on my test env

you will need to name the file according to your mount name /!\ THIS IS VERY IMPORTANT /!\ . for you - home-username-media-downloads-mydrive.mount

nano  /usr/lib/systemd/system/home-username-media-downloads-mydrive.mount

[Unit]
Description=mydrive Sshfs mount
Requires=network-online.target
After=netctl@br0.service

[Mount]
What=pi@192.168.1.86:/media/mydrive/
Where=/home/username/media/downloads/mydrive
Type=fuse.sshfs
Options=IdentityFile=/home/username/.ssh/mykey,uid=1000,gid=1000,reconnect,_netdev,allow_other,transform_symlinks,user,idmap=user,BatchMode=yes

[Install]
WantedBy=multi-user.target

Please adapt any of your env to the file .

thanks


___________________
Adevarul se afla dincolo de noi ...
IT Engineer

Offline

#17 2014-06-26 13:01:31

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,624
Website

Re: [Solved] sshfs can't mount via fstab on startup

catalin, you shouldn't be doing anything in /usr/lib/systemd/, /etc/systemd is the correct place for user generated modifications. This doesn't matter so much in this case, but any new files you create in /usr/lib/systemd may cause conflicts in the future, and any modifications you make will be overwritten by updates to the packages that own them.

Please also use [ code ] tags when posting blocks of text files like that, it makes it much easier to read.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#18 2014-06-26 13:49:20

Varemenos
Member
From: Greece
Registered: 2011-09-01
Posts: 24
Website

Re: [Solved] sshfs can't mount via fstab on startup

It just doesn't want to work...

# systemctl status home-username-media-downloads-mydrive.mount

==>

● home-username-media-downloads-mydrive.mount - mydrive Sshfs mount
   Loaded: loaded (/etc/systemd/system/home-username-media-downloads-mydrive.mount; enabled)
   Active: failed (Result: exit-code) since Thu 2014-06-26 16:45:21 EEST; 31s ago
    Where: /home/username/media/downloads/mydrive
     What: pi@192.168.1.86:/media/mydrive/
  Process: 281 ExecMount=/bin/mount pi@192.168.1.86:/media/mydrive/ /home/username/media/downloads/mydrive -t fuse.sshfs -o IdentityFile=/home/username/.ssh/mykey,uid=1000,gid=1000,reconnect,_netdev,allow_other,transform_symlinks,user,idmap=user,BatchMode=yes (code=exited, status=1/FAILURE)

Jun 26 16:45:21 home mount[281]: read: Connection reset by peer
Jun 26 16:45:21 home systemd[1]: home-username-media-downloads-mydrive.mount mount process exited, code=exited status=1
Jun 26 16:45:21 home systemd[1]: Failed to mount mydrive Sshfs mount.
Jun 26 16:45:21 home systemd[1]: Unit home-username-media-downloads-mydrive.mount entered failed state.

The file:

[Unit]
Description=mydrive Sshfs mount
Requires=network-online.target
After=netctl@enp0s25.service
[Mount]
What=pi@192.168.1.86:/media/mydrive/
Where=/home/username/media/downloads/mydrive
Type=fuse.sshfs
Options=IdentityFile=/home/username/.ssh/mykey,uid=1000,gid=1000,reconnect,_netdev,allow_other,transform_symlinks,user,idmap=user,BatchMode=yes
[Service]
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target

Note that running

systemctl start home-username-media-downloads-mydrive.mount

, works just fine...

Last edited by Varemenos (2014-06-26 14:00:23)

Offline

#19 2014-06-26 14:00:36

catalin
Member
From: Romania
Registered: 2014-06-25
Posts: 18
Website

Re: [Solved] sshfs can't mount via fstab on startup

you can remove

[Service]
Restart=on-failure
RestartSec=10

it seems is not working for mounts ,


What error message you get if you run

/bin/mount pi@192.168.1.86:/media/mydrive/ /home/username/media/downloads/mydrive -t fuse.sshfs -o IdentityFile=/home/username/.ssh/mykey,uid=1000,gid=1000,reconnect,_netdev,allow_other,transform_symlinks,user,idmap=user,BatchMode=yes

___________________
Adevarul se afla dincolo de noi ...
IT Engineer

Offline

#20 2014-06-26 14:05:05

Varemenos
Member
From: Greece
Registered: 2011-09-01
Posts: 24
Website

Re: [Solved] sshfs can't mount via fstab on startup

It's exactly the same:

read: Connection reset by peer

Offline

#21 2014-06-26 14:13:38

catalin
Member
From: Romania
Registered: 2014-06-25
Posts: 18
Website

Re: [Solved] sshfs can't mount via fstab on startup

i manage to reproduce the "read: Connection reset by peer" error , something is wrong with your ssh key , could you please double check if /home/username/.ssh/mykey exist and work ?


___________________
Adevarul se afla dincolo de noi ...
IT Engineer

Offline

#22 2014-06-26 14:18:20

Varemenos
Member
From: Greece
Registered: 2011-09-01
Posts: 24
Website

Re: [Solved] sshfs can't mount via fstab on startup

Yep, there is no other way to mount the drive via ssh without using the key.
The only logical issue that I can think of, is the key not being added to the key-agent for the user that tries to run the systemd script?

Offline

#23 2014-06-26 14:32:55

catalin
Member
From: Romania
Registered: 2014-06-25
Posts: 18
Website

Re: [Solved] sshfs can't mount via fstab on startup

try to exclude IdentityFile=/home/username/.ssh/mykey, from command

and store phe private key under : /root/.ssh/id_rsa

Last edited by catalin (2014-06-26 14:36:23)


___________________
Adevarul se afla dincolo de noi ...
IT Engineer

Offline

#24 2014-06-26 16:13:52

Varemenos
Member
From: Greece
Registered: 2011-09-01
Posts: 24
Website

Re: [Solved] sshfs can't mount via fstab on startup

Isn't the root user the one that executes the systemd unit file?
Cause I can now run the /bin/mount command successfully but it still won't mount on boot (stating the same error)...

Last edited by Varemenos (2014-06-26 16:14:06)

Offline

#25 2014-06-26 18:05:29

catalin
Member
From: Romania
Registered: 2014-06-25
Posts: 18
Website

Re: [Solved] sshfs can't mount via fstab on startup

the service runs as root , and by default will look in /root/.ssh/id_rsa as ssh key


___________________
Adevarul se afla dincolo de noi ...
IT Engineer

Offline

Board footer

Powered by FluxBB