#2740 Issue closed: RFC: Copy symlinks as symlinks and add missing symlink targets at the end

Labels: enhancement, cleanup, discuss / RFC, no-issue-activity

jsmeix opened issue at 2022-01-17 13:07:

When creating the recovery system files and directories get copied.
The problem is how to deal best with (possibly dangling) symlinks.

See https://github.com/rear/rear/issues/2739
therein in particular
https://github.com/rear/rear/issues/2739#issuecomment-1014473854
that reads (a bit adapted excerpts):

Perhaps we should in general not specfically care about symlinks
in the individual scripts i.e. that in general we just copy symlinks as symlinks
and leave it completely to build/default/490_fix_broken_links.sh
to fix the broken symlinks inside the recovery system?

On first glance this looks wrong because each code part should do its task right
but on a second glance fix only actually broken symlinks in a generic script at the end
could have general advantages.

Example:
Assume in the original system there are

/path/to/huge_file
/path1/to/symlink1 -> /path/to/huge_file
/path2/to/symlink2 -> /path/to/huge_file

then cp -L results that in the recovery system
both /path1/to/symlink1 and /path2/to/symlink2 are regular files
with identical contents as /path/to/huge_file
cf. https://github.com/rear/rear/issues/2739#issuecomment-1012949307
so cp -L can result needlessly duplicated content
in particular when /path/to/huge_file gets included anyway.

Another reason is that in practice it gets rather complicated
to deal correctly with symlinks at each code place
(e.g. see https://github.com/rear/rear/issues/2739)
so it could be better in practice to not care at each code place
and only fix what actually needs to be fixed at the end by a generic script.

jsmeix commented at 2022-01-17 13:15:

Code lines that call cp ... -L ...:

# find usr/sbin/rear usr/share/rear/ -type f | xargs grep 'cp .*-.*L'

usr/share/rear/output/RAWDISK/Linux-i386/280_create_bootable_disk_image.sh
cp -rL $v "${staged_boot_partition_contents[@]}" "$boot_partition_root" >&2 || Error "Could not populate boot partition"

usr/share/rear/output/default/940_grub_rescue.sh
cp -pLlf $v $KERNEL_FILE /boot/rear-kernel || BugError "Failed to hardlink '$KERNEL_FILE' to /boot/rear-kernel"
cp -pLf $v $KERNEL_FILE /boot/rear-kernel || BugError "Failed to copy '$KERNEL_FILE' to /boot/rear-kernel"

usr/share/rear/output/default/940_grub2_rescue.sh
cp -pLlf $v $KERNEL_FILE $boot_kernel_file || BugError "Failed to hardlink '$KERNEL_FILE' to '$boot_kernel_file'"
cp -pLf $v $KERNEL_FILE $boot_kernel_file || BugError "Failed to copy '$KERNEL_FILE' to '$boot_kernel_file'"

usr/share/rear/output/USB/Linux-i386/830_copy_kernel_initrd.sh
cp -pL $v "$KERNEL_FILE" "$BUILD_DIR/outputfs/$USB_PREFIX/kernel" >&2 || Error "Could not create $BUILD_DIR/outputfs/$USB_PREFIX/kernel"

usr/share/rear/output/USB/Linux-i386/100_create_efiboot.sh
cp -L $v "$UEFI_BOOTLOADER" "$efi_dst/BOOTX64.efi" || Error "Failed to copy UEFI_BOOTLOADER '$UEFI_BOOTLOADER' to $efi_dst/BOOTX64.efi"
cp -L $v "$KERNEL_FILE" "$efi_dst/kernel" || Error "Failed to copy KERNEL_FILE '$KERNEL_FILE' to $efi_dst/kernel"
cp -L $v "$TMP_DIR/$REAR_INITRD_FILENAME" "$efi_dst/$REAR_INITRD_FILENAME" || Error "Failed to copy initrd to $efi_dst/$REAR_INITRD_FILENAME"

usr/share/rear/output/PXE/default/800_copy_to_tftp.sh
cp -L $v "$KERNEL_FILE" "$PXE_TFTP_LOCAL_PATH/$PXE_KERNEL" || Error "Failed to copy KERNEL_FILE '$KERNEL_FILE'"
cp -L $v "$TMP_DIR/$REAR_INITRD_FILENAME" "$PXE_TFTP_LOCAL_PATH/$PXE_INITRD" || Error "Failed to copy initrd '$REAR_INITRD_FILENAME'"

usr/share/rear/output/ISO/Linux-i386/800_create_isofs.sh
cp -pL $v $KERNEL_FILE $TMP_DIR/isofs/isolinux/kernel || Error "Failed to copy KERNEL_FILE '$KERNEL_FILE'"
cp -pL $v ${ISO_FILES[@]} $TMP_DIR/isofs/isolinux/ || Error "Failed to copy ISO_FILES '${ISO_FILES[@]}'"

usr/share/rear/output/ISO/Linux-i386/300_create_isolinux.sh
cp -L $v "$ISO_ISOLINUX_BIN" $TMP_DIR/isolinux/isolinux.bin >&2

usr/share/rear/output/ISO/Linux-i386/250_populate_efibootimg.sh
cp -pL $v $KERNEL_FILE $efi_boot_tmp_dir/kernel || Error "Failed to copy KERNEL_FILE '$KERNEL_FILE' to $efi_boot_tmp_dir/kernel"

usr/share/rear/output/ISO/Linux-ia64/300_create_bootimg.sh
cp -L $v "$ELILO_BIN" $TMP_DIR/mnt/boot || Error "Failed to copy elilo.efi '$ELILO_BIN'"

usr/share/rear/output/ISO/Linux-ppc64le/800_create_isofs.sh
cp -pL $v $KERNEL_FILE $TMP_DIR/kernel || Error "Failed to copy KERNEL_FILE '$KERNEL_FILE'"

usr/share/rear/output/RAMDISK/default/900_copy_ramdisk.sh
cp $v -pLf $KERNEL_FILE $kernel_file || Error "Failed to copy KERNEL_FILE '$KERNEL_FILE'"
cp $v -pLf $TMP_DIR/$REAR_INITRD_FILENAME $initrd_file || Error "Failed to copy initramfs '$REAR_INITRD_FILENAME'"

usr/share/rear/build/GNU/Linux/100_copy_as_is.sh
cp $v -r -L $CONFIG_DIR/. $ROOTFS_DIR/etc/rear/

usr/share/rear/build/GNU/Linux/420_copy_firmware_files.sh
find /lib*/firmware -ipath "$find_ipath_pattern" | xargs cp $verbose -t $ROOTFS_DIR -p -L --parents 2>&1 | grep -v 'omitting directory' 1>&2 || true

usr/share/rear/build/GNU/Linux/400_copy_modules.sh
if ! cp $verbose -t $ROOTFS_DIR -a -L --parents /lib/modules/$KERNEL_VERSION 2>>/dev/$DISPENSABLE_OUTPUT_DEV 1>&2 ; then
if ! cp $verbose -t $ROOTFS_DIR -L --preserve=all --parents $loaded_modules_files 1>&2 ; then
if ! cp $verbose -t $ROOTFS_DIR -L --preserve=all --parents $module_files 1>&2 ; then

github-actions commented at 2022-03-19 02:26:

Stale issue message

github-actions commented at 2022-05-21 02:39:

Stale issue message

hpannenb commented at 2023-01-03 15:56:

@jsmeix Unfortunately closed.


[Export of Github issue for rear/rear.]