[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#627677: alternative initramfs compressor



Package: live-build
Version: 3.0~a17-1
Severity: wishlist
Tags: patch
User: ubuntu-devel@lists.ubuntu.com
Usertags: origin-ubuntu ubuntu-patch oneiric

We compress the initramfs on the Ubuntu live CD with LZMA to save a bit
of space.  Here's a patch to allow live-build to do this.

Thanks,

-- 
Colin Watson                                       [cjwatson@ubuntu.com]
>From 71d20b7f5a057c0e234fc1080d61a8840d9e0ad6 Mon Sep 17 00:00:00 2001
From: Colin Watson <cjwatson@canonical.com>
Date: Mon, 23 May 2011 15:43:59 +0100
Subject: [PATCH] Add --initramfs-compression option.

---
 functions/defaults.sh         |    4 ++++
 manpages/en/lb_config.1       |    4 ++++
 scripts/build/lb_chroot_hacks |   25 +++++++++++++++++++++++++
 scripts/build/lb_config       |   12 +++++++++++-
 4 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/functions/defaults.sh b/functions/defaults.sh
index a1e5c83..b6824b7 100755
--- a/functions/defaults.sh
+++ b/functions/defaults.sh
@@ -84,6 +84,8 @@ Set_defaults ()
 
 	LZIP_OPTIONS="${LZIP_OPTIONS:---best}"
 
+	LZMA_OPTIONS="${LZMA_OPTIONS:---best}"
+
 	# Setting apt recommends
 	case "${LB_MODE}" in
 		emdebian|progress)
@@ -153,6 +155,8 @@ Set_defaults ()
 			;;
 	esac
 
+	LB_INITRAMFS_COMPRESSION="${LB_INITRAMFS_COMPRESSION:-gzip}"
+
 	# Setting initsystem
 	case "${LB_MODE}" in
 		ubuntu)
diff --git a/manpages/en/lb_config.1 b/manpages/en/lb_config.1
index 5e247b4..a8a9c6f 100644
--- a/manpages/en/lb_config.1
+++ b/manpages/en/lb_config.1
@@ -111,6 +111,8 @@
 .br
 	[\fB\-\-initramfs\fR auto|none|live\-boot|casper]
 .br
+	[\fB\-\-initramfs\-compression\fR bzip2|gzip|lzma]
+.br
 	[\fB\-\-initsystem\fR sysvinit|runit|systemd|upstart|none]
 .br
 	[\fB\-\-interactive\fR shell]
@@ -361,6 +363,8 @@ sets the hostname of the live system.
 sets the path to the includes that live\-build is going to use, e.g. additional minimal documentation that you want to have on all live systems. By default, this is set to /usr/share/live/build/includes/. Choose none to disable inclusion of documentation.
 .IP "\fB\-\-initramfs\fR auto|none|live\-boot|casper" 4
 sets the name of package that contains the live system specific initramfs modification. By default, auto is used, which means that at build time of the image rather than on configuration time, the value will be expanded to casper when building ubuntu systems, to live\-boot for all other systems. Using 'none' is useful if the resulting system image should not be a live image (experimental).
+.IP "\fB\-\-initramfs\-compression\fR bzip2|gzip|lzma]
+defines the compression program to be used to compress the initramfs. Defaults to gzip.
 .IP "\fB\-\-interactive\fR shell" 4
 defines if after the chroot stage and before the beginning of the binary stage, a interactive shell login should be spawned in the chroot in order to allow you to do manual customizations. Once you close the shell with logout or exit, the build will continue as usual. Note that it's strongly discouraged to use this for anything else than testing. Modifications that should be present in all builds of a live system should be properly made through hooks. Everything else destroys the beauty of being able to completely automatise the build process and making it non interactive. By default, this is of course false.
 .IP "\fB\-\-isohybrid\-options\fR \fIOPTION\fR|""\fIOPTIONS\fR""" 4
diff --git a/scripts/build/lb_chroot_hacks b/scripts/build/lb_chroot_hacks
index 194d667..12279fd 100755
--- a/scripts/build/lb_chroot_hacks
+++ b/scripts/build/lb_chroot_hacks
@@ -183,6 +183,31 @@ esac
 
 Chroot chroot "${UPDATE_INITRAMFS_OPTIONS} update-initramfs -k all -t -u"
 
