From 571976a179c961cd48f8b40f2af91af6337da52f Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Mon, 14 Jun 2021 18:19:14 -0400 Subject: [PATCH] overlay: ignition-ostree-firstboot-uuid: add workaround for FS without metadata_csum_seed It will be some time before we can support metadata_csum_seed in grub on all our target platforms. This commit adds a workaround for the case where grub doesn't support it yet. We specifically workaround the behavior of tune2fs that isn't sensitive to timing inconsistencies. See https://github.com/coreos/fedora-coreos-tracker/issues/735#issuecomment-859605953 Fixes: https://github.com/coreos/fedora-coreos-tracker/issues/735 --- .../ignition-ostree-firstboot-uuid | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/ignition-ostree-firstboot-uuid b/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/ignition-ostree-firstboot-uuid index 0eed19db06..0318471354 100755 --- a/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/ignition-ostree-firstboot-uuid +++ b/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/ignition-ostree-firstboot-uuid @@ -27,7 +27,37 @@ esac if [ "${TYPE}" == "${orig_type}" ] && [ "${UUID}" == "${orig_uuid}" ]; then case "${TYPE}" in - ext4) tune2fs -O metadata_csum_seed -U random "${target}" ;; + ext4) + # If the filesystem supports metadata_csum_seed then the UUID is stored + # in the superblock and there is no need to worry with an fsck. For the + # boot filesystem this FS feature wasn't supported by GRUB until recently. + # https://lists.gnu.org/archive/html/grub-devel/2021-06/msg00031.html + # Once grub is updated in all systems we care about we can standardize + # on the metadata_csum_seed and delete the `else` code block. + if tune2fs -l ${target} | grep 'metadata_csum_seed'; then + tune2fs -U random "${target}" + else + # Run an fsck since tune2fs -U requires the FS to be clean + e2fsck -fy "${target}" + # We just ran an fsck, but there is a bug where tune2fs -U will still + # complain. It will still error if the last checked timestamp (just + # set by the e2fsck above) is older than the last mount timestamp (happens + # on systems with out of date or non-functioning hardware clocks). + # See https://github.com/coreos/fedora-coreos-tracker/issues/735#issuecomment-859605953 + # Potentially fixed in future by: https://www.spinics.net/lists/linux-ext4/msg78012.html + tune2fsinfo="$(tune2fs -l ${target})" + lastmount=$(echo "$tune2fsinfo" | grep '^Last mount time:' | cut -d ':' -f 2,3,4) + lastfsck=$(echo "$tune2fsinfo" | grep '^Last checked:' | cut -d ':' -f 2,3,4) + lastmountsse=$(date --date="$lastmount" +%s) + lastfscksse=$(date --date="$lastfsck" +%s) + if (( lastfscksse < lastmountsse )); then + echo "Detected timestamp of last fsck is older than timestamp of last mount." + echo "Setting "${target}" timestamp of last fsck to same time as last mount." + tune2fs -T $(date --date="$lastmount" +%Y%m%d%H%M%S) "${target}" + fi + # Finally, we can randomize the UUID + tune2fs -U random "${target}" + fi ;; xfs) xfs_admin -U generate "${target}" ;; *) echo "unexpected filesystem type ${TYPE}" 1>&2; exit 1 ;; esac