Consider we mount a foreign directory tree under some location and then chroot into it:

mount /dev/sdx1 /mnt
chroot /mnt
readlink /usr/bin/myapp    # Outputs: /usr/libexec/myapp/run

Is there any tool to resolve paths inside /mnt prefix before (without) doing chroot? For example, if there is a /usr/bin/myapp file in /mnt which is a symbolic link pointing to absolute path /usr/libexec/myapp/run (rather than more robust ../libexec/myapp/run), then how can this be resolved to /mnt/usr/libexec/myapp/run without chrooting?

The realpath --relative-to=DIR --relative-base=DIR looks promising, but actually serves another purpose. Using --canonicalize-missing may slightly help when only one symlink appears in the path, yet it returns a path relative to its base, which by itself is not valid in the host system.

Of course it is feasible to write a script what traverses each path level manually and resolves every one of them using readlink, but that seems overkill.

Your Answer

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

Browse other questions tagged or ask your own question.