From 30d2e05eed7a8558afa77947616ebab0c4529172 Mon Sep 17 00:00:00 2001 From: Will Woods Date: Fri, 8 Feb 2013 18:04:15 -0500 Subject: Add dracut/save-initramfs.sh Since dracut dropped its slightly-too-clever trick to save a copy of itself at /run/initramfs, we need to locate or save a copy of initramfs so we can switch back into it and shut down properly. So: first, check to see if we're running off media; if so, we can just use the initramfs from the media. Easy! Otherwise we need to save a copy. The anaconda initramfs (for current F18-ish images on x86_64) uses about 96M RAM when unpacked, which is a bit wasteful. To save RAM we can filter out some stuff we don't need for shutdown: * kernel modules: ~39M * firmware: ~9M * python: ~8M * ssl certs: ~1M * fsck binaries: ~1M which leaves us with 38M of data. We can reduce this to 18M by gzipping it, but that delays startup for 3s on my test system. (Using xz would save 4.5M, but it takes 15s (!) and uses 100M RAM (!!).) Using gzip -1 drops this to just over 1 second; RAM use goes up by 1M, but that seems like a reasonable tradeoff. If `pigz` is available, that gets used instead, which makes the delay basically negligible on any modern multicore system. --- dracut/Makefile.am | 3 ++- dracut/module-setup.sh | 5 +++-- dracut/save-initramfs.sh | 27 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100755 dracut/save-initramfs.sh diff --git a/dracut/Makefile.am b/dracut/Makefile.am index cb38e759c..7646e2377 100644 --- a/dracut/Makefile.am +++ b/dracut/Makefile.am @@ -38,7 +38,8 @@ dist_dracut_SCRIPTS = module-setup.sh \ fetch-kickstart-disk \ fetch-updates-disk \ parse-kickstart \ - anaconda-modprobe.sh + anaconda-modprobe.sh \ + save-initramfs.sh MAINTAINERCLEANFILES = Makefile.in diff --git a/dracut/module-setup.sh b/dracut/module-setup.sh index be2bd7103..cdf3e4f03 100755 --- a/dracut/module-setup.sh +++ b/dracut/module-setup.sh @@ -29,8 +29,9 @@ install() { inst_hook initqueue/settled 00 "$moddir/anaconda-ks-sendheaders.sh" inst_hook initqueue/online 80 "$moddir/anaconda-netroot.sh" inst "$moddir/anaconda-diskroot" "/sbin/anaconda-diskroot" - inst_hook pre-pivot 99 "$moddir/anaconda-copy-ks.sh" - inst_hook pre-pivot 99 "$moddir/anaconda-copy-cmdline.sh" + inst_hook pre-pivot 50 "$moddir/anaconda-copy-ks.sh" + inst_hook pre-pivot 50 "$moddir/anaconda-copy-cmdline.sh" + inst_hook pre-pivot 99 "$moddir/save-initramfs.sh" # kickstart parsing, WOOOO inst_hook initqueue/online 10 "$moddir/fetch-kickstart-net.sh" inst "$moddir/fetch-kickstart-disk" "/sbin/fetch-kickstart-disk" diff --git a/dracut/save-initramfs.sh b/dracut/save-initramfs.sh new file mode 100755 index 000000000..4ebbdfe70 --- /dev/null +++ b/dracut/save-initramfs.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# save-initramfs - save a copy of initramfs for shutdown/eject, if needed + +command -v config_get >/dev/null || . /lib/anaconda-lib.sh +initramfs="" + +# First, check to see if we can find a copy of initramfs laying around +for i in images/pxeboot/initrd.img ppc/ppc64/initrd.img images/initrd.img; do + [ -f $repodir/$i ] && initramfs=$repodir/$i && break +done + + +# If we didn't find an initramfs image, save a copy of it +if [ -z "$initramfs" ]; then + initramfs=/run/initramfs/initramfs-saved.cpio.gz + gzip=$(type -P pigz || type -P gzip) + # Prune out things we don't need - modules & firmware, python, overlay file + find / -xdev | \ + grep -Ev 'lib/modules|lib/firmware|python|overlay|etc/ssl|fsck' | \ + cpio -co 2>/dev/null | $gzip -c1 > $initramfs +fi + + +# Make sure dracut-shutdown.service can find the initramfs later. +mkdir -p $NEWROOT/boot +ln -s $initramfs $NEWROOT/boot/initramfs-$(uname -r).img +# NOTE: $repodir must also be somewhere under /run for this to work correctly -- cgit