9f65cc
From 39d06b934fd4bec88b0945b5277407d7b5510c22 Mon Sep 17 00:00:00 2001
9f65cc
From: Kairui Song <kasong@redhat.com>
9f65cc
Date: Mon, 15 Feb 2021 22:58:20 +0800
9f65cc
Subject: [PATCH] feat(squash): install and depmod modules seperately
9f65cc
9f65cc
Separately install the modules required for squash image setup.
9f65cc
These modules can be deleted after squash image setup to save
9f65cc
memory.
9f65cc
9f65cc
Signed-off-by: Kairui Song <kasong@redhat.com>
9f65cc
(cherry picked from commit 5a18b24a8b9c20c98f711963ce5407ceb2f3d57b)
9f65cc
9f65cc
Cherry-picked from: 5a18b24a8b9c20c98f711963ce5407ceb2f3d57b
9f65cc
Resolves: #1959336
9f65cc
---
9f65cc
 modules.d/99squash/init-squash.sh  |  3 +++
9f65cc
 modules.d/99squash/module-setup.sh | 12 +++++-------
9f65cc
 2 files changed, 8 insertions(+), 7 deletions(-)
9f65cc
9f65cc
diff --git a/modules.d/99squash/init-squash.sh b/modules.d/99squash/init-squash.sh
9f65cc
index 449585f0..ecb6cc58 100755
9f65cc
--- a/modules.d/99squash/init-squash.sh
9f65cc
+++ b/modules.d/99squash/init-squash.sh
9f65cc
@@ -34,6 +34,9 @@ if [ $? != 0 ]; then
9f65cc
     echo "Unable to setup overlay module"
9f65cc
 fi
9f65cc
 
9f65cc
+# These modules are no longer needed, delete to save memory
9f65cc
+rm -rf /usr/lib/modules/
9f65cc
+
9f65cc
 [ ! -d "$SQUASH_MNT" ] && \
9f65cc
 	mkdir -m 0755 -p $SQUASH_MNT
9f65cc
 
9f65cc
diff --git a/modules.d/99squash/module-setup.sh b/modules.d/99squash/module-setup.sh
9f65cc
index c0eb4acd..ad619176 100644
9f65cc
--- a/modules.d/99squash/module-setup.sh
9f65cc
+++ b/modules.d/99squash/module-setup.sh
9f65cc
@@ -18,10 +18,6 @@ depends() {
9f65cc
     return 0
9f65cc
 }
9f65cc
 
9f65cc
-installkernel() {
9f65cc
-    hostonly="" instmods -c squashfs loop overlay
9f65cc
-}
9f65cc
-
9f65cc
 installpost() {
9f65cc
     local squash_candidate=( "usr" "etc" )
9f65cc
 
9f65cc
@@ -36,7 +32,6 @@ installpost() {
9f65cc
     # - Files need to be accessible without mounting the squash image
9f65cc
     # - Initramfs marker
9f65cc
     for file in \
9f65cc
-        "$squash_dir"/usr/lib/modules/*/modules.* \
9f65cc
         "$squash_dir"/usr/lib/dracut/* \
9f65cc
         "$squash_dir"/etc/initrd-release
9f65cc
     do
9f65cc
@@ -46,8 +41,7 @@ installpost() {
9f65cc
     done
9f65cc
 
9f65cc
     # Install required files for the squash image setup script.
9f65cc
-    hostonly="" instmods "loop" "squashfs" "overlay"
9f65cc
-    inst_multiple modprobe mount mkdir ln echo
9f65cc
+    inst_multiple modprobe mount mkdir ln echo rm
9f65cc
 
9f65cc
     mv "$initdir"/init "$initdir"/init.orig
9f65cc
     inst "$moddir"/init-squash.sh /init
9f65cc
@@ -63,6 +57,10 @@ installpost() {
9f65cc
         find "$initdir/$folder/" -not -type d \
9f65cc
             -exec bash -c 'mv -f "$squash_dir${1#$initdir}" "$1"' -- "{}" \;
9f65cc
     done
9f65cc
+
9f65cc
+    # Install required modules for the squash image init script.
9f65cc
+    hostonly="" instmods "loop" "squashfs" "overlay"
9f65cc
+    dracut_kernel_post
9f65cc
 }
9f65cc
 
9f65cc
 install() {
9f65cc