mirror of
https://github.com/dockur/windows.git
synced 2026-08-24 15:48:59 +01:00
feat: Validate the required RAM amount per Windows version (#2070)
This commit is contained in:
@@ -934,6 +934,38 @@ getVersion() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRequiredMemory() {
|
||||||
|
|
||||||
|
local id="${1,,}"
|
||||||
|
|
||||||
|
case "$id" in
|
||||||
|
"win11"* )
|
||||||
|
echo 4294967296 ;;
|
||||||
|
"tiny11"* | "core11"* )
|
||||||
|
echo 2147483648 ;;
|
||||||
|
"win10"* | "tiny10"* )
|
||||||
|
echo 2147483648 ;;
|
||||||
|
"win2025"* | "win2022"* | "win2019"* | "win2016"* )
|
||||||
|
echo 2147483648 ;;
|
||||||
|
"win81"* | "win7x64"* )
|
||||||
|
echo 2147483648 ;;
|
||||||
|
"win7x86"* | "winvista"* | "win2012"* )
|
||||||
|
echo 1073741824 ;;
|
||||||
|
"win2008"* | "win2003"* )
|
||||||
|
echo 536870912 ;;
|
||||||
|
"winxpx64"* )
|
||||||
|
echo 268435456 ;;
|
||||||
|
"win9"* | "winnt4"* | "winxpx86"* | "win2k"* )
|
||||||
|
echo 136314880 ;;
|
||||||
|
"reactos"* )
|
||||||
|
echo 136314880 ;;
|
||||||
|
* )
|
||||||
|
echo 136314880 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
isLegacy() {
|
isLegacy() {
|
||||||
|
|
||||||
local id="$1"
|
local id="$1"
|
||||||
|
|||||||
+64
-8
@@ -112,6 +112,13 @@ configureMachine() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! checkMemory "$DETECTED" "$desc"; then
|
||||||
|
if [ -n "${REUSED_ISO:-}" ]; then
|
||||||
|
useOriginalImage "$iso" || return 79
|
||||||
|
fi
|
||||||
|
return 79
|
||||||
|
fi
|
||||||
|
|
||||||
if ! setMachine "$DETECTED" "$iso" "$dir" "$desc"; then
|
if ! setMachine "$DETECTED" "$iso" "$dir" "$desc"; then
|
||||||
skipUnattended "$dir" "$iso" "$boot" || return 80
|
skipUnattended "$dir" "$iso" "$boot" || return 80
|
||||||
handled=1
|
handled=1
|
||||||
@@ -305,7 +312,7 @@ startInstall() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if ! rm -f -- "$BOOT"; then
|
if ! rm -f -- "$BOOT"; then
|
||||||
error "Failed to remove ISO file \"$BOOT\" !"
|
error "Failed to remove obsolete ISO file \"$BOOT\" !"
|
||||||
exit 50
|
exit 50
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -324,6 +331,10 @@ startInstall() {
|
|||||||
exit 50
|
exit 50
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "$CUSTOM" ] && [ -z "$REUSED_ISO" ] && [[ "${VERSION,,}" != "http"* ]]; then
|
||||||
|
checkMemory "$VERSION" || exit 67
|
||||||
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -832,14 +843,15 @@ prepareImage() {
|
|||||||
local dir="$2"
|
local dir="$2"
|
||||||
|
|
||||||
local desc missing
|
local desc missing
|
||||||
|
|
||||||
desc=$(printVariant "$DETECTED" "$DETECTED")
|
desc=$(printVariant "$DETECTED" "$DETECTED")
|
||||||
|
|
||||||
|
# Use the standard Windows BIOS boot image unless legacy preparation
|
||||||
|
# already selected a media-specific El Torito image.
|
||||||
|
ETFS="${ETFS:-boot/etfsboot.com}"
|
||||||
|
|
||||||
# Legacy rebuilt media must retain the source ISO's El Torito boot-load size.
|
# Legacy rebuilt media must retain the source ISO's El Torito boot-load size.
|
||||||
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
|
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
|
||||||
if [[ "${DETECTED,,}" != "win9"* && "${DETECTED,,}" != "winnt4" ]]; then
|
getBootLoadSize "$iso" "$dir" "$desc" || return 1
|
||||||
getBootLoadSize "$iso" "$dir" "$desc" || return 1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
supportsXML "$DETECTED" || return 0
|
supportsXML "$DETECTED" || return 0
|
||||||
@@ -1404,6 +1416,52 @@ backupPrevious () {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkMemory() {
|
||||||
|
|
||||||
|
local id="$1"
|
||||||
|
local desc="${2:-}"
|
||||||
|
local required wanted available
|
||||||
|
|
||||||
|
required=$(getRequiredMemory "$id") || return 1
|
||||||
|
|
||||||
|
if [ -z "$desc" ]; then
|
||||||
|
desc=$(printVariant "$id" "$id") || return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure the final memory allocation also uses this floor.
|
||||||
|
RAM_MINIMUM="$required"
|
||||||
|
|
||||||
|
# Refresh host and container memory availability.
|
||||||
|
getMemoryInfo
|
||||||
|
|
||||||
|
available=$(( RAM_AVAIL - RAM_SPARE ))
|
||||||
|
(( available < 0 )) && available=0
|
||||||
|
|
||||||
|
case "${RAM_SIZE,,}" in
|
||||||
|
"max" )
|
||||||
|
wanted="$available" ;;
|
||||||
|
"half" )
|
||||||
|
wanted=$(( RAM_TOTAL / 2 ))
|
||||||
|
(( wanted > available )) && wanted="$available" ;;
|
||||||
|
* )
|
||||||
|
wanted=$(numfmt --from=iec "$RAM_SIZE") || return 1
|
||||||
|
|
||||||
|
if (( wanted < required )); then
|
||||||
|
error "$desc requires at least $(formatBytes "$required") of RAM, but RAM_SIZE is set to $(formatBytes "$wanted")."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
(( wanted > available )) && wanted="$available" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if (( wanted < required )); then
|
||||||
|
error "$desc requires at least $(formatBytes "$required") of RAM, but only $(formatBytes "$wanted") can be allocated."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
restoreBootMode() {
|
restoreBootMode() {
|
||||||
|
|
||||||
local current="${BOOT_MODE:-}"
|
local current="${BOOT_MODE:-}"
|
||||||
@@ -1463,10 +1521,8 @@ setMachine() {
|
|||||||
local iso="$2"
|
local iso="$2"
|
||||||
local dir="$3"
|
local dir="$3"
|
||||||
local desc="$4"
|
local desc="$4"
|
||||||
|
|
||||||
ETFS="boot/etfsboot.com"
|
|
||||||
|
|
||||||
local version=""
|
local version=""
|
||||||
|
|
||||||
case "${id,,}" in
|
case "${id,,}" in
|
||||||
"win2k"* ) version="2k" ;;
|
"win2k"* ) version="2k" ;;
|
||||||
"winxp"* ) version="xp" ;;
|
"winxp"* ) version="xp" ;;
|
||||||
|
|||||||
Reference in New Issue
Block a user