Symlink from one workstation to another without mount

53,056

Solution 1

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.

Solution 2

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.

Solution 3

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.

Share:
53,056

Related videos on Youtube

speedyrazor
Author by

speedyrazor

Updated on September 18, 2022

Comments

  • speedyrazor
    speedyrazor over 1 year

    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
    
    • deltab
      deltab almost 10 years
      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.
    • speedyrazor
      speedyrazor almost 10 years
      Sorry, missed off the -s. I have now added it.
    • deltab
      deltab almost 10 years
      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?
    • speedyrazor
      speedyrazor almost 10 years
      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?
    • SHW
      SHW almost 10 years
      If you have not mounted any network share then said symlink will be "dangling" pointer. Why you want to do this ?
    • Angelos Asonitis
      Angelos Asonitis about 5 years
      You should not confuse the linux symbolic links with windows shortcuts. The major difference between them is that a symbolic link behaves in most ways as a file. For instance if you "edit" the symbolic link, you edit the file. While the shortcut is a special kind of file that provides only "opening" capability for the linked file. If you edit the windows shortcut, you will literally edit the shortcut. I Understand that "file associations", make you feel that this is not true because when you click a shortcut, it "may" be opened with an associated editor and thus give the impression of a file.
  • speedyrazor
    speedyrazor almost 10 years
    Not the answer I wanted, but honest and clear, cheers.
  • phk
    phk over 7 years
    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.
  • Eli Sigal
    Eli Sigal over 6 years
    @MichaelHomer +1 For correct explanation of symbolic links see stackoverflow.com/questions/16912997