I have a complete sub-filesystem inside a path /home/user/system
containing the standard Linux structure with directories /bin
, /home
, /root
, /usr
, /var
, /etc
,...
This sub-filesystem contain symbolic links, either relative or absolute. The relative symlinks are just fine, they stay within the sub-filesystem under /home/user/system
. But absolute symlinks are problematic, as they point to a target outside of the sub-filesystem.
As an example we assume an absolute symlink as follows (seen inside the sub-filesystem):
/usr/file1 -> /usr/lib/file1
In the overall filesystem we have a link at /home/user/system/usr/file1
that now point to a file /usr/lib/file1
outside the sub-filesystem, instead of a file /home/user/system/usr/lib/file1
inside the sub-filesystem.
I would like to have a simple script, preferably a single command line (rsync, chroot, find, ...) that converts every absolute symlink to a relative one.
In the given example, that relative link would become
/usr/file1 -> ../usr/lib/file1