#1734 PR merged
: Trace broken symbolic links in rootfs¶
Labels: enhancement
, fixed / solved / done
, minor bug
gdha opened issue at 2018-02-17 09:03:¶
copy the mising symbolic files to ROOTFS_DIR (we do skip broken links in /dev/)¶
-
Type: Bug Fix
-
Impact: Normal
-
Reference to related issue (URL): https://github.com/rear/rear/issues/1638
-
How was this pull request tested? Script only on saved rootfs dir with
pushd
-
Brief description of the changes in this pull request: Issue was detected via ReaR Automated Testing - see issue https://github.com/gdha/rear-automated-testing/issues/47
jsmeix commented at 2018-10-30 13:53:¶
I think I understand now why chroot $ROOTFS_DIR
should be used
instead of pushd $ROOTFS_DIR
because the former makes it
straightforward to detect symlinks where the symlink target is
not inside ROOTFS_DIR.
With current ReaR master code I get:
# chroot /tmp/rear.xRsEEfjGJVOhU3T/rootfs bash-4.4# for symlink in $( find . -xdev -path ./dev -prune -o -type l -print ) ; do echo -n "$symlink -> " ; readlink -e $symlink || echo failed ; done | grep failed ./etc/localtime -> failed ./etc/mtab -> failed ./etc/termcap -> failed bash-4.4# ls -l etc/localtime etc/mtab etc/termcap lrwxrwxrwx 1 root root 33 Sep 13 07:52 etc/localtime -> /usr/share/zoneinfo/Europe/Berlin lrwxrwxrwx 1 root root 17 Oct 29 12:18 etc/mtab -> /proc/self/mounts lrwxrwxrwx 1 root root 23 May 12 21:16 etc/termcap -> /usr/share/misc/termcap bash-4.4# file etc/localtime etc/mtab etc/termcap etc/localtime: broken symbolic link to /usr/share/zoneinfo/Europe/Berlin etc/mtab: broken symbolic link to /proc/self/mounts etc/termcap: broken symbolic link to /usr/share/misc/termcap
pcahyna commented at 2018-10-30 14:04:¶
@jsmeix yes. You can use find -xtype l
like in the original code to
detect broken symlinks instead of grepping for failed
in readlink
output, that's the point of the original code.
jsmeix commented at 2018-10-31 10:24:¶
@pcahyna
sorry for causing confusion.
My above command was not meant to be used in the final code.
I had used it to inspect all the links inside the recovery system.
To make the point of chroot ... find
versus pushd ... find ... pod
more clear:
# pushd /tmp/rear.xRsEEfjGJVOhU3T/rootfs &>/dev/null ; find . -xdev -path './proc' -prune -o -path './sys' -prune -o -path './dev' -prune -o -xtype l -ls ; popd &>/dev/null [no output] # chroot /tmp/rear.xRsEEfjGJVOhU3T/rootfs find . -xdev -path './proc' -prune -o -path './sys' -prune -o -path './dev' -prune -o -xtype l -ls 39585486 0 lrwxrwxrwx 1 root root 33 Sep 13 07:52 ./etc/localtime -> /usr/share/zoneinfo/Europe/Berlin 39584072 0 lrwxrwxrwx 1 root root 17 Oct 29 12:18 ./etc/mtab -> /proc/self/mounts 39585482 0 lrwxrwxrwx 1 root root 23 May 12 21:16 ./etc/termcap -> /usr/share/misc/termcap
i.e. chroot ... find
finds symlinks that are broken within the
recovery system
because their link target is outside of the recovery system
while pushd ... find ... pod
does not find them.
pcahyna commented at 2018-10-31 11:54:¶
@jsmeix thanks for the demonstration, that's what I meant indeed.
jsmeix commented at 2018-10-31 15:08:¶
@pcahyna
my current
https://github.com/rear/rear/pull/1947
intends to improve it.
Because there are so many cases how symlinks could behave unexpected
I would very much appreciate it if you could test if it actually makes
things
behave better on your particular system.
On my system I have no longer a broken symlink in the recovery system
(the only exception is ./etc/mtab -> /proc/self/mounts
see the
comment in the code about "known to be broken by intention" symlinks)
# ROOTFS_DIR=/tmp/rear.aNIwiSL1iAp0jiV/rootfs # chroot $ROOTFS_DIR find . -xdev -path './proc' -prune -o -path './sys' -prune -o -path './dev' -prune -o -xtype l -ls 40638977 0 lrwxrwxrwx 1 root root 17 Oct 31 15:54 ./etc/mtab -> /proc/self/mounts # chroot $ROOTFS_DIR find . -xdev -path './proc' -prune -o -path './sys' -prune -o -path './dev' -prune -o -ls | egrep 'mtab|zoneinfo|termcap' 40639794 0 lrwxrwxrwx 1 root root 33 Sep 13 09:52 ./etc/localtime -> /usr/share/zoneinfo/Europe/Berlin 40638977 0 lrwxrwxrwx 1 root root 17 Oct 31 15:54 ./etc/mtab -> /proc/self/mounts 40639790 0 lrwxrwxrwx 1 root root 23 May 12 23:16 ./etc/termcap -> /usr/share/misc/termcap 40894481 4 drwxr-xr-x 3 root root 4096 Oct 31 15:55 ./usr/share/zoneinfo 40894536 4 drwxr-xr-x 2 root root 4096 Oct 31 15:55 ./usr/share/zoneinfo/Europe 40894537 4 -rw-r--r-- 1 root root 2326 Oct 25 16:14 ./usr/share/zoneinfo/Europe/Berlin 40765669 4 -rw-r--r-- 1 root root 442 May 12 23:14 ./usr/share/terminfo/a/ansi-mtabs 40770610 1068 -rw-r--r-- 1 root root 1092917 May 12 23:16 ./usr/share/misc/termcap
jsmeix commented at 2018-10-31 16:46:¶
With
https://github.com/rear/rear/pull/1947
merged
missing symlink target detection should now work better.
[Export of Github issue for rear/rear.]