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

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


12 thoughts on “Samba Shares, Spaces and fstab (With a bit of Octal thrown in)

  1. 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?

  2. 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.

  3. Awesome information, mount kept throwing a fit with my fstab and quick google search lead me to your info. Figures that fstab wouldn’t take any of my escape characters for spaces. The octal space however, works perfectly!

  4. Pingback: Spaces in fstab | Stuart Mullen

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s