From 62453b92723bf04239b06f8966f256ef0feb233e Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Mon, 14 Mar 2016 12:46:53 +0100 Subject: Added: ENABLE_REDUCE - down to 160MB used space,fix-resolve,fix-machineid --- README.md | 5 +++ bootstrap.d/13-kernel.sh | 6 +++- bootstrap.d/50-firstboot.sh | 6 ++++ files/apt/02nocache | 2 ++ files/apt/03compress | 2 ++ files/apt/04norecommends | 2 ++ files/apt/05nodoc | 9 +++++ files/dpkg/01nodoc | 9 +++++ files/firstboot/23-generate-machineid.sh | 3 ++ files/firstboot/24-create-resolv-symlink.sh | 4 +++ rpi2-gen-image.sh | 53 +++++++++++++++++++++++++---- 11 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 files/apt/02nocache create mode 100644 files/apt/03compress create mode 100644 files/apt/04norecommends create mode 100644 files/apt/05nodoc create mode 100644 files/dpkg/01nodoc create mode 100644 files/firstboot/23-generate-machineid.sh create mode 100644 files/firstboot/24-create-resolv-symlink.sh diff --git a/README.md b/README.md index f2da0f4..6f5e744 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ APT_SERVER=ftp.de.debian.org APT_PROXY="http://127.0.0.1:3142/" ./rpi2-gen-image ENABLE_MINBASE=true ./rpi2-gen-image.sh BUILD_KERNEL=true ENABLE_MINBASE=true ENABLE_IPV6=false ./rpi2-gen-image.sh BUILD_KERNEL=true KERNEL_SRCDIR=/tmp/linux ./rpi2-gen-image.sh +ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh ``` #### APT settings: @@ -129,6 +130,9 @@ Install a user defined window manager for the X Window System. To make sure all ##### `ENABLE_MINBASE`=false Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB. +##### `ENABLE_REDUCE`=false +Reduce the disk usage by deleting all man pages and doc files (harsh). APT will be configured to use compressed package repository lists and no package caching files. If `ENABLE_MINGPU`=true unnecessary start.elf and fixup.dat files will also be removed from the boot partition. This will make it possible to generate output OS images with about 160MB of used disk space. It's recommended to use this parameter in combination with `ENABLE_MINBASE`=true. + ##### `ENABLE_UBOOT`=false Replace default RPi2 second stage bootloader (bootcode.bin) with U-Boot bootloader. U-Boot can boot images via the network using the BOOTP/TFTP protocol. @@ -204,6 +208,7 @@ All the required configuration files that will be copied to the generated OS ima | Directory | Description | | --- | --- | | `boot` | Boot and RPi2 configuration files | +| `dpkg` | Package Manager configuration | | `firstboot` | Scripts that get executed on first boot | | `iptables` | Firewall configuration files | | `locales` | Locales configuration | diff --git a/bootstrap.d/13-kernel.sh b/bootstrap.d/13-kernel.sh index 5163f0d..798a5ce 100644 --- a/bootstrap.d/13-kernel.sh +++ b/bootstrap.d/13-kernel.sh @@ -52,7 +52,11 @@ if [ "$BUILD_KERNEL" = true ] ; then fi # Install kernel modules - make -C $R/usr/src/linux ARCH=${KERNEL_ARCH} CROSS_COMPILE=${CROSS_COMPILE} INSTALL_MOD_PATH=../../.. modules_install + if [ "$ENABLE_REDUCE" = true ] ; then + make -C $R/usr/src/linux ARCH=${KERNEL_ARCH} CROSS_COMPILE=${CROSS_COMPILE} INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install + else + make -C $R/usr/src/linux ARCH=${KERNEL_ARCH} CROSS_COMPILE=${CROSS_COMPILE} INSTALL_MOD_PATH=../../.. modules_install + fi # Install kernel headers if [ "$KERNEL_HEADERS" = true ] ; then diff --git a/bootstrap.d/50-firstboot.sh b/bootstrap.d/50-firstboot.sh index 78197fd..f3deb18 100644 --- a/bootstrap.d/50-firstboot.sh +++ b/bootstrap.d/50-firstboot.sh @@ -19,6 +19,12 @@ if [ "$EXPANDROOT" = true ] ; then cat files/firstboot/22-expandroot.sh >> $R/etc/rc.firstboot fi +# Ensure that dbus machine-id exists +cat files/firstboot/23-generate-machineid.sh >> $R/etc/rc.firstboot + +# Create /etc/resolv.conf symlink +cat files/firstboot/24-create-resolv-symlink.sh >> $R/etc/rc.firstboot + # Finalize rc.firstboot script cat files/firstboot/99-finish.sh >> $R/etc/rc.firstboot chmod +x $R/etc/rc.firstboot diff --git a/files/apt/02nocache b/files/apt/02nocache new file mode 100644 index 0000000..ed295c1 --- /dev/null +++ b/files/apt/02nocache @@ -0,0 +1,2 @@ +Dir::Cache::pkgcache ""; +Dir::Cache::srcpkgcache ""; diff --git a/files/apt/03compress b/files/apt/03compress new file mode 100644 index 0000000..9dd10cc --- /dev/null +++ b/files/apt/03compress @@ -0,0 +1,2 @@ +Acquire::GzipIndexes "true"; +Acquire::CompressionTypes::Order:: "gz"; diff --git a/files/apt/04norecommends b/files/apt/04norecommends new file mode 100644 index 0000000..b3cfff9 --- /dev/null +++ b/files/apt/04norecommends @@ -0,0 +1,2 @@ +APT::Install-Suggests "0"; +APT::Install-Recommends "0"; diff --git a/files/apt/05nodoc b/files/apt/05nodoc new file mode 100644 index 0000000..87b8255 --- /dev/null +++ b/files/apt/05nodoc @@ -0,0 +1,9 @@ +path-exclude /usr/share/doc/* +path-include /usr/share/doc/*/copyright +path-exclude /usr/share/man/* +path-exclude /usr/share/groff/* +path-exclude /usr/share/info/* +path-exclude /usr/share/lintian/* +path-exclude /usr/share/linda/* +path-exclude /usr/share/locale/* +path-include /usr/share/locale/en* diff --git a/files/dpkg/01nodoc b/files/dpkg/01nodoc new file mode 100644 index 0000000..c17061f --- /dev/null +++ b/files/dpkg/01nodoc @@ -0,0 +1,9 @@ +path-exclude=/usr/share/doc/* +path-include=/usr/share/doc/*/copyright +path-exclude=/usr/share/man/* +path-exclude=/usr/share/groff/* +path-exclude=/usr/share/info/* +path-exclude=/usr/share/lintian/* +path-exclude=/usr/share/linda/* +path-exclude=/usr/share/locale/* +path-include=/usr/share/locale/en* diff --git a/files/firstboot/23-generate-machineid.sh b/files/firstboot/23-generate-machineid.sh new file mode 100644 index 0000000..dca48b3 --- /dev/null +++ b/files/firstboot/23-generate-machineid.sh @@ -0,0 +1,3 @@ +logger -t "rc.firstboot" "Generating D-Bus machine-id" +rm -f /var/lib/dbus/machine-id +dbus-uuidgen --ensure diff --git a/files/firstboot/24-create-resolv-symlink.sh b/files/firstboot/24-create-resolv-symlink.sh new file mode 100644 index 0000000..e4a65b4 --- /dev/null +++ b/files/firstboot/24-create-resolv-symlink.sh @@ -0,0 +1,4 @@ +logger -t "rc.firstboot" "Creating /etc/resolv.conf symlink" +if [ -f "/run/systemd/resolve/resolv.conf" ] ; then + ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf +fi diff --git a/rpi2-gen-image.sh b/rpi2-gen-image.sh index ec14e25..ed7fc02 100755 --- a/rpi2-gen-image.sh +++ b/rpi2-gen-image.sh @@ -89,6 +89,7 @@ ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false} # Advanced settings ENABLE_MINBASE=${ENABLE_MINBASE:=false} +ENABLE_REDUCE=${ENABLE_REDUCE:=flase} ENABLE_UBOOT=${ENABLE_UBOOT:=false} ENABLE_FBTURBO=${ENABLE_FBTURBO:=false} ENABLE_HARDNET=${ENABLE_HARDNET:=false} @@ -296,8 +297,44 @@ EOF rm -rf "${R}/chroot_scripts" fi -## Cleanup -chroot_exec apt-get purge -q -y --force-yes apt-utils +# Remove apt-utils +chroot_exec apt-get purge -qq -y --force-yes apt-utils + +# Reduce the image size by removing and compressing +if [ "$ENABLE_REDUCE" = true ] ; then + # Install dpkg configuration fragment file + install_readonly files/dpkg/01nodoc $R/etc/dpkg/dpkg.cfg.d/01nodoc + + # Install APT configuration fragment files + install_readonly files/apt/02nocache $R/etc/apt/apt.conf.d/02nocache + install_readonly files/apt/03compress $R/etc/apt/apt.conf.d/03compress + install_readonly files/apt/04norecommends $R/etc/apt/apt.conf.d/04norecommends + + # Remove APT cache files + rm -fr $R/var/cache/apt/pkgcache.bin + rm -fr $R/var/cache/apt/srcpkgcache.bin + + # Remove all doc and man files + find $R/usr/share/doc -depth -type f ! -name copyright | xargs rm || true + find $R/usr/share/doc -empty | xargs rmdir || true + rm -rf $R/usr/share/man $R/usr/share/groff $R/usr/share/info $R/usr/share/lintian $R/usr/share/linda $R/var/cache/man + + # Remove all translation files + find $R/usr/share/locale -mindepth 1 -maxdepth 1 ! -name 'en' | xargs rm -r + + # Clean APT list of repositories + rm -fr $R/var/lib/apt/lists/* + chroot_exec apt-get -qq -y update + + if [ "$ENABLE_MINGPU" = true ] ; then + rm -f $R/boot/firmware/start.elf + rm -f $R/boot/firmware/fixup.dat + rm -f $R/boot/firmware/start_x.elf + rm -f $R/boot/firmware/fixup_x.dat + fi +fi + +# APT Cleanup chroot_exec apt-get -y clean chroot_exec apt-get -y autoclean chroot_exec apt-get -y autoremove @@ -306,19 +343,21 @@ chroot_exec apt-get -y autoremove umount -l $R/proc umount -l $R/sys +# Clean up directories +rm -rf $R/run +rm -rf $R/tmp/* + # Clean up files rm -f $R/etc/apt/sources.list.save rm -f $R/etc/resolvconf/resolv.conf.d/original -rm -rf $R/run -mkdir -p $R/run rm -f $R/etc/*- rm -f $R/root/.bash_history -rm -rf $R/tmp/* rm -f $R/var/lib/urandom/random-seed -[ -L $R/var/lib/dbus/machine-id ] || rm -f $R/var/lib/dbus/machine-id +rm -f $R/var/lib/dbus/machine-id rm -f $R/etc/machine-id -rm -fr $R/etc/apt/apt.conf.d/10proxy +rm -f $R/etc/apt/apt.conf.d/10proxy rm -f $R/etc/resolv.conf +rm -f "${R}${QEMU_BINARY}" # Calculate size of the chroot directory in KB CHROOT_SIZE=$(expr `du -s $R | awk '{ print $1 }'`) -- cgit v1.2.3