6

I am trying to create a symlink of a file on one linux workstation to another linux workstation, without having to 'mount' any network shares. Here's what I am trying to do, but can't get it to work.

ln -s /link/to/local/file.mov //10.0.1.103/sharedFolder/symlinkFile.mov
  • 1
    You need -s to make a symlink; otherwise you're trying to make a hard link, and those can only be made on the same filesystem. – deltab Jul 21 '14 at 5:24
  • Sorry, missed off the -s. I have now added it. – speedyrazor Jul 21 '14 at 5:27
  • When you say "can't get it to work", what actually happens when you try? Also, what are you using that would make //10.0.1.103 refer to another machine, and not just a subdirectory of / called 10.0.1.103? – deltab Jul 21 '14 at 5:33
  • I have updated the question to show that on //10.0.1.103 (the other linux workstation on the same network) has a shared folder (sharedFolder). So rather than mounting that shared folder, can I just link straight to it, like you can on Windows PC? – speedyrazor Jul 21 '14 at 5:39
  • If you have not mounted any network share then said symlink will be "dangling" pointer. Why you want to do this ? – SHW Jul 21 '14 at 5:56
13

You can't:

A symlink is simply an extra inode (a structure that points to the file) and this inode consists of, amongst other things, a deviceId and an inode pointer. The deviceId effectively points to a device special file within the /dev directory and the inode pointer points to a block on that device.

Your network location of 10.0.1.103 does not and cannot have an deviceId (it's not in /dev) therefore you can't possibly have a symlink to a network location.

On the other hand, a mounted network share will have a deviceId which is why you can create a symlink to a mounted location.

7

Windows has a special syntax \\MACHINE\DIRECTORY…\FILE meaning the file located at \DIRECTORY…\FILE on the machine called \\MACHINE over the SMB protocol. This is built into the operating system and specialized to one network protocol.

Linux has a flexible filesystem based on the notion of mounting. Filesystems are attached to an existing directory, and the administrator gets to choose how to arrange the directory hierarchy. For more background, read What is meant by mounting a device in Linux?, Why is Linux's filesystem designed as a single directory tree? and What mount points exist on a typical Linux system?. Linux supports many network filesystems (i.e. filesystems that allow one machine to access files on another machine), including NFS, SMB, SSHFS, etc.

NFS can be considered Linux's native network filesystem, the way SMB is Windows's. However Linux doesn't export its files by default: you need to install an NFS server. An NFS server is available in all Linux distributions, but requires a bit of setup (you need to register the directories you want to export in the file /etc/exports). Furthermore NFS is from a gentler time when attackers on the local network weren't a concern, and securing it requires a bit of knowledge about firewalls which is beyond the scope of this answer. To make the directory /some/where from the remote machine foo.example.com available at the location /local/dir (which must be an existing directory), assuming that it is exported by the remote machine, run the following command as root:

mount foo.example.com:/some/where /local/dir

The easy way to access remote files with next to no setup is over SSHFS. All you need is to install an SSH server on the remote machine, and the sshfs package on the local machine. You should also generate a key (see How to make password-less login work), though you don't have to do it if you don't mind entering your password each time. SSH is additionally useful to run commands on the remote machine. To make the directory /some/where from the remote machine foo.example.com available at the location /local/dir (which must be an existing directory) over SSHFS, run the following command (as your usual user):

sshfs foo.example.com:/some/where /local/dir

Linux can be a server or a client for the SMB protocol (communicating with Windows machines, or even with other Linux machines though it's less well integrated than other protocols) through the Samba software.

You can set up an automounter (such as autofs) so that accessing certain directories automatically mounts directories from some remote machine. For example, a common configuration arranges that the autofs filesystem is mounted on the directory /net, and accessing /net/MACHINE/DIRECTORY causes the remote directory /DIRECTORY from /net/MACHINE to be mounted over NFS at that location (and it will be unmounted after a certain period of inactivity). The remote machine must of course have an NFS server set up and allowing that connection.

It is possible to set up an automounter with SSHFS. See Totally Seamless SSHFS under Linux using Fuse and Autofs and Autofs and sshfs – the perfect couple for quick tutorials; in a nutshell:

  1. Install autofs and sshfs.
  2. Add the following line to /etc/auto.master:

    /mnt/sshfs /etc/auto.sshfs uid=1000,gid=1000,--timeout=30,--ghost
    

    Replace the two occurrences of 1000 by your user id and group id (run id -u and id -g to show these values). Create the directory /mnt/sshfs.

  3. Create a file /etc/auto.sshfs containing lines like the following:

    machinename -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,max_read=65536 :sshfs\#machinename.example.com\:
    

    where machinename.example.com is the host name (or IP address) of the remote machine and machinename is the name you want to access it as locally, via the path /mnt/sshfs/machinename.

Autosshfs provides a more convenient autofs+sshfs setup.

Finally, regarding the symbolic part: you can create a symbolic link to a non-existent path. The symbolic link is the second argument, so you'll need something like

ln -s /net/10.0.1.103/sharedFolder/symlinkFile.mov /link/to/local/file.mov

You'll need to manually or automatically arrange for /sharedFolder from 10.0.1.103 to be mounted at /net/10.0.1.103/sharedFolder.

0

For what it's worth ...

I have worked on a small tool called lionfs which is based on Raphael S. Carvalho's GhostFS. The goal is to allow symbolic links pointing to an URI. It is fairly incomplete, have a lot of issues, and currently supports only HTTP. FUSE (Filesystem in Userspace) is used to handle the background.

  • 1
    Please be more specific of what it does and how it helps OP, at first I thought it might to automagic mounting but apparently this is not the case, it's just for offering HTTP served content as a FS?! This does not seem what OP wanted. – phk Oct 26 '16 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.