Mounting A Directory In Linux

The mount Command

The most common use of the mount command in Linux is to mount a file system from a block device such as a hard drive, usb stick or an image file. The mount command also has an option to mount a directory.

A Problem With 260 Character Path Limits

The Scenario

While working with the Cross Platform Command-line Client to access Team Foundation Server for source control, I was hit with the familiar “path or filename length too long” error preventing file checkin. In this particular environment, the code directory was deeply nested in a file system mount location. To work around this limitation, in Linux, a mount can be created from the root code directory with the mount command’s --bind option. For example, a long path such as


could be shortened to


A Workaround

First create the target folder with the mkdir command

mkdir -p /home/user/company/projects

The -p or --parents option for mkdir will create the parent folders as needed, without error, if for example neither ‘company‘ or ‘projects‘ exist in the example above.

You’re now ready to bind the source directory to the target directory.

sudo mount --bind /original/location/path /new/location/path

To have the mount persist across reboots, you will need to add the mount entry to the /etc/fstab file with the bind option there as well.

/from /to        none    bind

To load these settings, you can either reboot the machine or reload fstab mounts with the command

mount -a

A Caveat

One note worth mentioning here regarding the tfs-cli client. If the TFS project workspace mappings are already in place, the workfold command will need to be used to remap to the newly mounted directory location. Perhaps more on this in another post.

Leave a Reply