From 9a6b40f023db3763694fb99a820f11017cc56811 Mon Sep 17 00:00:00 2001 From: Kairui Song 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 (cherry picked from commit 4159819fbb20fca8c0a80ddb17e211f481ec7717) Resolves: #1959336 --- dracut.sh | 89 ++++++++++++++------------------------------------------------- 1 file changed, 20 insertions(+), 69 deletions(-) diff --git a/dracut.sh b/dracut.sh index b9657dc6..176b2259 100755 --- a/dracut.sh +++ b/dracut.sh @@ -1736,23 +1736,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 @@ -1763,57 +1759,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 @@ -1824,17 +1778,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