If dracut fails to build the initrd image or EFI binary for any reason (e.g., if
`cp` fails because there is no space left on the device), it removes the
existing output file before exiting, which may result in an unbootable system.
Instead of copying the initrd image directly to the output, copy it alongside it
to the same output directory, and if the copy succeeds, replace it.
compress="cat"
fi
+# protect existing output file against build errors
+if [[ -e $outfile ]]; then
+ outfile_final="$outfile"
+ outfile="${outfile}.tmp"
+fi
+
dinfo "*** Creating image file '$outfile' ***"
if [[ $uefi == yes ]]; then
fi
fi
+if [[ $outfile_final ]]; then
+ dinfo "*** Moving image file '$outfile' to '$outfile_final' ***"
+ if mv -f "$outfile" "$outfile_final"; then
+ dinfo "*** Moving image file '$outfile' to '$outfile_final' done ***"
+ outfile="$outfile_final"
+ else
+ rm -f -- "$outfile_final"
+ dfatal "Move of $outfile_final failed"
+ exit 1
+ fi
+fi
+
btrfs_uuid() {
btrfs filesystem show "$1" | sed -n '1s/^.*uuid: //p'
}