Package: initramfs-tools Version: 0.93.4 Severity: normal Tags: patch Dear initramfs-tools Maintainers,
since I've recently did some experiments regarding lzma compressed initramfs images I stumbled upon this quite old bugreport. As mentioned before the stock kernel has support for lzma/bzip2 compressed images built in nowadays and it works great. Instead of having to recompress the initramfs image by hand over and over again i did a patch against initramfs-tools-0.93.4 which enables mkinitramfs to build gzip/bzip2/lzma compressed images. Therefor I've set a new variable in /etc/initramfs-tools/update-initramfs.conf # # compress_initramfs [ gzip | bzip2 | lzma ] # compress_initramfs=gzip added the new function verify_compression() to the update-initramfs script which - checks the availability of the compression utility in userspace - matches the kernel's config file against the selected compression method - falls back to gzip compression if either or both are missing and prints verbose messages if that has happened. The method gets passed to mkinitramfs via a new optional argument "-c <COMP>" and mkinitramfs itself verifies that "lzma" or "bzip2" has been passed as argument, or defaults to gzip. (as well if the -c argument has been omitted) Given the fact that gzip, bzip2 and lzma read input from stdin and pass the compressed output to stdout theres no need to change a lot of code here. unified diff attached best regards Bert Schulze
diff -rup a/conf/update-initramfs.conf b/conf/update-initramfs.conf --- a/conf/update-initramfs.conf 2009-03-19 21:16:14.000000000 +0100 +++ b/conf/update-initramfs.conf 2010-02-03 00:41:03.000000000 +0100 @@ -18,3 +18,10 @@ update_initramfs=yes # If set to no leaves no .bak backup files. backup_initramfs=yes + +# +# compress_initramfs [ gzip | bzip2 | lzma ] +# +# Default is gzip + +compress_initramfs=gzip diff -rup a/hook-functions b/hook-functions --- a/hook-functions 2009-06-25 20:28:51.000000000 +0200 +++ b/hook-functions 2010-02-03 01:15:33.000000000 +0100 @@ -465,10 +465,11 @@ usage() Usage: ${0} [OPTION]... -o outfile [version] Options: - -d confdir Specify an alternative configuration directory. - -k Keep temporary directory used to make the image. - -o outfile Write to outfile. - -r root Override ROOT setting in initramfs.conf. + -c compress Utility used to compress the initramfs image. + -d confdir Specify an alternative configuration directory. + -k Keep temporary directory used to make the image. + -o outfile Write to outfile. + -r root Override ROOT setting in initramfs.conf. See mkinitramfs(8) for further details. EOF diff -rup a/mkinitramfs b/mkinitramfs --- a/mkinitramfs 2009-05-18 13:58:41.000000000 +0200 +++ b/mkinitramfs 2010-02-03 01:31:40.000000000 +0100 @@ -11,7 +11,7 @@ errors_to="2>/dev/null" # BUSYBOXDIR="/usr/lib/initramfs-tools/bin/" BUSYBOXDIR="/bin" -OPTIONS=`getopt -o d:ko:r:v -n "$0" -- "$@"` +OPTIONS=`getopt -o d:ko:r:c:v -n "$0" -- "$@"` # Check for non-GNU getopt if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi @@ -40,6 +40,10 @@ while true; do ROOT="$2" shift 2 ;; + -c) + compress="$2" + shift 2 + ;; -v) verbose="y" shift @@ -86,6 +90,10 @@ if [ -n "${UMASK}" ]; then umask "${UMASK}" fi +if [ "bzip2" != "${compress}" ] && [ "lzma" != "${compress}" ]; then + compress=gzip +fi + if [ -z "${outfile}" ]; then usage fi @@ -284,7 +292,7 @@ eval ` find . 4>&-; echo "ec1=$?;" >&4 } | { cpio --quiet --dereference -o -H newc 4>&-; echo "ec2=$?;" >&4 - } | gzip >"${outfile}" + } | ${compress} >"${outfile}" echo "ec3=$?;" >&4 ` if [ "$ec1" -ne 0 ]; then exit "$ec1"; fi diff -rup a/mkinitramfs.8 b/mkinitramfs.8 --- a/mkinitramfs.8 2009-03-19 21:16:14.000000000 +0100 +++ b/mkinitramfs.8 2010-02-03 00:41:03.000000000 +0100 @@ -5,6 +5,8 @@ mkinitramfs \- low-level tool for genera .SH SYNOPSIS .B mkinitramfs +.RB [ \-c +.IR compress ] .RB [ \-d .IR confdir ] .RB [ \-k ] @@ -27,7 +29,7 @@ mkinitramfs \- low-level tool for genera The .B mkinitramfs script generates an initramfs image. -The initramfs is a gzipped cpio archive. The archive can be used on a +The initramfs is a compressed cpio archive. The archive can be used on a different box of the same arch with the corresponding Linux kernel. .B mkinitramfs is meant for advanced usage. On your local box @@ -45,6 +47,10 @@ happens in this early userspace. .SH OPTIONS .TP +\fB \-c \fI compress +Use either gzip, bzip2 or lzma to compress the initramfs image +(defaults to gzip). +.TP \fB \-d \fI confdir Set an alternate configuration directory. diff -rup a/update-initramfs b/update-initramfs --- a/update-initramfs 2009-06-10 15:58:58.000000000 +0200 +++ b/update-initramfs 2010-02-03 01:33:34.000000000 +0100 @@ -88,6 +88,23 @@ version_exists() return $? } +# fallback to gzip if userspace/kernelsupport is missing +verify_compression() +{ + COMP=${compress_initramfs} + [ -z "${COMP}" ] && COMP=gzip + + if [ ! `which ${COMP}` ] ;then + verbose "Missing ${compress_initramfs}, userspace using gzip instead" + COMP=gzip + + elif ! grep -q -i config_rd_`echo ${compress_initramfs}`=y \ + ${BOOTDIR}/config-${version} ;then + verbose "Kernel doesn't support ${compress_initramfs} using gzip instead" + COMP=gzip + fi +} + set_initramfs() { initramfs="${BOOTDIR}/initrd.img-${version}" @@ -152,7 +169,7 @@ remove_initramfs() generate_initramfs() { echo "update-initramfs: Generating ${initramfs}" - OPTS="-o" + OPTS="-c ${COMP} -o" if [ "${verbose}" = 1 ]; then OPTS="-v ${OPTS}" fi @@ -367,6 +384,8 @@ create() usage "Create mode requires a version argument" fi + verify_compression + set_initramfs if [ "${takeover}" = 0 ]; then @@ -405,6 +424,8 @@ update() verbose "Nothing to do, exiting." exit 0 fi + + verify_compression set_initramfs diff -rup a/update-initramfs.conf.5 b/update-initramfs.conf.5 --- a/update-initramfs.conf.5 2009-03-19 21:16:14.000000000 +0100 +++ b/update-initramfs.conf.5 2010-02-03 00:41:03.000000000 +0100 @@ -19,6 +19,9 @@ the \fBupdate_initramfs \-u\fP call. .TP \fB backup_initramfs By default \fBupdate_initramfs\fP keeps an .bak file of the previous initramfs. If set to \fIno\fP the backup initramfs will not be kept. +.TP +\fB compress_initramfs +Specify the method used to compress the initramfs image. If set to lzma or bzip2 the corresponding userspace utility needs to be installed and the kernel must be built with support for it. Otherwise \fBupdate-initramfs\fP will fallback to gzip. .SH AUTHOR The initramfs-tools are written by Maximilian Attems <m...@debian.org>,