qubes-installer-qubes-os/anaconda/data/systemd/anaconda-cleanup-initramfs
2013-01-24 01:45:53 +01:00

36 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# anaconda-cleanup-initramfs - clean up initramfs to save RAM.
#
# Normal systems just throw away the initramfs after boot, since they have a
# copy of it in /boot/initramfs-$(uname -r).img that they can unpack and use
# to shut down the system cleanly. (See dracut-shutdown.service.)
#
# We have to keep initramfs because we don't have it laying around in /boot,
# and we might want to read some files out of it (e.g. /etc/cmdline*)
#
# There are still redundant/unneeded files, though, and we can save RAM by
# cleaning those up.
systemd-notify --pid --status="Removing unneeded files..."
# the runtime has all the firmware/modules we need.
# removing the ssl certs saves another easy ~1MB.
rm -rf /run/initramfs/usr/lib/{firmware,modules} \
/run/initramfs/etc/ssl
# Try to compress the remaining initramfs contents.
# 99% of the RAM used by initramfs is in usr/, so just compress/remove that.
# (this also means we save etc/cmdline* and we don't have to move mounts)
# check for cpio and pigz/gzip.
# (xz would be ~4MB smaller but uses 100MB RAM (!). gzip uses ~2MB.)
type -P cpio >/dev/null || exit 0
gzip=$(type -P pigz || type -P gzip) || exit 0
# systemd-notify --ready --> continue startup, do the rest in the background
systemd-notify --ready --status="Compressing initramfs contents..."
mkdir -p /boot
initramfs=/boot/initramfs-$(uname -r).img
find /run/initramfs/usr | cpio -co 2>/dev/null | $gzip -c > $initramfs
rm -rf /run/initramfs/usr