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