+# We probably ought to use COMPRESS= in a temporary file in
+# /etc/initramfs-tools/conf.d/ instead, but it's hard to pass options that
+# way.
+case "${LB_INITRAMFS_COMPRESSION}" in
+	gzip)
+		;;
+
+	bzip2)
+		for INITRAMFS in $(find chroot/boot -name 'initrd*'); do
+			zcat "${INITRAMFS}" | bzip2 -c ${BZIP2_OPTIONS} > "${INITRAMFS}.new"
+			mv "${INITRAMFS}.new" "${INITRAMFS}"
+		done
+		;;
+
+	lzma)
+		# We probably ought to use COMPRESS= in a temporary file in
+		# /etc/initramfs-tools/conf.d/ instead, but it's hard to
+		# pass options that way.
+		for INITRAMFS in $(find chroot/boot -name 'initrd*'); do
+			zcat "${INITRAMFS}" | lzma -c ${LZMA_OPTIONS} > "${INITRAMFS}.new"
+			mv "${INITRAMFS}.new" "${INITRAMFS}"
+		done
+		;;
+esac
+
 # Ensure readable permissions on initramfs. loop-aes-utils sets umask to
 # protect GPG keys, which live-build does not support.
 # Note: Use find rather than chmod on the wildcard, one never knows what
diff --git a/scripts/build/lb_config b/scripts/build/lb_config
index a2f90eb..f2c6bdc 100755
--- a/scripts/build/lb_config
+++ b/scripts/build/lb_config
@@ -80,6 +80,7 @@ USAGE="${PROGRAM}   [--apt apt|aptitude]\n\
 \t    [--ignore-system-defaults]\n\
 \t    [--includes PATH|none]\n\
 \t    [--initramfs auto|none|live-boot|casper]\n\
+\t    [--initramfs-compression bzip2|gzip|lzma]\n\
 \t    [--initsystem sysvinit|runit|systemd|upstart|none]\n\
 \t    [--interactive shell]\n\
 \t    [--isohybrid-options OPTION|\"OPTIONS\"]\n\
@@ -152,7 +153,7 @@ Local_arguments ()
 	LONG_OPTIONS="apt:,apt-ftp-proxy:,apt-http-proxy:,apt-options:,aptitute-options:,
 		apt-pipeline:,apt-recommends:,apt-secure:,bootstrap:,cache:,cache-indices:,cache-packages:,
 		cache-stages:,debconf-frontend:,debconf-nowarnings:,debconf-priority:,dump,
-		initramfs:,initsystem:,fdisk:,losetup:,mode:,repositories:,root-command:,use-fakeroot:,tasksel:,includes:,
+		initramfs:,initramfs-compression:,initsystem:,fdisk:,losetup:,mode:,repositories:,root-command:,use-fakeroot:,tasksel:,includes:,
 		templates:,architectures:,bootstrap-config:,bootstrap-flavour:,bootstrap-keyring:,clean,
 		distribution:,parent-distribution:,parent-debian-installer-distribution:,parent-mirror-bootstrap:,parent-mirror-chroot:,parent-mirror-chroot-security:,parent-mirror-chroot-volatile:,parent-mirror-chroot-backports:,parent-mirror-binary:,
 		parent-mirror-binary-security:,parent-mirror-binary-volatile:,parent-mirror-binary-backports:,parent-mirror-debian-installer:,
@@ -316,6 +317,11 @@ Local_arguments ()
 				shift 2
 				;;
 
+			--initramfs-compression)
+				LB_INITRAMFS_COMPRESSION="${2}"
+				shift 2
+				;;
+
 			--initsystem)
 				LB_INITSYSTEM="${2}"
 				shift 2
@@ -951,6 +957,10 @@ LB_DEBCONF_PRIORITY="${LB_DEBCONF_PRIORITY}"
 # (Default: ${LB_INITRAMFS})
 LB_INITRAMFS="${LB_INITRAMFS}"
 
+# \$LB_INITRAMFS_COMPRESSION: set initramfs compression
+# (Default: ${LB_INITRAMFS_COMPRESSION})
+LB_INITRAMFS_COMPRESSION="${LB_INITRAMFS_COMPRESSION}"
+
 # \$LB_INITSYSTEM: set init system
 # (Default: ${LB_INITSYSTEM})
 LB_INITSYSTEM="${LB_INITSYSTEM}"
-- 
1.7.4.1


Reply to: