Disable ext4 metadata_csum_seed for Debian releases older than bookworm
[grml-debootstrap.git] / grml-debootstrap
index 2ed2964..339d352 100755 (executable)
@@ -64,6 +64,7 @@ MNTPOINT="/mnt/debootstrap.$$"
 [ -n "$HOSTNAME" ] || HOSTNAME='grml'
 [ -n "$INITRD" ] || INITRD='yes'
 [ -n "$INITRD_GENERATOR" ] || INITRD_GENERATOR='initramfs-tools'
+[ -n "$INITRD_GENERATOR_OPTS" ] || INITRD_GENERATOR_OPTS=''
 [ -n "$INSTALL_NOTES" ] || INSTALL_NOTES='/etc/debootstrap/install_notes'
 [ -n "$LOCALES" ] || LOCALES='yes'
 [ -n "$MIRROR" ] || MIRROR="$FALLBACK_MIRROR"
@@ -73,7 +74,7 @@ MNTPOINT="/mnt/debootstrap.$$"
 [ -n "$POST_SCRIPTS" ] || POST_SCRIPTS='yes'
 [ -n "$PRE_SCRIPTS" ] || PRE_SCRIPTS='yes'
 [ -n "$RECONFIGURE" ] || RECONFIGURE='console-data'
-[ -n "$RELEASE" ] || RELEASE='bullseye'
+[ -n "$RELEASE" ] || RELEASE='bookworm'
 [ -n "$RM_APTCACHE" ] || RM_APTCACHE='yes'
 [ -n "$SCRIPTS" ] || SCRIPTS='no' # deprecated, replaced by POST_SCRIPTS
 [ -n "$SECURE" ] || SECURE='yes'
@@ -152,7 +153,7 @@ Configuration options:
       --backportrepos      Enable Debian's backports repository (backports.debian.org).
       --keep_src_list      Do not overwrite user provided apt sources.list.
       --contrib            Enable 'contrib' in COMPONENTS (defaults to 'main' only).
-      --non-free           Enable non-free in COMPONENTS (defaults to 'main' only).
+      --non-free           Enable non-free / non-free-firmware in COMPONENTS (defaults to 'main' only).
       --hostname <name>    Hostname of Debian system.
       --nopassword         Do not prompt for the root password.
       --password <pwd>     Use specified password as password for user root.
@@ -588,7 +589,15 @@ done
 # make sure main is always included
 [ -z "$COMPONENTS" ]            && COMPONENTS="main"
 [ "$_opt_contrib" ]             && COMPONENTS="$COMPONENTS contrib"
-[ "$_opt_non_free" ]            && COMPONENTS="$COMPONENTS non-free"
+
+case "${RELEASE}" in
+  lenny|squeeze|wheezy|jessie|stretch|buster|bullseye)
+    [ "$_opt_non_free" ] && COMPONENTS="$COMPONENTS non-free"
+    ;;
+  *)
+    [ "$_opt_non_free" ] && COMPONENTS="$COMPONENTS non-free-firmware non-free"
+    ;;
+esac
 
 # command line option checks
 if [ "$_opt_scripts_set" ] ; then
@@ -792,13 +801,9 @@ prompt_for_release()
   RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
             "Please enter the Debian release you would like to use for installation:" \
             0 50 8 \
-            lenny    Debian/5.0 \
-            squeeze  Debian/6.0 \
-            wheezy   Debian/7.0 \
-            jessie   Debian/8.0 \
-            stretch  Debian/9.0 \
-            buster   Debian/10.0 \
-            bullseye Debian/11.0 \
+            buster   Debian/10 \
+            bullseye Debian/11 \
+            bookworm Debian/12 \
             sid      Debian/unstable)"
   [ $? -eq 0 ] || bailout
 }
@@ -1182,7 +1187,7 @@ fi
 # Support for generic release codenames is unavailable. {{{
 if [ "$RELEASE" = "stable" ] || [ "$RELEASE" = "testing" ] ; then
    eerror "Generic release codenames (stable, testing) are unsupported. \
-Please use specific codenames such as buster or bullseye." ; eend 1
+Please use specific codenames such as bullseye or bookworm." ; eend 1
    bailout 1
 fi
 # }}}
@@ -1306,6 +1311,24 @@ mkfs() {
     esac
   fi
 
+  # starting with e2fsprogs v1.47.0 mkfs.ext4 enables the metadata_csum_seed feature
+  # by default, which requires Linux kernel >=4.4, e2fsprogs >=1.43, according GRUB etc.
+  # Disable this feature for Debian releases older than bookworm
+  if [ -n "$MKFS" ] && [ "$MKFS" = "mkfs.ext4" ] ; then
+    case "$RELEASE" in
+      lenny|squeeze|wheezy|jessie|stretch|buster|bullseye)
+        local e2fsprogs_version
+        # assume a more recent version if we can't identify the version via dpkg-query
+        e2fsprogs_version="$(dpkg-query --show --showformat='${Version}' e2fsprogs 2>/dev/null || echo 1.47)"
+        if [ -n "$e2fsprogs_version" ] && dpkg --compare-versions "$e2fsprogs_version" ge '1.43' ; then
+          einfo "Disabling metadata_csum_seed feature for $MKFS as $RELEASE doesn't support it."
+          MKFS_OPTS="$MKFS_OPTS -O ^metadata_csum_seed"
+          eend 0
+        fi
+        ;;
+    esac
+  fi
+
   if [ -n "$MKFS" ] ; then
     einfo "Running $MKFS $MKFS_OPTS on $TARGET"
     # shellcheck disable=SC2086
@@ -1693,6 +1716,7 @@ preparechroot() {
   [ -n "$HOSTNAME" ]            && echo "HOSTNAME='$(sed "s,','\\\\'',g" <<<"${HOSTNAME}")'"                       >> "$CHROOT_VARIABLES"
   [ -n "$INITRD" ]              && echo "INITRD='$(sed "s,','\\\\'',g" <<<"${INITRD}")'"                           >> "$CHROOT_VARIABLES"
   [ -n "$INITRD_GENERATOR" ]    && echo "INITRD_GENERATOR='$(sed "s,','\\\\'',g" <<<"${INITRD_GENERATOR}")'"       >> "$CHROOT_VARIABLES"
+  [ -n "$INITRD_GENERATOR_OPTS" ] && echo "INITRD_GENERATOR_OPTS='$(sed "s,','\\\\'',g" <<<"${INITRD_GENERATOR_OPTS}")'" >> "$CHROOT_VARIABLES"
   [ -n "$INSTALL_NOTES" ]       && echo "INSTALL_NOTES='$(sed "s,','\\\\'',g" <<<"${INSTALL_NOTES}")'"             >> "$CHROOT_VARIABLES"
   [ -n "$ISODIR" ]              && echo "ISODIR='$(sed "s,','\\\\'',g" <<<"${ISO}")'"                              >> "$CHROOT_VARIABLES"
   [ -n "$ISO" ]                 && echo "ISO='$(sed "s,','\\\\'',g" <<<"${ISO}")'"                                 >> "$CHROOT_VARIABLES"