64

I'm trying to run:

sudo mount -t cifs //user.my-backup.com /mnt/wal_drive -o iocharset=utf8,rw,credentials=/etc/backupcredentials.txt,uid=postgres,gid=postgres,file_mode=0660,dir_mode=0770

However I keep on getting the following error:

mount error(22): Invalid argument
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

What am I doing wrong?

  • 1
    Two possible problems: your source is an URL which either may not resolve or is not advertising Samba; and, the uid/gid need to be expressed numerically. Have you read the referred man page? – douggro Feb 27 '14 at 15:57
  • 10
    Mount should really return a better error message. Knowing which argument is invalid would make this error message so much more helpful. – Gregory Arenius Jul 06 '18 at 21:23
  • 1
    Mount gives a generic error because the details are in the log. As it is said below, use tail -f /var/log/kern.log to understand what's going on. – Sam Feb 13 '19 at 11:29
  • 3
    dmesg | tail tells you a bit more about which option is giving you trouble. – HongboZhu Jul 15 '19 at 12:24

9 Answers9

82

maybe this helps with this, mount error(22): Invalid argument... possible error is the argument/s (mode) on mount command.

  1. check your logs on the errors encountered.

    tail -f  /var/log/kern.log 
    
  2. remove the invalid argument

Avinash Raj
  • 78,556
  • 11
    This worked for me. I found the error CIFS not working, kernel upgrade:No dialect specified on mount and resolved it by [adding] vers=1.0 to my /etc/fstab(https://bbs.archlinux.org/viewtopic.php?id=230952). I suspect it is caused by using kernel 4.13. – blaha Nov 13 '17 at 23:27
  • 1
    Jeez, thank goodness for stackoverflow. Same problem on ubuntu. I added vers=2.0 and it works. Current mount.cifs is at 6.4. Probably some enhancements to credentials but not digging into CIFS now... – dturvene Jun 08 '18 at 13:15
16

Another possible cause is the presence of sec=ntlm in /etc/fstab and it's incompatibility with newer SMB protocols like SMB3.

While not the OP's case, this can also cause mount error(22): Invalid argument errors, as it did for me after upgrading an old server.

Even though kern.log includes a suggestion to specify vers=1.0 on mount, it may be safer to remove or change sec=ntlm instead. Perhaps use the defaults to allow automatic negotiation of the SMB version and security, or specify compatible options such as vers=3.0,sec=ntlmssp.

Obviously this depends on your SMB server's features, but I would try and avoid vers=1.0 unless necessary.

drgrog
  • 2,867
  • 1
    This worked for me. I have a Synology DS918+. Enabled SMB3 on the NAS. Set vers=3.0 parameter and removed the sec=ntlm parameter. Thanks. – dgnorton Apr 12 '20 at 14:48
  • 1
    You answer was very helpful to me. I removed sec=ntlm completely and then all my drives mounted. Thank you. – Lonnie Best May 09 '20 at 04:55
10

I had the same issue on Arch Linux, with this message in log:

kernel: CIFS VFS: cifs_mount failed w/return code = -22

For me the solution was to specify older version of cifs (by default it was 3.0):

/etc/fstab:

//my-router/share /media/share cifs ver="2.1",rw,soft,uid=ele,gid=ele,file_mode=0770,dir_mode=0770,credentials=/etc/router-credentials.conf 0 0
Zanna
  • 70,465
  • Could you please explain your command? what "soft" , uid and other parts mean? – Luke Feb 21 '20 at 07:24
  • 1
  • soft - The program accessing a file on the cifs mounted file system will not hang when the server crashes and will return errors to the user application.
  • uid and gid - sets the uid that will own all files or directories on the mounted filesystem when the server does not provide ownership information.
  • file_mode and dir_mode works the same way as uid and gid.
  • 0 0 these fields are not used, and by convention set to 0
  • For more information please see mount.cifs man

    – Igor Golovin Feb 22 '20 at 10:43