The Computer Oracle

How to mount partition with spaces in path

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Future Grid Looping

--

Chapters
00:00 How To Mount Partition With Spaces In Path
00:35 Accepted Answer Score 2
00:48 Answer 2 Score 44
01:19 Answer 3 Score 4
01:35 Answer 4 Score 3
02:21 Thank you

--

Full question
https://superuser.com/questions/527495/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #mount

#avk47



ANSWER 1

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




ANSWER 2

Score 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")



ANSWER 3

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



ACCEPTED ANSWER

Score 2


Use quote marks.

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