Harsh but fair

Open source chicanery and the battle with my inner geek

Samba Shares, Spaces and fstab (With a bit of Octal thrown in)

Posted by raetsel on February 2, 2008

It is a necessary evil at work that I have to get my laptop that runs Kubuntu to interact with the rest of the Windows systems at work.In order to show that Linux can hold its own I’ve not asked for any special changes to be made to the way the windows servers are set up. I just make Linux work with what the Windows PCs use.

The main area of interaction is the mounting of Samba shares to get at my network storage.

In general this is fine but I have found one little gotcha if you are using /etc/fstab to mount shares at boot up and the share names in question have spaces in them.

The problem is that spaces are delimiters in /etc/fstab and trying to avoid getting the space interpreted by usng quotes or backslashes won’t work with /etc/fstab.

The answer is to use the octal code for the ASCII number of the space character. (Wow so much jargon in one short sentence)

So first here are two lines from an /etc/fstab for mounting two windows shares. The windows shares on a server called nas001 and the share names are “Backup” and “My Documents”

# /etc/fstab: static file system information.#
# <file system> <mount point> <type> <options> <dump> <pass>
//nas001/Backup /mnt/backup cifs credentials=/home/raetsel/creds 0 0
//nas001/My\040Documents /mnt/mydocs cifs credentials=/home/raetsel/creds 0 0

So after the comments the first line shows mounting a share without a space, the second line shows mounting a share with a space where space is replaced with \040

So what’s with \040? Well the and a three digit code is interpreted as an ASCII value of a character in octal (base 8).

In an Linux command shell type man ascii to see a list ofASCII codes and their octal, decimal and hexadecimal equivalents.

Space is decimal 32 which is octal 40 ( but we need 3 digits for the interpretation to work so it is 040)

In a similar vein \134 is the octal code for a \ backslash so if you want to have a domain username pair in the options of the line in fstab you could do it with username=mydomain\134raetsel

6 Responses to “Samba Shares, Spaces and fstab (With a bit of Octal thrown in)”

  1. gabo said

    Yeah, you saved me a lot of time!! Thanks a lot!

    g4b0

  2. Miradwyn said

    I was just having this problem myself and found the answer on the first search I hit on. Thank you.

  3. Von said

    I have a problem with cifs as I’ve now upgraded to Hardy Heron and smbfs has been replaced. Anyway, if my windows share has a “$” I get the following:

    mount: //server/drive$/folder is not a valid block device

    any ideas?

  4. raetsel said

    Hi Yvonne,

    Well the ascii code (in octal) for the $ sign is 044 so you could try

    //server/drive\ 044/folder ( no space between the \ and the 0 I just had to do that because of how wordpress interprets a \ )

    I don’t have any Windows shares with dollar signs in to access at the moment so can’t test the theory.

  5. s said

    It would be just swell if we got the Samba folks to put this in the man page.

  6. Bart van Deenen said

    Thanks for the posting. The dollar octal value 44 does work fine in fstab!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>