You are not logged in.

#1 2012-08-08 03:32:20

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

[SOLVED] Systemd automounting sshfs shares

Hey all...recently converted successfully to systemd with the exception of automounting sshfs shares. 'systemctl list-units' is here  and /etc/fstab is here.  The wiki just mentions adding the comment= line in fstab which I have done. Is there a service file that I also need to enable first? If I change to the directory or try to ls the directory it just stays empty...no change in mount status. All 3 mounts work fine when issuing 'mount <mountpoint>' as user.

What am I missing here? Any other logs/files that I need to provide? I'm still trying to wrap my brain around all these systemd'isms smile

Thanks!
Scott

Last edited by firecat53 (2012-10-28 22:20:56)

Offline

#2 2012-08-12 01:11:02

erikw
Member
From: Lund, Sweden
Registered: 2012-07-17
Posts: 17
Website

Re: [SOLVED] Systemd automounting sshfs shares

I'm in the same situation.

Edit.

I got it to work now by using

comment=systemd.automount

instead of the following, what I believed was the correct, format

comment=x-systemd.automount

Last edited by erikw (2012-08-12 01:29:58)

Offline

#3 2012-08-12 11:29:11

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [SOLVED] Systemd automounting sshfs shares

the correct format is "x-systemd.automount" (without the comment= !). The old "comment=systemd.automount" still works but is not documented anymore, so I guess it may be removed in the future.

Offline

#4 2012-08-12 17:47:15

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED] Systemd automounting sshfs shares

Hmm, if I use comment=systemd.automount, it tries to work but fails like:

ls /mnt/media
ls: cannot open directory /mnt/media: No such device

journalctl (applicable entries):

Aug 12 10:32:17 scotty systemd[1]: mnt-media.mount mount process exited, code=exited status=1

Aug 12 10:32:17 scotty systemd[1]: Unit mnt-media.mount entered failed state.

......<repeated several more times>
$ mount | grep media
$ systemd-1 on /mnt/media type autofs (rw,relatime,fd=33,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)

I don't need autofs installed do I? I've never seen that type before in a mount entry.

If I use the 'correct' x-systemd.automount, there are absolutely no related entries in the logs...it doesn't try to mount or automount the shares at all!

Mind sharing your fstab entries and systemctl outputs so I can see if I've got something else messed up?

Thanks,
Scott

Last edited by firecat53 (2012-08-12 18:23:58)

Offline

#5 2012-08-13 19:45:29

erikw
Member
From: Lund, Sweden
Registered: 2012-07-17
Posts: 17
Website

Re: [SOLVED] Systemd automounting sshfs shares

@65kid: Is that format suppose to work now or is it to be implemented in the future? Because it does not work for me.

@firecat53:

$ cat /etc/fstab
...
usr@host:/home/usr /mnt/ssh/host fuse.sshfs noauto,comment=systemd.automount,noatime,nonempty,nosuid,noexec,nodev,allow_other,max_read=65536,follow_symlinks	0	0

Offline

#6 2012-08-13 20:22:33

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [SOLVED] Systemd automounting sshfs shares

This works for me:

sshfs#user@host: /mountpoint fuse x-systemd.automount,defaults,noauto,intr,allow_other 0 0

ᶘ ᵒᴥᵒᶅ

Offline

#7 2012-08-13 20:36:04

erikw
Member
From: Lund, Sweden
Registered: 2012-07-17
Posts: 17
Website

Re: [SOLVED] Systemd automounting sshfs shares

If I remove "x-" that line works for me too. This is strange. And my system is up to date.

Last edited by erikw (2012-08-13 20:36:30)

Offline

#8 2012-08-14 00:45:02

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED] Systemd automounting sshfs shares

Well...still not working for sshfs. If I use 'comment=systemd.automount' in the fstab line for a LOCAL hard drive, it works:

/dev/mapper/laptop-backup	/mnt/backup	ext4 	noauto,comment=systemd.automount,noatime,users,exec,data=ordered	0 2

x-systemd.automount has no effect.

@litemotiv: according to the man pages, the 'sshfs#user@host <dir> fuse' .....  format is deprecated in favour of sshfs.fuse. However, I did try it and am still getting the 'no such device' errors.

I wonder....do any of you use ssh-agent/keychain with a passphrase for your keys? I do, and also non-standard ssh port. I wonder if the ssh-agent is the issue, because typically scripts need to source the keys prior to use (eval `keychain --noask --eval --agents ssh` or equivalent for ssh-agent). Any thoughts? Would it be possible to source those keys using a custom mount unit file?

Scott

Offline

#9 2012-08-14 07:57:43

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [SOLVED] Systemd automounting sshfs shares

firecat53 wrote:

I wonder....do any of you use ssh-agent/keychain with a passphrase for your keys? I do, and also non-standard ssh port. I wonder if the ssh-agent is the issue, because typically scripts need to source the keys prior to use (eval `keychain --noask --eval --agents ssh` or equivalent for ssh-agent). Any thoughts? Would it be possible to source those keys using a custom mount unit file?

I think that might be the cause of your problems... i don't use ssh-agent myself, but in my ssh_config i do have:

Host server1 server2 server3
    Port #####
    IdentityFile /home/user/.ssh/id_dsa

for the custom port and identity file.

Have you tried something like this for the ssh-agent part?


ᶘ ᵒᴥᵒᶅ

Offline

#10 2012-08-14 15:14:51

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED] Systemd automounting sshfs shares

set the SSH_AUTH_SOCK environment variable in the environment of the sshfs process

Heh, that'd be great, but there's no explanation of how to actually accomplish this. My sshfs mounts work fine normally with ssh-agent/keychain with this fstab entry:

