blob: f2bd274408d4f3484c1703a8e3fe71f11e13c5a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#!/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
|