From cc057bbdcb8d93afe8e2a747640be32bd8fbc5d7 Mon Sep 17 00:00:00 2001 From: Shiva Kumar Date: Mon, 9 Mar 2026 16:12:14 +0530 Subject: [PATCH] apt(-get) operations that require network: do not suppress stdout/err, timeout-control Signed-off-by: Shiva Kumar (SW-CLOUD) --- ubuntu22.04/nvidia-driver | 26 ++++++++++++++++++------ ubuntu22.04/precompiled/nvidia-driver | 16 ++++++++++++++- ubuntu24.04/nvidia-driver | 28 +++++++++++++++++++------- ubuntu24.04/precompiled/nvidia-driver | 16 ++++++++++++++- vgpu-manager/ubuntu22.04/nvidia-driver | 26 ++++++++++++++++++------ vgpu-manager/ubuntu24.04/nvidia-driver | 26 ++++++++++++++++++------ 6 files changed, 111 insertions(+), 27 deletions(-) diff --git a/ubuntu22.04/nvidia-driver b/ubuntu22.04/nvidia-driver index 0039a674d..ce9c71037 100755 --- a/ubuntu22.04/nvidia-driver +++ b/ubuntu22.04/nvidia-driver @@ -25,10 +25,24 @@ DRIVER_ARCH=${TARGETARCH/amd64/x86_64} && DRIVER_ARCH=${DRIVER_ARCH/arm64/aarch6 echo "DRIVER_ARCH is $DRIVER_ARCH" +# Run apt-get -qq quietly, on failure print actual error to stdout and exit. +_apt_quiet() { + local err_file + err_file=$(mktemp) + trap "rm -f \"$err_file\"" RETURN + if ! apt-get -qq "$@" 2>"$err_file"; then + echo "ERROR: apt-get failed (exit $?): $*" + echo "apt-get stderr:" + cat "$err_file" + return 1 + fi + return 0 +} + _enable_fips_if_required() { if [[ -n "${UBUNTU_PRO_TOKEN}" && ${KERNEL_VERSION} =~ "fips" ]]; then echo "Ubuntu Pro token and FIPS kernel detected" - apt-get -qq install --no-install-recommends ubuntu-advantage-tools > /dev/null + _apt_quiet install --no-install-recommends ubuntu-advantage-tools echo "Attaching Ubuntu Pro token..." pro attach --no-auto-enable "${UBUNTU_PRO_TOKEN}" echo "Enabling FIPS apt repo access..." @@ -39,7 +53,7 @@ _enable_fips_if_required() { _update_package_cache() { if [ "${PACKAGE_TAG:-}" != "builtin" ]; then echo "Updating the package cache..." - if ! apt-get -qq update; then + if ! _apt_quiet update; then echo "ERROR: Failed to update package cache. "\ "Ensure that the cluster can access the proper networks." exit 1 @@ -89,11 +103,11 @@ _install_prerequisites() ( mkdir -p /lib/modules/${KERNEL_VERSION}/proc echo "Installing Linux kernel headers..." - apt-get -qq install --no-install-recommends linux-headers-${KERNEL_VERSION} > /dev/null + _apt_quiet install --no-install-recommends linux-headers-${KERNEL_VERSION} echo "Installing Linux kernel module files..." - apt-get -qq download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb . - { apt-get -qq download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; } 2> /dev/null + _apt_quiet download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb . + { _apt_quiet download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; } mv lib/modules/${KERNEL_VERSION}/modules.* /lib/modules/${KERNEL_VERSION} mv lib/modules/${KERNEL_VERSION}/kernel /lib/modules/${KERNEL_VERSION} depmod ${KERNEL_VERSION} @@ -111,7 +125,7 @@ _install_prerequisites() ( # Cleanup the prerequisites installed above. _remove_prerequisites() { if [ "${PACKAGE_TAG:-}" != "builtin" ]; then - apt-get -qq purge linux-headers-${KERNEL_VERSION} > /dev/null + _apt_quiet purge linux-headers-${KERNEL_VERSION} # TODO remove module files not matching an existing driver package. fi } diff --git a/ubuntu22.04/precompiled/nvidia-driver b/ubuntu22.04/precompiled/nvidia-driver index bb63653a3..2b90e9bb8 100755 --- a/ubuntu22.04/precompiled/nvidia-driver +++ b/ubuntu22.04/precompiled/nvidia-driver @@ -75,10 +75,24 @@ nvsdm_install() { fi } +# Run apt-get -qq quietly, on failure print actual error to stdout and exit. +_apt_quiet() { + local err_file + err_file=$(mktemp) + trap "rm -f \"$err_file\"" RETURN + if ! apt-get -qq "$@" 2>"$err_file"; then + echo "ERROR: apt-get failed (exit $?): $*" + echo "apt-get stderr:" + cat "$err_file" + return 1 + fi + return 0 +} + _update_package_cache() { if [ "${PACKAGE_TAG:-}" != "builtin" ]; then echo "Updating the package cache..." - if ! apt-get -qq update; then + if ! _apt_quiet update; then echo "ERROR: Failed to update package cache. "\ "Ensure that the cluster can access the proper networks." exit 1 diff --git a/ubuntu24.04/nvidia-driver b/ubuntu24.04/nvidia-driver index b272fcd86..17f766f1a 100755 --- a/ubuntu24.04/nvidia-driver +++ b/ubuntu24.04/nvidia-driver @@ -25,10 +25,24 @@ DRIVER_ARCH=${TARGETARCH/amd64/x86_64} && DRIVER_ARCH=${DRIVER_ARCH/arm64/aarch6 echo "DRIVER_ARCH is $DRIVER_ARCH" +# Run apt-get -qq quietly, on failure print actual error to stdout and exit. +_apt_quiet() { + local err_file + err_file=$(mktemp) + trap "rm -f \"$err_file\"" RETURN + if ! apt-get -qq "$@" 2>"$err_file"; then + echo "ERROR: apt-get failed (exit $?): $*" + echo "apt-get stderr:" + cat "$err_file" + return 1 + fi + return 0 +} + _enable_fips_if_required() { if [[ -n "${UBUNTU_PRO_TOKEN}" && ${KERNEL_VERSION} =~ "fips" ]]; then echo "Ubuntu Pro token and FIPS kernel detected" - apt-get -qq install --no-install-recommends ubuntu-advantage-tools > /dev/null + _apt_quiet install --no-install-recommends ubuntu-advantage-tools # This workaround is needed in Ubuntu 24.04 as OpenSSL attempts to leverage the FIPS provider # when the underlying kernel is FIPS enabled. @@ -39,7 +53,7 @@ _enable_fips_if_required() { echo "Enabling FIPS apt repo access..." pro enable --access-only --assume-yes fips-updates echo "Installing the OpenSSL FIPS modules" - apt-get -qq install --no-install-recommends ubuntu-fips-userspace > /dev/null + _apt_quiet install --no-install-recommends ubuntu-fips-userspace # With the OpenSSL FIPS module installed, OpenSSL can now work with the default settings, unset OPENSSL_FORCE_FIPS_MODE @@ -49,7 +63,7 @@ _enable_fips_if_required() { _update_package_cache() { if [ "${PACKAGE_TAG:-}" != "builtin" ]; then echo "Updating the package cache..." - if ! apt-get -qq update; then + if ! _apt_quiet update; then echo "ERROR: Failed to update package cache. "\ "Ensure that the cluster can access the proper networks." exit 1 @@ -99,11 +113,11 @@ _install_prerequisites() ( mkdir -p /lib/modules/${KERNEL_VERSION}/proc echo "Installing Linux kernel headers..." - apt-get -qq install --no-install-recommends linux-headers-${KERNEL_VERSION} > /dev/null + _apt_quiet install --no-install-recommends linux-headers-${KERNEL_VERSION} echo "Installing Linux kernel module files..." - apt-get -qq download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb . - { apt-get -qq download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; } 2> /dev/null + _apt_quiet download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb . + { _apt_quiet download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; } mv lib/modules/${KERNEL_VERSION}/modules.* /lib/modules/${KERNEL_VERSION} mv lib/modules/${KERNEL_VERSION}/kernel /lib/modules/${KERNEL_VERSION} depmod ${KERNEL_VERSION} @@ -121,7 +135,7 @@ _install_prerequisites() ( # Cleanup the prerequisites installed above. _remove_prerequisites() { if [ "${PACKAGE_TAG:-}" != "builtin" ]; then - apt-get -qq purge linux-headers-${KERNEL_VERSION} > /dev/null + _apt_quiet purge linux-headers-${KERNEL_VERSION} # TODO remove module files not matching an existing driver package. fi } diff --git a/ubuntu24.04/precompiled/nvidia-driver b/ubuntu24.04/precompiled/nvidia-driver index eb887b2d8..ef656ca7c 100755 --- a/ubuntu24.04/precompiled/nvidia-driver +++ b/ubuntu24.04/precompiled/nvidia-driver @@ -76,10 +76,24 @@ nvsdm_install() { fi } +# Run apt-get -qq quietly, on failure print actual error to stdout and exit. +_apt_quiet() { + local err_file + err_file=$(mktemp) + trap "rm -f \"$err_file\"" RETURN + if ! apt-get -qq "$@" 2>"$err_file"; then + echo "ERROR: apt-get failed (exit $?): $*" + echo "apt-get stderr:" + cat "$err_file" + return 1 + fi + return 0 +} + _update_package_cache() { if [ "${PACKAGE_TAG:-}" != "builtin" ]; then echo "Updating the package cache..." - if ! apt-get -qq update; then + if ! _apt_quiet update; then echo "ERROR: Failed to update package cache. "\ "Ensure that the cluster can access the proper networks." exit 1 diff --git a/vgpu-manager/ubuntu22.04/nvidia-driver b/vgpu-manager/ubuntu22.04/nvidia-driver index 5a12f0a6f..9544257b5 100755 --- a/vgpu-manager/ubuntu22.04/nvidia-driver +++ b/vgpu-manager/ubuntu22.04/nvidia-driver @@ -13,10 +13,24 @@ MODPROBE_CONFIG_DIR="/etc/modprobe.d" export DEBIAN_FRONTEND=noninteractive +# Run apt-get -qq quietly, on failure print actual error to stdout and exit. +_apt_quiet() { + local err_file + err_file=$(mktemp) + trap "rm -f \"$err_file\"" RETURN + if ! apt-get -qq "$@" 2>"$err_file"; then + echo "ERROR: apt-get failed (exit $?): $*" + echo "apt-get stderr:" + cat "$err_file" + return 1 + fi + return 0 +} + _update_package_cache() { if [ "${PACKAGE_TAG:-}" != "builtin" ]; then echo "Updating the package cache..." - apt-get -qq update + _apt_quiet update fi } @@ -56,13 +70,13 @@ _install_prerequisites() { mkdir -p /lib/modules/${KERNEL_VERSION}/proc echo "Installing Linux kernel headers..." - apt-get -qq install --no-install-recommends linux-headers-${KERNEL_VERSION} > /dev/null + _apt_quiet install --no-install-recommends linux-headers-${KERNEL_VERSION} echo "Installing Linux kernel module files..." - apt-get -qq download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb . - { apt-get -qq download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; } 2> /dev/null + _apt_quiet download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb . + { _apt_quiet download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; } # linux-modules-extra contains pci-pf-stub which is required when enabling SR-IOV on a physical GPU - { apt-get -qq download linux-modules-extra-${KERNEL_VERSION} && dpkg -x linux-modules-extra*.deb . || true; } 2> /dev/null + { _apt_quiet download linux-modules-extra-${KERNEL_VERSION} && dpkg -x linux-modules-extra*.deb . || true; } mv lib/modules/${KERNEL_VERSION}/modules.* /lib/modules/${KERNEL_VERSION} mv lib/modules/${KERNEL_VERSION}/kernel /lib/modules/${KERNEL_VERSION} depmod ${KERNEL_VERSION} @@ -80,7 +94,7 @@ _install_prerequisites() { # Cleanup the prerequisites installed above. _remove_prerequisites() { if [ "${PACKAGE_TAG:-}" != "builtin" ]; then - apt-get -qq purge linux-headers-${KERNEL_VERSION} > /dev/null + _apt_quiet purge linux-headers-${KERNEL_VERSION} # TODO remove module files not matching an existing driver package. fi } diff --git a/vgpu-manager/ubuntu24.04/nvidia-driver b/vgpu-manager/ubuntu24.04/nvidia-driver index b16bc2ef2..647bc27bc 100644 --- a/vgpu-manager/ubuntu24.04/nvidia-driver +++ b/vgpu-manager/ubuntu24.04/nvidia-driver @@ -13,10 +13,24 @@ MODPROBE_CONFIG_DIR="/etc/modprobe.d" export DEBIAN_FRONTEND=noninteractive +# Run apt-get -qq quietly, on failure print actual error to stdout and exit. +_apt_quiet() { + local err_file + err_file=$(mktemp) + trap "rm -f \"$err_file\"" RETURN + if ! apt-get -qq "$@" 2>"$err_file"; then + echo "ERROR: apt-get failed (exit $?): $*" + echo "apt-get stderr:" + cat "$err_file" + return 1 + fi + return 0 +} + _update_package_cache() { if [ "${PACKAGE_TAG:-}" != "builtin" ]; then echo "Updating the package cache..." - apt-get -qq update + _apt_quiet update fi } @@ -56,13 +70,13 @@ _install_prerequisites() { mkdir -p /lib/modules/${KERNEL_VERSION}/proc echo "Installing Linux kernel headers..." - apt-get -qq install --no-install-recommends linux-headers-${KERNEL_VERSION} > /dev/null + _apt_quiet install --no-install-recommends linux-headers-${KERNEL_VERSION} echo "Installing Linux kernel module files..." - apt-get -qq download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb . - { apt-get -qq download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; } 2> /dev/null + _apt_quiet download linux-image-${KERNEL_VERSION} && dpkg -x linux-image*.deb . + { _apt_quiet download linux-modules-${KERNEL_VERSION} && dpkg -x linux-modules*.deb . || true; } # linux-modules-extra contains pci-pf-stub which is required when enabling SR-IOV on a physical GPU - { apt-get -qq download linux-modules-extra-${KERNEL_VERSION} && dpkg -x linux-modules-extra*.deb . || true; } 2> /dev/null + { _apt_quiet download linux-modules-extra-${KERNEL_VERSION} && dpkg -x linux-modules-extra*.deb . || true; } mv lib/modules/${KERNEL_VERSION}/modules.* /lib/modules/${KERNEL_VERSION} mv lib/modules/${KERNEL_VERSION}/kernel /lib/modules/${KERNEL_VERSION} depmod ${KERNEL_VERSION} @@ -80,7 +94,7 @@ _install_prerequisites() { # Cleanup the prerequisites installed above. _remove_prerequisites() { if [ "${PACKAGE_TAG:-}" != "builtin" ]; then - apt-get -qq purge linux-headers-${KERNEL_VERSION} > /dev/null + _apt_quiet purge linux-headers-${KERNEL_VERSION} # TODO remove module files not matching an existing driver package. fi }