dracut/0100.patch
Harald Hoyer 460d2c99f9 dracut-050-157.git20201002
git snapshot
2020-10-02 14:08:26 +02:00

139 lines
4.7 KiB
Diff

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