homeserver:/mnt/media		/mnt/media	fuse.sshfs	noauto,idmap=user	0	0

Maybe I'll have a look at writing a systemd mount file and see if that'll work. Unless someone has one laying around already! tongue

Thanks,
Scott

EDIT: Progress!

1. Created a passwordless ssh key test_rsa
2. Created mnt-media.mount and mnt-media.automount unit files:

mnt-media.automount

[Unit]
Description=Automount /mnt/media sshfs

[Automount]
Where=/mnt/media
DirectoryMode=0775

mnt-media.mount

[Unit]
Description=Mount file for /mnt/media sshfs mount

[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

Success!

3. Then applied this to /etc/fstab:

firecat53@hostname:/mnt/media		/mnt/media	fuse.sshfs 	noauto,comment=systemd.automount,user,idmap=user,Port=5000,IdentityFile=/root/.ssh/test_rsa,allow_other		0	0

and also got Success!

4. So....to summarize:
  - Unit mount files work the same as /etc/fstab entries (as they should)
  - For sshfs mounts, it doesn't appear to respect entries in ~/.ssh/config. You have to explicitly put the ssh parameters into fstab or the unit file
  - The x-systemd.automount setting doesn't work. Still have to use comment=systemd.automount in fstab
  - I don't know how to get ssh-agent passphrases pulled into systemd automounts.

Last edited by firecat53 (2012-08-14 17:15:46)

Offline

#11 2012-10-28 22:20:40

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED] Systemd automounting sshfs shares

Sorry forgot about this thread. Solved with this in /etc/fstab:

firecat53@home.net:/mnt/media		/mnt/media	fuse.sshfs 	noauto,x-systemd.automount,users,idmap=user,Port=22,IdentityFile=/home/firecat53/.ssh/id_rsa,allow_other,reconnect		0	0

Scott

Offline

#12 2012-12-05 21:57:57

grine
Member
Registered: 2010-02-09
Posts: 38

Re: [SOLVED] Systemd automounting sshfs shares

I used the same line as firecat53 but would get "peer disconnected" I solved it by adding the server key to roots trusted keys, now it works great.

Offline

#13 2013-01-23 03:54:51

whatshisname
Member
Registered: 2010-04-24
Posts: 162

Re: [SOLVED] Systemd automounting sshfs shares

Thanks, Firecat.  Thatnks to your advice, I'm finally automounting my sshfs shares on boot.  The trick was the creation of the .mount and .automount files in  /usr/lib/systemd/system.  This has been bugging me for weeks!

Just wanted to note I was able to automount *without* the "noauto" option you have in your  example .mount and fstab files.

Offline

#14 2013-01-25 21:43:11

whatshisname
Member
Registered: 2010-04-24
Posts: 162

Re: [SOLVED] Systemd automounting sshfs shares

Following up in this thread because it's the best around for automounting sshfs shares.

My previous post had to do with connecting my laptop to my Raspberry Pi to which I have an external drive connected.

When I tried to repeat what I did with my laptop with my desktop, I ran into all sorts of problems which I have spent hours trying to ferret out.

At first I was getting the "ls: cannot open directory /mnt/media: No such device" type error indicated above by Firecat.  I eventually discovered you can "umount /mnt/media" and that error will go away and a "ls /mnt/media" returned "total 0" as one would expect.  So it appeared I was halfway mounting the Pi but not quite.

Once I was past that, I could experiment with manually mounting my Pi per usual which I couldn't do as long as my desktop was mangling the mount operation.

I was using rsa authentication.  My normal user could ssh into my Raspberry Pi no problems.   But no matter what "mount -a" as root returned "read: Connection reset by peer" every single time.

Finally, I tried sshfs mounting the Pi as root using my normal user credentials and discovered I had a conflict in root's "known_hosts" file with my current Raspberry Pi.  (I had in fact, switched my old 256 meg Pi with my new 512 meg Pi and given them the same name and ip address.)  Once I had removed the offending entry, root could mount the Pi from the command line.  And "mount -a" started mounting the Pi as well.

I guess this is what Grine was getting at with his post but I thought I'd make it more explicit for those having this problem. 

So the take away here is:  if you're having problems automounting an sshfs share, make sure that both your normal user *and* root can mount your external host from the commandline using the "IdentityFile" as specified in your fstab line.

Hope this helps someone.

Offline

#15 2013-09-13 12:22:30

bobwya
Member
Registered: 2012-01-09
Posts: 36

Re: [SOLVED] Systemd automounting sshfs shares

firecat53 wrote:

set the SSH_AUTH_SOCK environment variable in the environment of the sshfs process

Heh, that'd be great, but there's no explanation of how to actually accomplish this. My sshfs mounts work fine normally with ssh-agent/keychain with this fstab entry:

homeserver:/mnt/media		/mnt/media	fuse.sshfs	noauto,idmap=user	0	0

Maybe I'll have a look at writing a systemd mount file and see if that'll work. Unless someone has one laying around already! tongue

Thanks,
Scott

EDIT: Progress!

1. Created a passwordless ssh key test_rsa
2. Created mnt-media.mount and mnt-media.automount unit files:

...

@firecat53

Eternal thanks!! I know this quite an old thread - but some problems never go away big_smile  I was trying to do the reverse (create an sshfs systemd mount unit that worked with my normal user). This post solved another problem I had (allowing root access to the mountpoint)... Kind-of this info was in either the Arch or Gentoo systemd wiki's - "front-and-centre" so to speak...

Thanks
Bob

Offline

Board footer

Powered by FluxBB