Browse Source

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>
master
Kairui Song 5 years ago committed by Daniel Molkentin
parent
commit
4159819fbb
  1. 89
      dracut.sh

89
dracut.sh

@ -1833,23 +1833,19 @@ fi


if dracut_module_included "squash"; then if dracut_module_included "squash"; then
dinfo "*** Install squash loader ***" dinfo "*** Install squash loader ***"
if ! check_kernel_config CONFIG_SQUASHFS; then for config in \
dfatal "CONFIG_SQUASHFS have to be enabled for dracut squash module to work" CONFIG_SQUASHFS \
exit 1 CONFIG_OVERLAY_FS \
fi CONFIG_DEVTMPFS;
if ! check_kernel_config CONFIG_OVERLAY_FS; then do
dfatal "CONFIG_OVERLAY_FS have to be enabled for dracut squash module to work" if ! check_kernel_config $config; then
exit 1 dfatal "$config have to be enabled for dracut squash module to work"
fi
if ! check_kernel_config CONFIG_DEVTMPFS; then
dfatal "CONFIG_DEVTMPFS have to be enabled for dracut squash module to work"
exit 1 exit 1
fi fi
done


readonly squash_dir="$initdir/squash/root" readonly squash_dir="$initdir/squash/root"
readonly squash_img=$initdir/squash/root.img readonly squash_img="$initdir/squash/root.img"

# Currently only move "usr" "etc" to squashdir
readonly squash_candidate=( "usr" "etc" ) readonly squash_candidate=( "usr" "etc" )


mkdir -m 0755 -p $squash_dir 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: # Move some files out side of the squash image, including:
# - Files required to boot and mount the squashfs image # - Files required to boot and mount the squashfs image
# - Files need to be accessible without mounting the squash image # - Files need to be accessible without mounting the squash image
required_in_root() { # - Initramfs marker
local file=$1 for file in \
local _sqsh_file=$squash_dir/$file $squash_dir/usr/lib/modules/*/modules.* \
local _init_file=$initdir/$file $squash_dir/usr/lib/dracut/* \

$squash_dir/etc/initrd-release
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/*;
do 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 done


mv $initdir/init $initdir/init.stock mv $initdir/init $initdir/init.stock
@ -1921,17 +1875,14 @@ if dracut_module_included "squash"; then
# accessible before mounting the image. # accessible before mounting the image.
inst_multiple "echo" "sh" "mount" "modprobe" "mkdir" inst_multiple "echo" "sh" "mount" "modprobe" "mkdir"
hostonly="" instmods "loop" "squashfs" "overlay" hostonly="" instmods "loop" "squashfs" "overlay"

# Only keep systemctl outsite if we need switch root # Only keep systemctl outsite if we need switch root
if [[ ! -f "$initdir/lib/dracut/no-switch-root" ]]; then if [[ ! -f "$initdir/lib/dracut/no-switch-root" ]]; then
inst "systemctl" inst "systemctl"
fi fi


# Remove duplicated files
for folder in "${squash_candidate[@]}"; do for folder in "${squash_candidate[@]}"; do
# Remove duplicated files in squashfs image, save some more space for file in $(find $initdir/$folder/ -not -type d); do
[[ ! -d $initdir/$folder/ ]] && continue
for file in $(find $initdir/$folder/ -not -type d);
do
if [[ -e $squash_dir${file#$initdir} ]]; then if [[ -e $squash_dir${file#$initdir} ]]; then
mv $squash_dir${file#$initdir} $file mv $squash_dir${file#$initdir} $file
fi fi

Loading…
Cancel
Save