]> git.ipfire.org Git - thirdparty/dracut.git/commit
Add support for building a squashed initramfs
authorKairui Song <kasong@redhat.com>
Tue, 11 Sep 2018 11:32:24 +0000 (19:32 +0800)
committerHarald Hoyer <harald@hoyer.xyz>
Fri, 21 Sep 2018 08:32:04 +0000 (10:32 +0200)
commit095e1f37c41e8995c95635a47dbe2bf61d8ee2bc
treef300bac6f3cdc6efe4a0e92a715b96c796f5fddd
parentf4334e9bdf5ff85d5f9d9eb12f51a6b78e94101e
Add support for building a squashed initramfs

With all files stored in ramfs, and most of them are not compressed,
the initramfs will take up a lot of memory. Besides, if the file number
is large, each file will waste some memory due to page fragmetation.
This is due to ramfs' design, at least one page will be allocated for
one file however small the file is. On machine with large page size,
this will become worse and waste too many memory.

One approach to reducing the memory usage is to reduce the number of
files that got directly loaded into the root ramfs, and compress files
by put most files will into a read-only squash image and keep a minimum
set of executable and libraries outside as the loader for the squash
image. After the squash image is mounted, the real 'init' will be
executed and then everything behaves as usual.

This patch will introduce a '99squash' module which will never be
included by default. User can force add it, and if it is included,
dracut will perform some extra steps before creating the final image:

For now, "/etc" and "/usr" will be moved into the squashfs image.
"/init" will be renamed to "/init.stock" and replaced by "/init.squash".
Files and folders need to be accessible before mounting the image will
be still avaliable at their original place. And due to squashfs is
readonly, an overlayfs layer will be created on top of squashfs mount
point, as many dracut module require readwrite access to "/etc" and
"/usr", "init.squash" will ultimately call "/init.stock".

An extra systemd service will be installed. This service will umount all
squashfs related mount points right before switch-root to release
resources properly. This service will not actually do anything if
switch-root is not used.

This is very helpful when mem resource is very limited, like Kdump.
According to my tests, this squash module can help save about 35MB of
memory with 64K page size, or about 15MB with 4K page size on an
ordinary kdump capture routine. This module could also help reduce
memory usage for normal boot up process.

Won't change any behavior if squash module is not enabled.

Signed-off-by: Kairui Song <kasong@redhat.com>
dracut.sh
modules.d/99squash/clear-squash.sh [new file with mode: 0755]
modules.d/99squash/init.sh [new file with mode: 0755]
modules.d/99squash/module-setup.sh [new file with mode: 0644]
modules.d/99squash/setup-squash.sh [new file with mode: 0755]
modules.d/99squash/shutdown.sh [new file with mode: 0755]
modules.d/99squash/squash-mnt-clear.service [new file with mode: 0644]