From e8fa85304cc9f69fee09fa67c7b61e75cf8ba580 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 16 Feb 2024 16:08:23 +0100 Subject: [vmware.*] Try to avoid chroot in addon-required check script --- .../opt/openslx/bin/vmware-get-supported-version | 24 +++++++++++---- core/modules/vmware12/data/addon-required | 35 +++++++++++++++------- core/modules/vmware15/data/addon-required | 35 +++++++++++++++------- core/modules/vmware16/data/addon-required | 35 +++++++++++++++------- core/modules/vmware17/data/addon-required | 35 +++++++++++++++------- 5 files changed, 114 insertions(+), 50 deletions(-) (limited to 'core') diff --git a/core/modules/vmware-version-check/data/opt/openslx/bin/vmware-get-supported-version b/core/modules/vmware-version-check/data/opt/openslx/bin/vmware-get-supported-version index 7d1190c5..c8c43666 100755 --- a/core/modules/vmware-version-check/data/opt/openslx/bin/vmware-get-supported-version +++ b/core/modules/vmware-version-check/data/opt/openslx/bin/vmware-get-supported-version @@ -3,8 +3,8 @@ # * Intel: check for "VMX Unrestricted Guest" CPU flag # * AMD: check if CPU family is Bulldozer or newer # -# It can be called inside a dracut context and tries to do -# chroot magic to call/load the required tools. +# Please do not move or rename this script, it is expected exactly +# at /opt/openslx/bin/vmware-get-supported-version VIRTTYPE="$( grep -m1 '^flags\s*:' /proc/cpuinfo | grep -woF -e svm -e vmx )" @@ -14,7 +14,14 @@ if [ -z "$VIRTTYPE" ]; then exit 0 fi -modprobe msr +[ -e "/dev/cpu/0/msr" ] \ + || modprobe msr \ + || insmod "$NEWROOT/lib/modules/$( uname -r )/kernel/arch/x86/kernel/msr.ko"* + # * because it might be compressed -> msr.ko.zstd ... + +if [ -n "$NEWROOT" ] && [ -d "$NEWROOT" ]; then + export PATH="${PATH}:${NEWROOT}/usr/sbin:${NEWROOT}/usr/bin" +fi version="legacy" if [ "$VIRTTYPE" = "vmx" ]; then # intel @@ -25,12 +32,17 @@ if [ "$VIRTTYPE" = "vmx" ]; then # intel [ "$flag" = "1" ] && version="new" fi elif [ "$VIRTTYPE" = "svm" ]; then # amd - BIT="$( rdmsr --bitfield 4:4 0xc0010114 2>/dev/null || echo "fail" )" - if [ "$BIT" = "0" ]; then + BIT1="$( rdmsr --bitfield 4:4 0xc0010114 2>/dev/null || echo "fail" )" + if [ "$BIT1" = "0" ]; then family="$( awk '$1$2 == "cpufamily" {print $NF;exit}' /proc/cpuinfo )" [ "$family" -ge 21 ] && version="new" fi fi -echo "$version" +if [ "$BIT1" = "fail" ]; then + echo "fail" + exit 1 +fi +echo "$version" +exit 0 diff --git a/core/modules/vmware12/data/addon-required b/core/modules/vmware12/data/addon-required index 6261292c..b3338504 100644 --- a/core/modules/vmware12/data/addon-required +++ b/core/modules/vmware12/data/addon-required @@ -1,19 +1,32 @@ #!/bin/bash -# the vmware helper needs the kmod msr and the tool rdmsr, -# /dev, /sys and /proc to properly detect the CPU info. +version=$( "$NEWROOT/opt/openslx/bin/vmware-get-supported-version" ) -bindmount=("/dev" "/proc" "/sys") +# Calling directly failed, try to chroot to $NEWROOT and call again -for bm in "${bindmount[@]}"; do - mount --bind "$bm" "${NEWROOT}/${bm}" -done +if [ -z "$version" ] || [ "$version" = "fail" ]; then + # the vmware helper needs the kmod msr and the tool rdmsr, + # /dev, /sys and /proc to properly detect the CPU info. -export PATH="$PATH:/opt/openslx/sbin:/opt/openslx/bin" -version="$(chroot "$NEWROOT" vmware-get-supported-version)" + declare -a bindmount=( "/dev" "/proc" "/sys" ) + declare -a bound=() + echo "Direct version check failed, trying chroot..." -for bm in "${bindmount[@]}"; do - umount "${NEWROOT}/${bm}" -done + cleanup() { + for bm in "${bound[@]}"; do + umount "${NEWROOT}/${bm}" + done + } + trap cleanup EXIT + + for bm in "${bindmount[@]}"; do + mount --bind "$bm" "${NEWROOT}/${bm}" || exit 1 + bound+=( "$bm" ) + done + + export PATH="$PATH:/opt/openslx/sbin:/opt/openslx/bin" + version="$( chroot "$NEWROOT" vmware-get-supported-version )" + +fi [ -n "$version" ] && [ "$version" = "legacy" ] diff --git a/core/modules/vmware15/data/addon-required b/core/modules/vmware15/data/addon-required index a86e41bc..a84bb7ff 100644 --- a/core/modules/vmware15/data/addon-required +++ b/core/modules/vmware15/data/addon-required @@ -1,19 +1,32 @@ #!/bin/bash -# the vmware helper needs the kmod msr and the tool rdmsr, -# /dev, /sys and /proc to properly detect the CPU info. +version=$( "$NEWROOT/opt/openslx/bin/vmware-get-supported-version" ) -bindmount=("/dev" "/proc" "/sys") +# Calling directly failed, try to chroot to $NEWROOT and call again -for bm in "${bindmount[@]}"; do - mount --bind "$bm" "${NEWROOT}/${bm}" -done +if [ -z "$version" ] || [ "$version" = "fail" ]; then + # the vmware helper needs the kmod msr and the tool rdmsr, + # /dev, /sys and /proc to properly detect the CPU info. -export PATH="$PATH:/opt/openslx/sbin:/opt/openslx/bin" -version="$(chroot "$NEWROOT" vmware-get-supported-version)" + declare -a bindmount=( "/dev" "/proc" "/sys" ) + declare -a bound=() + echo "Direct version check failed, trying chroot..." -for bm in "${bindmount[@]}"; do - umount "${NEWROOT}/${bm}" -done + cleanup() { + for bm in "${bound[@]}"; do + umount "${NEWROOT}/${bm}" + done + } + trap cleanup EXIT + + for bm in "${bindmount[@]}"; do + mount --bind "$bm" "${NEWROOT}/${bm}" || exit 1 + bound+=( "$bm" ) + done + + export PATH="$PATH:/opt/openslx/sbin:/opt/openslx/bin" + version="$( chroot "$NEWROOT" vmware-get-supported-version )" + +fi [ -n "$version" ] && [ "$version" = "new" ] diff --git a/core/modules/vmware16/data/addon-required b/core/modules/vmware16/data/addon-required index a86e41bc..a84bb7ff 100644 --- a/core/modules/vmware16/data/addon-required +++ b/core/modules/vmware16/data/addon-required @@ -1,19 +1,32 @@ #!/bin/bash -# the vmware helper needs the kmod msr and the tool rdmsr, -# /dev, /sys and /proc to properly detect the CPU info. +version=$( "$NEWROOT/opt/openslx/bin/vmware-get-supported-version" ) -bindmount=("/dev" "/proc" "/sys") +# Calling directly failed, try to chroot to $NEWROOT and call again -for bm in "${bindmount[@]}"; do - mount --bind "$bm" "${NEWROOT}/${bm}" -done +if [ -z "$version" ] || [ "$version" = "fail" ]; then + # the vmware helper needs the kmod msr and the tool rdmsr, + # /dev, /sys and /proc to properly detect the CPU info. -export PATH="$PATH:/opt/openslx/sbin:/opt/openslx/bin" -version="$(chroot "$NEWROOT" vmware-get-supported-version)" + declare -a bindmount=( "/dev" "/proc" "/sys" ) + declare -a bound=() + echo "Direct version check failed, trying chroot..." -for bm in "${bindmount[@]}"; do - umount "${NEWROOT}/${bm}" -done + cleanup() { + for bm in "${bound[@]}"; do + umount "${NEWROOT}/${bm}" + done + } + trap cleanup EXIT + + for bm in "${bindmount[@]}"; do + mount --bind "$bm" "${NEWROOT}/${bm}" || exit 1 + bound+=( "$bm" ) + done + + export PATH="$PATH:/opt/openslx/sbin:/opt/openslx/bin" + version="$( chroot "$NEWROOT" vmware-get-supported-version )" + +fi [ -n "$version" ] && [ "$version" = "new" ] diff --git a/core/modules/vmware17/data/addon-required b/core/modules/vmware17/data/addon-required index a86e41bc..a84bb7ff 100644 --- a/core/modules/vmware17/data/addon-required +++ b/core/modules/vmware17/data/addon-required @@ -1,19 +1,32 @@ #!/bin/bash -# the vmware helper needs the kmod msr and the tool rdmsr, -# /dev, /sys and /proc to properly detect the CPU info. +version=$( "$NEWROOT/opt/openslx/bin/vmware-get-supported-version" ) -bindmount=("/dev" "/proc" "/sys") +# Calling directly failed, try to chroot to $NEWROOT and call again -for bm in "${bindmount[@]}"; do - mount --bind "$bm" "${NEWROOT}/${bm}" -done +if [ -z "$version" ] || [ "$version" = "fail" ]; then + # the vmware helper needs the kmod msr and the tool rdmsr, + # /dev, /sys and /proc to properly detect the CPU info. -export PATH="$PATH:/opt/openslx/sbin:/opt/openslx/bin" -version="$(chroot "$NEWROOT" vmware-get-supported-version)" + declare -a bindmount=( "/dev" "/proc" "/sys" ) + declare -a bound=() + echo "Direct version check failed, trying chroot..." -for bm in "${bindmount[@]}"; do - umount "${NEWROOT}/${bm}" -done + cleanup() { + for bm in "${bound[@]}"; do + umount "${NEWROOT}/${bm}" + done + } + trap cleanup EXIT + + for bm in "${bindmount[@]}"; do + mount --bind "$bm" "${NEWROOT}/${bm}" || exit 1 + bound+=( "$bm" ) + done + + export PATH="$PATH:/opt/openslx/sbin:/opt/openslx/bin" + version="$( chroot "$NEWROOT" vmware-get-supported-version )" + +fi [ -n "$version" ] && [ "$version" = "new" ] -- cgit v1.2.3-55-g7522