rootfs-to-image: find, warn, and remove dangling symlinks in FAT32 /boot

This commit is contained in:
Ricardo Pardini
2023-05-23 13:57:43 +02:00
committed by igorpecovnik
parent 15fcc0bb00
commit 0a5740040e

View File

@@ -59,9 +59,19 @@ function create_image_from_sdcard_rootfs() {
# stage: rsync /boot
display_alert "Copying files to" "/boot (MOUNT /boot)"
if [[ $(findmnt --noheadings --output FSTYPE --target "$MOUNT/boot" --uniq) == vfat ]]; then
# FAT filesystems can't have symlinks; rsync, below, will replace them with copies (-L)...
# ... unless they're dangling symlinks, in which case rsync will fail.
# Find dangling symlinks in "$MOUNT/boot", warn, and remove them.
display_alert "Checking for dangling symlinks" "in FAT32 /boot" "info"
declare -a dangling_symlinks=()
while IFS= read -r -d '' symlink; do
dangling_symlinks+=("$symlink")
done < <(find "$SDCARD/boot" -xtype l -print0)
if [[ ${#dangling_symlinks[@]} -gt 0 ]]; then
display_alert "Dangling symlinks in /boot" "$(printf '%s ' "${dangling_symlinks[@]}")" "warning"
run_host_command_logged rm -fv "${dangling_symlinks[@]}"
fi
run_host_command_logged rsync -rLtWh --info=progress0,stats1 "$SDCARD/boot" "$MOUNT" # fat32
# @TODO: -L causes symlinks to be replaced with copies, but what if they don't exist?
# Also: what's the sense in replacing symlinks with copies?
else
run_host_command_logged rsync -aHWXh --info=progress0,stats1 "$SDCARD/boot" "$MOUNT" # ext4
fi