23

I created one partition and I wanted to mount that partition to this directory /home/max/VirtualBox VMs

I wrote this line in fstab:

/dev/sda4    /home/max/VirtualBox\ VMs  ext4    defaults        0 0

but it's giving this error

[mntent]: line 16 in /etc/fstab is bad

I know I am getting this error because of space in between 'virtualBox VMs'

Is it possible to mount to that Directory?

[max@localhost VirtualBox VMs]$ pwd
/home/max/VirtualBox VMs
0

4 Answers 4

2

Use quote marks.

/dev/sda4 "/home/max/VirtualBox VMs" ext4 defaults 0 0

8
  • 2
    Its not working I tried all these things "/home/max/VirtualBox VMs" , /home/max/VirtualBox\ VMs /home/max/"VirtualBox VMs" nothing is working.
    – max
    Commented Jan 3, 2013 at 10:02
  • 6
    You could try using \040 instead of the spaces; according to the internets that works fantastically; I just tried it on Arch running 3.7 kernel and it doesn't want to work for me however.
    – Justin
    Commented Jan 3, 2013 at 10:12
  • 1
    the \ is an escape character and 040 is the ASCII code for space. Now I want to know why it won't work for me :/
    – Justin
    Commented Jan 3, 2013 at 11:16
  • 4
    Does not work for me, but the \040 answer does. It's funny that I happen to need this answer for exactly the same reason as the original poster. Commented Jan 29, 2016 at 16:10
  • 2
    This should not be the accepted answer, as it doesn't work. The answer underneath this one with more votes does work and should be the accepted answer. Commented May 16, 2023 at 2:12
44

fstab has its own syntax. To use spaces as part of a directory name, you have to specify its code point as a zero-padded 3-digit octal number, preceded by a backslash (escape character).

In ASCII, the space character's code point is 32 or 40 in octal, so you can use:

/dev/sda4               /home/max/VirtualBox\040VMs  ext4    defaults        0 0

Note that, while code points are supported for other characters as well, the support is rather flaky. On my machine, you can write \127 instead of W, but not \070 instead of 8...

3
  • 2
    Thanks for this answer! Double quotes or single quotes didn't work, \040 worked! This should be the accepted answer. Commented Aug 24, 2021 at 11:32
  • 2
    Thanks for this answer - i had been searching for the solution with fstab with use on my Raspberry Pi (Raspian OS), and it worked perfect.
    – BlissSol
    Commented Jan 5, 2023 at 3:53
  • macOS, however, being BSD-based, creates a mount point named /home/max/VirtualBox\040VMs, not /home/max/VirtualBox VMs as expected. Hrrrmpf. Commented Nov 25, 2023 at 1:31
4

I am converting the whole path to code point with a Bash function:

fstab_path(){
    local path=$1
    local s=
    local c=
    for i in $(seq 1 ${#path})
    do
        c=${path:i-1:1}
        s="$s"$(printf '\\0%o' "'$c")
    done
    echo "$s"  >/dev/stdout
}

path="path with spaces tabs etc.."
fpath=$(fstab_path "$path")
3

I had the same problem, but with a slight twist: mounting btrfs subvolume containing Virtual Box into my home dir on partition of ext4 (I had just changed hard drives).

I followed Dennis's solution but was still having problems. The problem I ran into was that both the old and new system paths contained a space my solution was to replace all paths containing spaces with \040; it would look something like this:

  • /dev/sda1 being btrfs of old system
  • /dev/sdb1 of new system
  • Mount subvolume path/with space onto /home/<user>/VirtualBox VMs
  • Final /etc/fstab:
...
/dev/sdb1 /home ext4 defaults 0 0
/dev/sda1 /home/<user>/VirtualBox\040VMs btrfs defaults,subvol=path/with\040space 0 0
...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .