From d85bf2a155bdda90bb68bbedc0d0e0a56066ded3 Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Sun, 25 Sep 2022 03:29:51 +0200 Subject: [PATCH] armbian-next: many fixes after v29 rebase; mostly involving umount - remove grub's --verbose, it's really too verbose - trust in TMPDIR, do not use trap at all in compile_plymouth-theme-armbian - settings traps adhoc is forbidden in armbian-next as well - be more verbose in umount_chroot(), do not try to unmount tmpfs-mounted dir itself, only xx/tmp - try to be smarter about /tmp being mounted in rootfs-to-image -- in the end the recursive saves us - run post_debootstrap_tweaks when the SDCARD is still mounted, not after - don't try to download anything from any mirrors if SKIP_ARMBIAN_REPO==yes --- extensions/grub.sh | 2 +- lib/functions/compilation/debs.sh | 1 - lib/functions/general/chroot-helpers.sh | 12 +++++++----- lib/functions/image/partitioning.sh | 4 +++- lib/functions/image/rootfs-to-image.sh | 7 ++++--- lib/functions/main/rootfs-image.sh | 4 ++-- lib/functions/rootfs/create-cache.sh | 11 ++++++++--- 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/extensions/grub.sh b/extensions/grub.sh index fc3c7e831..099483ae6 100644 --- a/extensions/grub.sh +++ b/extensions/grub.sh @@ -108,7 +108,7 @@ pre_umount_final_image__install_grub() { } fi - local install_grub_cmdline="update-grub && grub-install --verbose --target=${UEFI_GRUB_TARGET} --no-nvram --removable" # nvram is global to the host, even across chroot. take care. + local install_grub_cmdline="update-grub && grub-install --target=${UEFI_GRUB_TARGET} --no-nvram --removable" # nvram is global to the host, even across chroot. take care. display_alert "Installing GRUB EFI..." "${UEFI_GRUB_TARGET}" "" chroot_custom "$chroot_target" "$install_grub_cmdline" || { exit_with_error "${install_grub_cmdline} failed!" diff --git a/lib/functions/compilation/debs.sh b/lib/functions/compilation/debs.sh index 42a7c7e35..e8724fc4a 100644 --- a/lib/functions/compilation/debs.sh +++ b/lib/functions/compilation/debs.sh @@ -200,7 +200,6 @@ compile_plymouth-theme-armbian() { local tmp_dir work_dir tmp_dir=$(mktemp -d) chmod 700 ${tmp_dir} - trap "ret=\$?; rm -rf \"${tmp_dir}\" ; exit \$ret" 0 1 2 3 15 plymouth_theme_armbian_dir=armbian-plymouth-theme_${REVISION}_all display_alert "Building deb" "armbian-plymouth-theme" "info" diff --git a/lib/functions/general/chroot-helpers.sh b/lib/functions/general/chroot-helpers.sh index 84fc78618..1d2efbb91 100644 --- a/lib/functions/general/chroot-helpers.sh +++ b/lib/functions/general/chroot-helpers.sh @@ -21,11 +21,13 @@ mount_chroot() { umount_chroot() { local target=$1 display_alert "Unmounting" "$target" "info" - while grep -Eq "${target}.*(dev|proc|sys|tmp)" /proc/mounts; do - umount --recursive "${target}"/dev > /dev/null 2>&1 || true - umount "${target}"/proc > /dev/null 2>&1 || true - umount "${target}"/sys > /dev/null 2>&1 || true - umount "${target}"/tmp > /dev/null 2>&1 || true + while grep -Eq "${target}\/(dev|proc|sys|tmp)" /proc/mounts; do + display_alert "Still things mounted at" "target: ${target}" + run_host_command_logged grep -E "'${target}/(dev|proc|sys|tmp)'" /proc/mounts + umount --recursive "${target}"/dev || true + umount "${target}"/proc || true + umount "${target}"/sys || true + umount "${target}"/tmp || true sync done } diff --git a/lib/functions/image/partitioning.sh b/lib/functions/image/partitioning.sh index d4ded1918..408ab9350 100644 --- a/lib/functions/image/partitioning.sh +++ b/lib/functions/image/partitioning.sh @@ -97,7 +97,9 @@ function prepare_partitions() { fi # Check if we need root partition [[ $ROOTFS_TYPE != nfs ]] && - local rootpart=$((next++)) + rootpart=$((next++)) + + display_alert "calculated rootpart" "rootpart: ${rootpart}" "debug" # stage: calculate rootfs size export rootfs_size=$(du -sm $SDCARD/ | cut -f1) # MiB diff --git a/lib/functions/image/rootfs-to-image.sh b/lib/functions/image/rootfs-to-image.sh index a40027c71..46379f7cb 100644 --- a/lib/functions/image/rootfs-to-image.sh +++ b/lib/functions/image/rootfs-to-image.sh @@ -80,9 +80,10 @@ create_image_from_sdcard_rootfs() { # unmount /boot/efi first, then /boot, rootfs third, image file last sync - [[ $UEFISIZE != 0 ]] && umount "${MOUNT}${UEFI_MOUNT_POINT}" - [[ $BOOTSIZE != 0 ]] && umount "${MOUNT}/boot" - umount "${MOUNT}" + [[ $UEFISIZE != 0 ]] && run_host_command_logged umount "${MOUNT}${UEFI_MOUNT_POINT}" + [[ $BOOTSIZE != 0 ]] && run_host_command_logged umount "${MOUNT}/boot" + run_host_command_logged umount "${MOUNT}"/tmp || true + run_host_command_logged umount "${MOUNT}" || true [[ $CRYPTROOT_ENABLE == yes ]] && cryptsetup luksClose $ROOT_MAPPER umount_chroot_recursive "${MOUNT}" # @TODO: wait. NFS is not really unmounted above. diff --git a/lib/functions/main/rootfs-image.sh b/lib/functions/main/rootfs-image.sh index c5883f1ed..bcec2c2ab 100644 --- a/lib/functions/main/rootfs-image.sh +++ b/lib/functions/main/rootfs-image.sh @@ -69,11 +69,11 @@ function build_rootfs_and_image() { # for reference, debugging / sanity checking LOG_SECTION="list_installed_packages" do_with_logging list_installed_packages + LOG_SECTION="post_debootstrap_tweaks" do_with_logging post_debootstrap_tweaks + # clean up / prepare for making the image umount_chroot "$SDCARD" - LOG_SECTION="post_debootstrap_tweaks" do_with_logging post_debootstrap_tweaks - # ------------------------------------ UP HERE IT's 'rootfs' stuff ------------------------------- #------------------------------------ DOWN HERE IT's 'image' stuff ------------------------------- diff --git a/lib/functions/rootfs/create-cache.sh b/lib/functions/rootfs/create-cache.sh index f25827800..1fbbe6ad9 100644 --- a/lib/functions/rootfs/create-cache.sh +++ b/lib/functions/rootfs/create-cache.sh @@ -40,9 +40,11 @@ get_or_create_rootfs_cache_chroot_sdcard() { # if aria2 file exists download didn't succeeded if [[ ! -f $cache_fname || -f ${cache_fname}.aria2 ]]; then - display_alert "Downloading from servers" - download_and_verify "rootfs" "$cache_name" || - continue + if [[ "${SKIP_ARMBIAN_REPO}" != "yes" ]]; then + display_alert "Downloading from servers" + download_and_verify "rootfs" "$cache_name" || + continue + fi fi [[ -f $cache_fname && ! -f ${cache_fname}.aria2 ]] && break @@ -265,6 +267,7 @@ function create_new_rootfs_cache() { # based on rootfs size calculation umount_chroot "$SDCARD" + display_alert "zstd ball of rootfs" "$RELEASE:: $cache_name" "debug" tar cp --xattrs --directory=$SDCARD/ --exclude='./dev/*' --exclude='./proc/*' --exclude='./run/*' --exclude='./tmp/*' \ --exclude='./sys/*' --exclude='./home/*' --exclude='./root/*' . | pv -p -b -r -s "$(du -sb $SDCARD/ | cut -f1)" -N "$(logging_echo_prefix_for_pv "store_rootfs") $cache_name" | zstdmt -5 -c > "${cache_fname}" @@ -277,6 +280,8 @@ function create_new_rootfs_cache() { # needed for backend to keep current only echo "$cache_fname" > $cache_fname.current + display_alert "Cache prepared" "$RELEASE:: $cache_fname" "debug" + return 0 # protect against possible future short-circuiting above this }