|
|
9f65cc |
From 9a6b40f023db3763694fb99a820f11017cc56811 Mon Sep 17 00:00:00 2001
|
|
|
9f65cc |
From: Kairui Song <kasong@redhat.com>
|
|
|
9f65cc |
Date: Tue, 9 Jun 2020 00:41:24 +0800
|
|
|
9f65cc |
Subject: [PATCH] 99squash: simplify the code
|
|
|
9f65cc |
|
|
|
9f65cc |
The new dracutsysrootdir could be used to replace the shell function
|
|
|
9f65cc |
required_in_root, so drop it and also simplify the code.
|
|
|
9f65cc |
|
|
|
9f65cc |
Signed-off-by: Kairui Song <kasong@redhat.com>
|
|
|
9f65cc |
(cherry picked from commit 4159819fbb20fca8c0a80ddb17e211f481ec7717)
|
|
|
9f65cc |
|
|
|
9f65cc |
Resolves: #1959336
|
|
|
9f65cc |
---
|
|
|
9f65cc |
dracut.sh | 89 ++++++++++++++-------------------------------------------------
|
|
|
9f65cc |
1 file changed, 20 insertions(+), 69 deletions(-)
|
|
|
9f65cc |
|
|
|
9f65cc |
diff --git a/dracut.sh b/dracut.sh
|
|
|
9f65cc |
index b9657dc6..176b2259 100755
|
|
|
9f65cc |
--- a/dracut.sh
|
|
|
9f65cc |
+++ b/dracut.sh
|
|
|
9f65cc |
@@ -1736,23 +1736,19 @@ fi
|
|
|
9f65cc |
|
|
|
9f65cc |
if dracut_module_included "squash"; then
|
|
|
9f65cc |
dinfo "*** Install squash loader ***"
|
|
|
9f65cc |
- if ! check_kernel_config CONFIG_SQUASHFS; then
|
|
|
9f65cc |
- dfatal "CONFIG_SQUASHFS have to be enabled for dracut squash module to work"
|
|
|
9f65cc |
- exit 1
|
|
|
9f65cc |
- fi
|
|
|
9f65cc |
- if ! check_kernel_config CONFIG_OVERLAY_FS; then
|
|
|
9f65cc |
- dfatal "CONFIG_OVERLAY_FS have to be enabled for dracut squash module to work"
|
|
|
9f65cc |
- exit 1
|
|
|
9f65cc |
- fi
|
|
|
9f65cc |
- if ! check_kernel_config CONFIG_DEVTMPFS; then
|
|
|
9f65cc |
- dfatal "CONFIG_DEVTMPFS have to be enabled for dracut squash module to work"
|
|
|
9f65cc |
+ for config in \
|
|
|
9f65cc |
+ CONFIG_SQUASHFS \
|
|
|
9f65cc |
+ CONFIG_OVERLAY_FS \
|
|
|
9f65cc |
+ CONFIG_DEVTMPFS;
|
|
|
9f65cc |
+ do
|
|
|
9f65cc |
+ if ! check_kernel_config $config; then
|
|
|
9f65cc |
+ dfatal "$config have to be enabled for dracut squash module to work"
|
|
|
9f65cc |
exit 1
|
|
|
9f65cc |
- fi
|
|
|
9f65cc |
+ fi
|
|
|
9f65cc |
+ done
|
|
|
9f65cc |
|
|
|
9f65cc |
readonly squash_dir="$initdir/squash/root"
|
|
|
9f65cc |
- readonly squash_img=$initdir/squash/root.img
|
|
|
9f65cc |
-
|
|
|
9f65cc |
- # Currently only move "usr" "etc" to squashdir
|
|
|
9f65cc |
+ readonly squash_img="$initdir/squash/root.img"
|
|
|
9f65cc |
readonly squash_candidate=( "usr" "etc" )
|
|
|
9f65cc |
|
|
|
9f65cc |
mkdir -m 0755 -p $squash_dir
|
|
|
9f65cc |
@@ -1763,57 +1759,15 @@ if dracut_module_included "squash"; then
|
|
|
9f65cc |
# Move some files out side of the squash image, including:
|
|
|
9f65cc |
# - Files required to boot and mount the squashfs image
|
|
|
9f65cc |
# - Files need to be accessible without mounting the squash image
|
|
|
9f65cc |
- required_in_root() {
|
|
|
9f65cc |
- local file=$1
|
|
|
9f65cc |
- local _sqsh_file=$squash_dir/$file
|
|
|
9f65cc |
- local _init_file=$initdir/$file
|
|
|
9f65cc |
-
|
|
|
9f65cc |
- if [[ -e $_init_file ]]; then
|
|
|
9f65cc |
- return
|
|
|
9f65cc |
- fi
|
|
|
9f65cc |
-
|
|
|
9f65cc |
- if [[ ! -e $_sqsh_file ]] && [[ ! -L $_sqsh_file ]]; then
|
|
|
9f65cc |
- derror "$file is required to boot a squashed initramfs but it's not installed!"
|
|
|
9f65cc |
- return
|
|
|
9f65cc |
- fi
|
|
|
9f65cc |
-
|
|
|
9f65cc |
- if [[ ! -d $(dirname $_init_file) ]]; then
|
|
|
9f65cc |
- required_in_root $(dirname $file)
|
|
|
9f65cc |
- fi
|
|
|
9f65cc |
-
|
|
|
9f65cc |
- if [[ -L $_sqsh_file ]]; then
|
|
|
9f65cc |
- cp --preserve=all -P $_sqsh_file $_init_file
|
|
|
9f65cc |
- _sqsh_file=$(realpath $_sqsh_file 2>/dev/null)
|
|
|
9f65cc |
- if [[ -e $_sqsh_file ]] && [[ "$_sqsh_file" == "$squash_dir"* ]]; then
|
|
|
9f65cc |
- # Relative symlink
|
|
|
9f65cc |
- required_in_root ${_sqsh_file#$squash_dir/}
|
|
|
9f65cc |
- return
|
|
|
9f65cc |
- fi
|
|
|
9f65cc |
- if [[ -e $squash_dir$_sqsh_file ]]; then
|
|
|
9f65cc |
- # Absolute symlink
|
|
|
9f65cc |
- required_in_root ${_sqsh_file#/}
|
|
|
9f65cc |
- return
|
|
|
9f65cc |
- fi
|
|
|
9f65cc |
- required_in_root ${module_spec#$squash_dir/}
|
|
|
9f65cc |
- else
|
|
|
9f65cc |
- if [[ -d $_sqsh_file ]]; then
|
|
|
9f65cc |
- mkdir $_init_file
|
|
|
9f65cc |
- else
|
|
|
9f65cc |
- mv $_sqsh_file $_init_file
|
|
|
9f65cc |
- fi
|
|
|
9f65cc |
- fi
|
|
|
9f65cc |
- }
|
|
|
9f65cc |
-
|
|
|
9f65cc |
- required_in_root etc/initrd-release
|
|
|
9f65cc |
-
|
|
|
9f65cc |
- for module_spec in $squash_dir/usr/lib/modules/*/modules.*;
|
|
|
9f65cc |
- do
|
|
|
9f65cc |
- required_in_root ${module_spec#$squash_dir/}
|
|
|
9f65cc |
- done
|
|
|
9f65cc |
-
|
|
|
9f65cc |
- for dracut_spec in $squash_dir/usr/lib/dracut/*;
|
|
|
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 |
- required_in_root ${dracut_spec#$squash_dir/}
|
|
|
9f65cc |
+ [[ -d $file ]] && continue
|
|
|
9f65cc |
+ DRACUT_RESOLVE_DEPS=1 dracutsysrootdir=$squash_dir inst ${file#$squash_dir}
|
|
|
9f65cc |
+ rm $file
|
|
|
9f65cc |
done
|
|
|
9f65cc |
|
|
|
9f65cc |
mv $initdir/init $initdir/init.stock
|
|
|
9f65cc |
@@ -1824,17 +1778,14 @@ if dracut_module_included "squash"; then
|
|
|
9f65cc |
# accessible before mounting the image.
|
|
|
9f65cc |
inst_multiple "echo" "sh" "mount" "modprobe" "mkdir"
|
|
|
9f65cc |
hostonly="" instmods "loop" "squashfs" "overlay"
|
|
|
9f65cc |
-
|
|
|
9f65cc |
# Only keep systemctl outsite if we need switch root
|
|
|
9f65cc |
if [[ ! -f "$initdir/lib/dracut/no-switch-root" ]]; then
|
|
|
9f65cc |
inst "systemctl"
|
|
|
9f65cc |
fi
|
|
|
9f65cc |
|
|
|
9f65cc |
+ # Remove duplicated files
|
|
|
9f65cc |
for folder in "${squash_candidate[@]}"; do
|
|
|
9f65cc |
- # Remove duplicated files in squashfs image, save some more space
|
|
|
9f65cc |
- [[ ! -d $initdir/$folder/ ]] && continue
|
|
|
9f65cc |
- for file in $(find $initdir/$folder/ -not -type d);
|
|
|
9f65cc |
- do
|
|
|
9f65cc |
+ for file in $(find $initdir/$folder/ -not -type d); do
|
|
|
9f65cc |
if [[ -e $squash_dir${file#$initdir} ]]; then
|
|
|
9f65cc |
mv $squash_dir${file#$initdir} $file
|
|
|
9f65cc |
fi
|
|
|
9f65cc |
|