Bug#950086: base-installer: please support configuring initramfs compression
On 29/01/2020 21:31, Ben Hutchings wrote:
This is definitely a rather niche option, so "wishlist" is appropriate.
Thanks! (My reasoning was that it's a new feature.)
So it's possible to set any arbitrary string, but if you set it to
anything other than "gzip", "xz", or "lzma" then the required
compressor might not be installed. (And it's possible to set a string
that mkinitramfs doesn't install either.)
I think this needs to be a "select" type question, so that only the
supported compression types can be selected.
Allowing arbitrary strings wasn't the intention. I had mimicked the
driver-policy implementation. The template you quoted is only used to
set a "select" type question, and I assumed doing that with an invalid
value would cause an error.
While testing I noticed that it would use the first choice when given
invalid values (e.g. with kernel cmdline [0]), so I reordered the
compression choices to match initramfs.conf, with "gzip" as the first
choice.
Anyway, I don't think checking the values would hurt, so I did that for
my patch and for the driver-policy question too (as patch 1/2). I'm just
running "exit 1" in the invalid cases, I'm not sure that's entirely right.
Also I'm now calling apt-install before writing the configuration, and
made it fail the installation step with (hopefully the appropriate
error) if it can't install the compressor package.
Attaching a series of two patch files to replace the previous one. Hope
they resolve your concerns.
[0] quiet console=tty0 priority=critical \
base-installer/initramfs-tools/compression=git \
base-installer/kernel/linux/initramfs-tools/compression=git
>From e6949630a32e4930561e5fa9d9f443ab8ac044bc Mon Sep 17 00:00:00 2001
From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Date: Thu, 30 Jan 2020 14:21:30 +0300
Subject: [PATCH 1/2] Verify answers to initramfs-tools driver-policy questions
Also set "base-installer/kernel/linux/initramfs-tools/driver-policy" to
type "select" with choices "most" and "dep".
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
---
debian/templates-arch | 3 ++-
library.sh | 9 +++++++--
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/debian/templates-arch b/debian/templates-arch
index 30e8f7a8..fbb18372 100644
--- a/debian/templates-arch
+++ b/debian/templates-arch
@@ -6,7 +6,8 @@ Description: for internal use only
Use an (initramfs) initrd (linux 2.6 and later only)
Template: base-installer/kernel/linux/initramfs-tools/driver-policy
-Type: string
+Type: select
+Choices: most, dep
Default: most
Default[armel]: dep
Description: for internal use
diff --git a/library.sh b/library.sh
index d7f05024..890f7087 100644
--- a/library.sh
+++ b/library.sh
@@ -583,12 +583,17 @@ EOF
fi
db_get base-installer/initramfs-tools/driver-policy
- if [ "$RET" != most ]; then
+ IT_MODULES="$RET"
+ if [ "$IT_MODULES" != most ] && [ "$IT_MODULES" != dep ]; then
+ exit 1
+ fi
+
+ if [ "$IT_MODULES" != most ]; then
cat > $IT_CONFDIR/driver-policy <<EOF
# Driver inclusion policy selected during installation
# Note: this setting overrides the value set in the file
# /etc/initramfs-tools/initramfs.conf
-MODULES=$RET
+MODULES=$IT_MODULES
EOF
fi
else
--
2.25.0
>From f0dad1298cfb8f0e32616243f44ba776b647dc75 Mon Sep 17 00:00:00 2001
From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Date: Thu, 30 Jan 2020 14:42:26 +0300
Subject: [PATCH 2/2] Support configuring initramfs compression
Some machines/bootloaders do not support initramfs images larger than a
certain size. Setting MODULES=dep in initramfs-tools config is usually
enough to satisfy these size limits, and base-installer already asks a
question for this (driver-policy, with priority medium). This patch
implements a similar question for initramfs-tools' COMPRESS setting
which can further reduce the initramfs size for these machines.
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
---
debian/bootstrap-base.templates | 11 +++++++++++
debian/templates-arch | 7 +++++++
library.sh | 34 +++++++++++++++++++++++++++++++++
3 files changed, 52 insertions(+)
diff --git a/debian/bootstrap-base.templates b/debian/bootstrap-base.templates
index 78a6f29a..8529fbf7 100644
--- a/debian/bootstrap-base.templates
+++ b/debian/bootstrap-base.templates
@@ -88,6 +88,17 @@ _Description: Drivers to include in the initrd:
smaller targeted initrd there is a very small chance that not all needed
drivers are included.
+Template: base-installer/initramfs-tools/compression
+Type: select
+Choices: gzip, bzip2, lz4, lzma, lzop, xz
+# :sl3:
+_Description: Compression method for the initramfs image:
+ Compressing the initramfs is usually a trade-off between initramfs
+ size, memory use, compression speed, and the time your system takes to
+ boot (decompression speed). Gzip is reasonably balanced, xz and lzma
+ makes the initramfs significantly smaller, but lz4 has the highest
+ decompression speed.
+
Template: base-installer/kernel/failed-install
Type: error
# :sl2:
diff --git a/debian/templates-arch b/debian/templates-arch
index fbb18372..29d01721 100644
--- a/debian/templates-arch
+++ b/debian/templates-arch
@@ -13,6 +13,13 @@ Default[armel]: dep
Description: for internal use
Default driver inclusion policy for initramfs-tools
+Template: base-installer/kernel/linux/initramfs-tools/compression
+Type: select
+Choices: gzip, bzip2, lz4, lzma, lzop, xz
+Default: gzip
+Description: for internal use
+ Default compression method for initramfs-tools
+
Template: base-installer/kernel/linux/extra-packages
Type: string
Default:
diff --git a/library.sh b/library.sh
index 890f7087..fa5090b1 100644
--- a/library.sh
+++ b/library.sh
@@ -575,8 +575,15 @@ EOF
db_get base-installer/kernel/linux/initramfs-tools/driver-policy
db_set base-installer/initramfs-tools/driver-policy "$RET"
fi
+ if db_get base-installer/initramfs-tools/compression && \
+ [ -z "$RET" ]; then
+ # Get default for architecture
+ db_get base-installer/kernel/linux/initramfs-tools/compression
+ db_set base-installer/initramfs-tools/compression "$RET"
+ fi
db_settitle debian-installer/bootstrap-base/title
db_input medium base-installer/initramfs-tools/driver-policy || true
+ db_input medium base-installer/initramfs-tools/compression || true
if ! db_go; then
db_progress stop
exit 10
@@ -588,12 +595,39 @@ EOF
exit 1
fi
+ db_get base-installer/initramfs-tools/compression
+ IT_COMPRESS="$RET"
+ case "$IT_COMPRESS" in
+ gzip|lzop|lz4|bzip2)
+ IT_COMPRESS_PKG="$IT_COMPRESS"
+ ;;
+ xz|lzma)
+ IT_COMPRESS_PKG=xz-utils
+ ;;
+ *)
+ exit 1
+ ;;
+ esac
+
+ if ! log-output -t base-installer apt-install "$IT_COMPRESS_PKG"; then
+ db_subst base-installer/kernel/failed-package-install PACKAGE "$IT_COMPRESS_PKG"
+ exit_error base-installer/kernel/failed-package-install
+ fi
+
if [ "$IT_MODULES" != most ]; then
cat > $IT_CONFDIR/driver-policy <<EOF
# Driver inclusion policy selected during installation
# Note: this setting overrides the value set in the file
# /etc/initramfs-tools/initramfs.conf
MODULES=$IT_MODULES
+EOF
+ fi
+ if [ "$IT_COMPRESS" != gzip ]; then
+ cat > $IT_CONFDIR/compression <<EOF
+# Compression method selected during installation
+# Note: this setting overrides the value set in the file
+# /etc/initramfs-tools/initramfs.conf
+COMPRESS=$IT_COMPRESS
EOF
fi
else
--
2.25.0
Reply to: