Bug#886337: live-boot-initramfs-tools: Please support building smaller initrd

2018-01-04 Thread Benjamin Drung
Package: live-boot-initramfs-tools
Version: 1:20170623
Severity: normal
Tags: patch

Hi,

Please add several environment variables to strip down the initrd size
(for minimal systems that do not need all features). This allows me to
reduce the initrd size from 8.5 MiB to 8.0 MiB when also using busybox's
mount (see Debian bug #868559) and wget (see Debian bug #885455). A
tested patch is attached.

-- 
Benjamin Drung
System Developer
Debian & Ubuntu Developer

ProfitBricks GmbH
Greifswalder Str. 207
D - 10405 Berlin

Email: benjamin.dr...@profitbricks.com
URL: https://www.profitbricks.de

Sitz der Gesellschaft: Berlin
Registergericht: Amtsgericht Charlottenburg, HRB 125506 B
Geschäftsführer: Achim Weiss, Matthias Steinberg
>From 0e3f0bd0705a8395c93bf212d7b7051fb87319da Mon Sep 17 00:00:00 2001
From: Benjamin Drung 
Date: Thu, 4 Jan 2018 15:05:37 +0100
Subject: [PATCH] Support building smaller initrd

Add several environment variables to strip down the initrd size (for
minimal systems that do not need all features). This allows me to reduce
the initrd size from 8.5 MiB to 8.0 MiB when also using busybox's
mount (see Debian bug #868559) and wget (see Debian bug #885455).

Signed-off-by: Benjamin Drung 
---
 backend/initramfs-tools/live.hook | 86 +++
 manpages/en/live-boot.7   | 25 
 2 files changed, 77 insertions(+), 34 deletions(-)

diff --git a/backend/initramfs-tools/live.hook 
b/backend/initramfs-tools/live.hook
index 97f4c5e..41ba7f0 100755
--- a/backend/initramfs-tools/live.hook
+++ b/backend/initramfs-tools/live.hook
@@ -53,12 +53,15 @@ do
 done
 
 # udev dependencies
-for FILE in /lib/udev/*_id
-do
-   copy_exec "${FILE}"
-done
+if [ "${MINIMAL-}" != "y" ]
+then
+   for FILE in /lib/udev/*_id
+   do
+   copy_exec "${FILE}"
+   done
+fi
 
-if [ -e /lib/udev/rules.d/60-cdrom_id.rules ]
+if [ -e /lib/udev/rules.d/60-cdrom_id.rules ] && [ "${DISABLE_CDROM-}" != "y" ]
 then
mkdir -p "${DESTDIR}/lib/udev/rules.d"
cp -p /lib/udev/rules.d/60-cdrom_id.rules "${DESTDIR}/lib/udev/rules.d"
@@ -103,7 +106,7 @@ manual_add_modules hfsplus
 # Filesystem: jffs2
 manual_add_modules jffs2
 
-if [ -x /usr/bin/rsync ]
+if [ -x /usr/bin/rsync ] && [ "${MINIMAL-}" != "y" ]
 then
copy_exec /usr/bin/rsync /bin
 fi
@@ -120,25 +123,37 @@ manual_add_modules aufs
 manual_add_modules overlay
 
 # Filesystem: vfat
-manual_add_modules nls_cp437
-manual_add_modules nls_iso8859-1
-manual_add_modules nls_utf8
-manual_add_modules nls_ascii
-manual_add_modules vfat
+if [ "${DISABLE_FAT-}" != "y" ]
+then
+   manual_add_modules nls_cp437
+   manual_add_modules nls_iso8859-1
+   manual_add_modules nls_utf8
+   manual_add_modules nls_ascii
+   manual_add_modules vfat
+fi
 
 # Filesystem: ntfs
-manual_add_modules ntfs
+if [ "${DISABLE_NTFS-}" != "y" ]
+then
+   manual_add_modules ntfs
+fi
 
 [ "${QUIET}" ] || echo -n " devices"
 # Hardware: cdrom
-manual_add_modules ide-cd
-manual_add_modules ide-generic
-manual_add_modules ohci1394
-manual_add_modules sbp2
-manual_add_modules sr_mod
+if [ "${DISABLE_CDROM-}" != "y" ]
+then
+   manual_add_modules ide-cd
+   manual_add_modules ide-generic
+   manual_add_modules ohci1394
+   manual_add_modules sbp2
+   manual_add_modules sr_mod
+fi
 
 # Hardware: usb
-manual_add_modules sd_mod
+if [ "${DISABLE_USB-}" != "y" ]
+then
+   manual_add_modules sd_mod
+fi
 
 # Hardware: network
 auto_add_modules net
@@ -194,24 +209,27 @@ then
 fi
 
 # FUSE kernel module
-manual_add_modules fuse
-
-# FUSE filesystem: httpfs2
-if [ -x /usr/bin/httpfs2_ssl ]
-then
-   [ "${QUIET}" ] || echo -n " httpfs:ssl"
-   copy_exec /usr/bin/httpfs2_ssl /bin/httpfs
-elif [ -x /usr/bin/httpfs2 ]
+if [ "${DISABLE_FUSE-}" != "y" ]
 then
-   [ "${QUIET}" ] || echo -n " httpfs"
-   copy_exec /usr/bin/httpfs2 /bin/httpfs
-fi
+   manual_add_modules fuse
 
-# FUSE filesystem: curlftpfs
-if [ -x /usr/bin/curlftpfs ]
-then
-   [ "${QUIET}" ] || echo -n " ftpfs"
-   copy_exec /usr/bin/curlftpfs /bin
+   # FUSE filesystem: httpfs2
+   if [ -x /usr/bin/httpfs2_ssl ]
+   then
+   [ "${QUIET}" ] || echo -n " httpfs:ssl"
+   copy_exec /usr/bin/httpfs2_ssl /bin/httpfs
+   elif [ -x /usr/bin/httpfs2 ]
+   then
+   [ "${QUIET}" ] || echo -n " httpfs"
+   copy_exec /usr/bin/httpfs2 /bin/httpfs
+   fi
+
+   # FUSE filesystem: curlftpfs
+   if [ -x /usr/bin/curlftpfs ]
+   then
+   [ "${QUIET}" ] || echo -n " ftpfs"
+   copy_exec /usr/bin/curlftpfs /bin
+   fi
 fi
 
 # iSCSI
diff --git a/manpages/en/live-boot.7 b/manpages/en/live-boot.7
index 72184cc..e0ce482 100644
--- a/manpages/en/live-boot.7
+++ b/manpages/en/live-boot.7
@@ -24,6 +24,31 @@ In addition, there are some more boot parameters to 

Bug#886328: live-boot: Please use /run/live instead of /lib/live/mount

2018-01-04 Thread Benjamin Drung
Source: live-boot
Version: 1:20170623
Severity: normal
Tags: patch

Currently live-boot mounts following things:

  /lib/live/mount/medium: the live media mounted read-only
  /lib/live/mount/rootfs/filesystem.{squashfs,ext*,...}: the root fs image
  /lib/live/mount/overlay: the copy-on-write content from aufs
  /lib/live/mount/findiso: the loop-mounted iso image when using findiso
  /lib/live/mount/persistence/*: persistent devices with copy-on-write overlay

Some of these mounts are mounted in /live before they are moved to their
correct place. Since the final root filesystem is mounted in /root and
run-init switches to it, special care needs to be taken when moving the
mount points around.

/lib/live/mount/overlay is not accessible any more in the live system:

$ df -h
/dev/loop0 169M  169M 0 100% /lib/live/mount/rootfs/root.squashfs
tmpfs  744M 0  744M   0% /lib/live/mount/overlay
overlay1,5G 1001M  536M  66% /

The early initramfs stage mounts tmpfs on /run which doesn't need to be
moved once the final root filesystem is in place. The mount points do
not need much space and can live on /run/live without problems. Since
these mount points are run-time variable data, they fit perfectly for
/run and comply with FHS 3.0.

Therefore move /lib/live/mount to /run/live and skip the intermedia
/live mount points. This reduces code and complexity. A tested patch is
attached.

See also for the previous larger layout change:
https://lists.debian.org/debian-live/2012/10/msg00021.html

-- 
Benjamin Drung
System Developer
Debian & Ubuntu Developer

ProfitBricks GmbH
Greifswalder Str. 207
D - 10405 Berlin

Email: benjamin.dr...@profitbricks.com
URL: https://www.profitbricks.de

Sitz der Gesellschaft: Berlin
Registergericht: Amtsgericht Charlottenburg, HRB 125506 B
Geschäftsführer: Achim Weiss, Matthias Steinberg
>From 3f97c0d3153c2073eb93473eeb26d2f8153f6464 Mon Sep 17 00:00:00 2001
From: Benjamin Drung 
Date: Thu, 4 Jan 2018 11:02:32 +0100
Subject: [PATCH] Use /run/live instead of /lib/live/mount

Currently live-boot mounts following things:

  /lib/live/mount/medium: the live media mounted read-only
  /lib/live/mount/rootfs/filesystem.{squashfs,ext*,...}: the root fs image
  /lib/live/mount/overlay: the copy-on-write content from aufs
  /lib/live/mount/findiso: the loop-mounted iso image when using findiso
  /lib/live/mount/persistence/*: persistent devices with copy-on-write overlay

Some of these mounts are mounted in /live before they are moved to their
correct place. Since the final root filesystem is mounted in /root and
run-init switches to it, special care needs to be taken when moving the
mount points around.

/lib/live/mount/overlay is not accessible any more in the live system:

$ df -h
/dev/loop0 169M  169M 0 100% /lib/live/mount/rootfs/root.squashfs
tmpfs  744M 0  744M   0% /lib/live/mount/overlay
overlay1,5G 1001M  536M  66% /

The early initramfs stage mounts tmpfs on /run which doesn't need to be
moved once the final root filesystem is in place. The mount points do
not need much space and can live on /run/live without problems. Since
these mount points are run-time variable data, they fit perfectly for
/run and comply with FHS 3.0.

Therefore move /lib/live/mount to /run/live and skip the intermedia
/live mount points. This reduces code and complexity.

See also for the previous larger layout change:
https://lists.debian.org/debian-live/2012/10/msg00021.html

Signed-off-by: Benjamin Drung 
---
 backend/initramfs-tools/live.hook  |  2 +-
 components/0001-init-vars.sh   |  2 +-
 components/2010-remove-persistence |  2 +-
 components/9990-main.sh| 20 +++
 components/9990-misc-helpers.sh| 24 +++---
 components/9990-overlay.sh | 41 +++---
 6 files changed, 25 insertions(+), 66 deletions(-)

diff --git a/backend/initramfs-tools/live.hook 
b/backend/initramfs-tools/live.hook
index 1ce922d..97f4c5e 100755
--- a/backend/initramfs-tools/live.hook
+++ b/backend/initramfs-tools/live.hook
@@ -8,7 +8,7 @@ set -e
 
 # Reading configuration file from filesystem and live-media
 for _FILE in /etc/live/boot.conf /etc/live/boot/* \
-/lib/live/mount/media/live/boot.conf 
/lib/live/mount/media/live/boot/*
+/run/live/medium/live/boot.conf /run/live/medium/live/boot/*
 do
if [ -e "${_FILE}" ]
then
diff --git a/components/0001-init-vars.sh b/components/0001-init-vars.sh
index 7e69956..603cf43 100755
--- a/components/0001-init-vars.sh
+++ b/components/0001-init-vars.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-mountpoint="/live/medium"
+mountpoint="/run/live/medium"
 alt_mountpoint="/media"
 LIVE_MEDIA_PATH="live"
 HOSTNAME="host"
diff --git a/components/2010-remove-persistence 
b/components/2010-remove-persistence
index 5dcf0c0..717a408 100755
--- a/components/2010-remove-persistence
+++