So, I am working on some sort of bash script, that basically works as industrial PC installer. Basically, what it does is, it mounts HDD (or SSD), copy a working image template on it using dd, than modify its content matching exact device that needs to be installed. That includes creating directories, files, modifing configs, etc..

Than you unmount it, disconnect, put in new PC, start, and you have new PC ready to go.

One part of the process, is creating symlinks for some dierctories. Example: ln -s /mnt/custom/home/user/original/path/source/subfolder /mnt/custom/home/user/symlnk

HOWEVER, as you probably guessed. This symlink, does not work, after the hard drive is unmounted and run on its own. Symlink is like this: /home/user/original/path/source/subfolder -> /mnt/custom/home/user/symlnk

So, my question is, how to do it on mounted hard drive, to have this symlink: /home/user/original/path/source/subfolder -> /home/user/symlnk when the drive is unmounted and booted?

Is it even possible?

2 Answers 2


This is not possible. All a symbolic link is, is a pointer saying "hey, you can find this file over there." If "over there" is on a path which is no longer mounted, the symlink will be broken until either:

  • The target location is remounted, or
  • A new file is placed at the target location

If you want a copy of the file from a location to which access is foreseeably breakable which will be available when that access is lost, you need to make an actual copy of the file and store that copy locally (i. e. in a location to which access is not foreseeably breakable).

You can theoretically place a file at that target location which would be masked by the mounted filesystem, but the practical result of that would be that your symlink would point to a different file when the target location is not mounted. The file would be in all ways other than path distinct from the one on the mounted drive, and would not be kept "in sync" with its "sibling file".

All that said, you can create a broken symlink which will be fixed when the drive is unmounted. If you:

$ ln -s /home/user/original/path/source/subfolder /mnt/custom/home/user/symlnk

while the drive is mounted at /mnt/custom, clearly that link won't work, but when that drive is mounted at /, it should be pointing to the correct location.

Another alternative is to make your symlinks to relative rather than absolute paths, and then so long as the links are within the same discrete partition they should still work wherever that partition is mounted.

  • what about chroot command? A friend of mine suested to use it like chroot /mnt/custom ln -s /home/user/original/path/source/subfolder /mnt/custom/home/user/symlnk
    – rRr
    Commented Mar 18 at 20:34

The answer is indeed chroot, I did it like this, and its working:

chroot /mnt/custom ln -s /home/user/original/path/source/subfolder /home/user/symlnk

You must log in to answer this question.

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