You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10 lines
174 B

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>
7 years ago
#!/bin/sh
SQUASH_MNT_REC=/squash/mounts
SQUASH_MNTS=( )
while read mnt; do
SQUASH_MNTS+=( "$mnt" )
done <<< "$(cat $SQUASH_MNT_REC)"
umount --lazy -- ${SQUASH_MNTS[@]}