fix(vm): fix UUID consistency, cp error handling, and machine flag in QEMU profile builder
- commit
- 05c7b58da92cd24bb5dade65ca9965eb7d5e4821
- author
- brice · · 2026-02-27 04:44 UTC
- parent
- 74d97ff
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +13 -7
M test/vm/lib/qemu-profile.sh +13 -7
| @@ -3,7 +3,8 @@ | |||
| 3 | 3 | # Source this file then call: build_qemu_args PROFILE SECURE_BOOT SSH_PORT TEST_DIR | |
| 4 | 4 | # Result is stored in the QEMU_ARGS array. | |
| 5 | 5 | ||
| 6 | - | OVMF_CODE_NORMAL="/usr/share/edk2/x64/OVMF_CODE.4m.fd" | |
| 6 | + | [[ "${BASH_SOURCE[0]}" == "${0}" ]] && { echo "Source this file, do not execute it directly." >&2; exit 1; } | |
| 7 | + | ||
| 7 | 8 | OVMF_CODE_SECBOOT="/usr/share/edk2/x64/OVMF_CODE.secboot.4m.fd" | |
| 8 | 9 | OVMF_VARS_TEMPLATE="/usr/share/edk2/x64/OVMF_VARS.4m.fd" | |
| 9 | 10 | ||
| @@ -13,22 +14,27 @@ build_qemu_args() { | |||
| 13 | 14 | local ssh_port="$3" | |
| 14 | 15 | local test_dir="$4" | |
| 15 | 16 | ||
| 17 | + | local machine_opts="q35,vmport=off" | |
| 18 | + | [[ "$secure_boot" == "on" ]] && machine_opts="q35,vmport=off,smm=on" | |
| 19 | + | ||
| 20 | + | local sys_uuid | |
| 21 | + | sys_uuid="$(uuidgen 2>/dev/null || cat /proc/sys/kernel/random/uuid)" | |
| 22 | + | ||
| 16 | 23 | QEMU_ARGS=() | |
| 17 | 24 | ||
| 18 | 25 | # ── Machine & CPU ──────────────────────────────────────────────────────────── | |
| 19 | 26 | QEMU_ARGS+=(-enable-kvm) | |
| 20 | - | QEMU_ARGS+=(-machine q35,vmport=off) | |
| 27 | + | QEMU_ARGS+=(-machine "$machine_opts") | |
| 21 | 28 | QEMU_ARGS+=(-cpu host) | |
| 22 | 29 | QEMU_ARGS+=(-smp 4,cores=2,threads=2,sockets=1) | |
| 23 | 30 | QEMU_ARGS+=(-m 4096) | |
| 24 | - | QEMU_ARGS+=(-uuid "$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen)") | |
| 31 | + | QEMU_ARGS+=(-uuid "$sys_uuid") | |
| 25 | 32 | ||
| 26 | 33 | # ── Firmware ───────────────────────────────────────────────────────────────── | |
| 27 | 34 | if [[ "$secure_boot" == "on" ]]; then | |
| 28 | 35 | local vars_copy | |
| 29 | 36 | vars_copy="$(mktemp /tmp/OVMF_VARS_XXXXXXXX.fd)" | |
| 30 | - | cp "$OVMF_VARS_TEMPLATE" "$vars_copy" | |
| 31 | - | QEMU_ARGS+=(-machine q35,vmport=off,smm=on) # override previous -machine | |
| 37 | + | cp "$OVMF_VARS_TEMPLATE" "$vars_copy" || { rm -f "$vars_copy"; return 1; } | |
| 32 | 38 | QEMU_ARGS+=(-global driver=cfi.pflash01,property=secure,value=on) | |
| 33 | 39 | QEMU_ARGS+=(-drive "if=pflash,readonly=on,format=raw,file=${OVMF_CODE_SECBOOT}") | |
| 34 | 40 | QEMU_ARGS+=(-drive "if=pflash,format=raw,file=${vars_copy}") | |
| @@ -45,7 +51,7 @@ build_qemu_args() { | |||
| 45 | 51 | case "$profile" in | |
| 46 | 52 | desktop) | |
| 47 | 53 | # Type 1: System | |
| 48 | - | QEMU_ARGS+=(-smbios "type=1,manufacturer=Gigabyte Technology Co. Ltd.,product=B550 AORUS ELITE V2,version=1.0,serial=SN-DESKTOP-001,uuid=$(uuidgen 2>/dev/null || cat /proc/sys/kernel/random/uuid),sku=Default string,family=Desktop") | |
| 54 | + | QEMU_ARGS+=(-smbios "type=1,manufacturer=Gigabyte Technology Co. Ltd.,product=B550 AORUS ELITE V2,version=1.0,serial=SN-DESKTOP-001,uuid=${sys_uuid},sku=Default string,family=Desktop") | |
| 49 | 55 | # Type 2: Board | |
| 50 | 56 | QEMU_ARGS+=(-smbios "type=2,manufacturer=Gigabyte Technology Co. Ltd.,product=B550 AORUS ELITE V2,version=x.x,serial=SN-BOARD-DESKTOP,asset=Base Board Asset Tag,location=Default string") | |
| 51 | 57 | # Type 3: Chassis — desktop (type 3) | |
| @@ -53,7 +59,7 @@ build_qemu_args() { | |||
| 53 | 59 | ;; | |
| 54 | 60 | laptop) | |
| 55 | 61 | # Type 1: System — ThinkPad X1 Carbon Gen 10 | |
| 56 | - | QEMU_ARGS+=(-smbios "type=1,manufacturer=LENOVO,product=21CB,version=ThinkPad X1 Carbon Gen 10,serial=SN-LAPTOP-001,uuid=$(uuidgen 2>/dev/null || cat /proc/sys/kernel/random/uuid),sku=LENOVO_MT_21CB,family=ThinkPad X1 Carbon Gen 10") | |
| 62 | + | QEMU_ARGS+=(-smbios "type=1,manufacturer=LENOVO,product=21CB,version=ThinkPad X1 Carbon Gen 10,serial=SN-LAPTOP-001,uuid=${sys_uuid},sku=LENOVO_MT_21CB,family=ThinkPad X1 Carbon Gen 10") | |
| 57 | 63 | # Type 2: Board | |
| 58 | 64 | QEMU_ARGS+=(-smbios "type=2,manufacturer=LENOVO,product=21CB,version=SDK0J40697 WIN,serial=SN-BOARD-LAPTOP,asset=Not Available,location=Not Available") | |
| 59 | 65 | # Type 3: Chassis — notebook (type 10) | |
| @@ -3,7 +3,8 @@ | |||||
| 3 | # Source this file then call: build_qemu_args PROFILE SECURE_BOOT SSH_PORT TEST_DIR | 3 | # Source this file then call: build_qemu_args PROFILE SECURE_BOOT SSH_PORT TEST_DIR | ||
| 4 | # Result is stored in the QEMU_ARGS array. | 4 | # Result is stored in the QEMU_ARGS array. | ||
| 5 | 5 | ||||
| 6 | - | OVMF_CODE_NORMAL="/usr/share/edk2/x64/OVMF_CODE.4m.fd" | 6 | + | [[ "${BASH_SOURCE[0]}" == "${0}" ]] && { echo "Source this file, do not execute it directly." >&2; exit 1; } |
| 7 | + | ||||
| 7 | OVMF_CODE_SECBOOT="/usr/share/edk2/x64/OVMF_CODE.secboot.4m.fd" | 8 | OVMF_CODE_SECBOOT="/usr/share/edk2/x64/OVMF_CODE.secboot.4m.fd" | ||
| 8 | OVMF_VARS_TEMPLATE="/usr/share/edk2/x64/OVMF_VARS.4m.fd" | 9 | OVMF_VARS_TEMPLATE="/usr/share/edk2/x64/OVMF_VARS.4m.fd" | ||
| 9 | 10 | ||||
| @@ -13,22 +14,27 @@ build_qemu_args() { | |||||
| 13 | local ssh_port="$3" | 14 | local ssh_port="$3" | ||
| 14 | local test_dir="$4" | 15 | local test_dir="$4" | ||
| 15 | 16 | ||||
| 17 | + | local machine_opts="q35,vmport=off" | |||
| 18 | + | [[ "$secure_boot" == "on" ]] && machine_opts="q35,vmport=off,smm=on" | |||
| 19 | + | ||||
| 20 | + | local sys_uuid | |||
| 21 | + | sys_uuid="$(uuidgen 2>/dev/null || cat /proc/sys/kernel/random/uuid)" | |||
| 22 | + | ||||
| 16 | QEMU_ARGS=() | 23 | QEMU_ARGS=() | ||
| 17 | 24 | ||||
| 18 | # ── Machine & CPU ──────────────────────────────────────────────────────────── | 25 | # ── Machine & CPU ──────────────────────────────────────────────────────────── | ||
| 19 | QEMU_ARGS+=(-enable-kvm) | 26 | QEMU_ARGS+=(-enable-kvm) | ||
| 20 | - | QEMU_ARGS+=(-machine q35,vmport=off) | 27 | + | QEMU_ARGS+=(-machine "$machine_opts") |
| 21 | QEMU_ARGS+=(-cpu host) | 28 | QEMU_ARGS+=(-cpu host) | ||
| 22 | QEMU_ARGS+=(-smp 4,cores=2,threads=2,sockets=1) | 29 | QEMU_ARGS+=(-smp 4,cores=2,threads=2,sockets=1) | ||
| 23 | QEMU_ARGS+=(-m 4096) | 30 | QEMU_ARGS+=(-m 4096) | ||
| 24 | - | QEMU_ARGS+=(-uuid "$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen)") | 31 | + | QEMU_ARGS+=(-uuid "$sys_uuid") |
| 25 | 32 | ||||
| 26 | # ── Firmware ───────────────────────────────────────────────────────────────── | 33 | # ── Firmware ───────────────────────────────────────────────────────────────── | ||
| 27 | if [[ "$secure_boot" == "on" ]]; then | 34 | if [[ "$secure_boot" == "on" ]]; then | ||
| 28 | local vars_copy | 35 | local vars_copy | ||
| 29 | vars_copy="$(mktemp /tmp/OVMF_VARS_XXXXXXXX.fd)" | 36 | vars_copy="$(mktemp /tmp/OVMF_VARS_XXXXXXXX.fd)" | ||
| 30 | - | cp "$OVMF_VARS_TEMPLATE" "$vars_copy" | 37 | + | cp "$OVMF_VARS_TEMPLATE" "$vars_copy" || { rm -f "$vars_copy"; return 1; } |
| 31 | - | QEMU_ARGS+=(-machine q35,vmport=off,smm=on) # override previous -machine | |||
| 32 | QEMU_ARGS+=(-global driver=cfi.pflash01,property=secure,value=on) | 38 | QEMU_ARGS+=(-global driver=cfi.pflash01,property=secure,value=on) | ||
| 33 | QEMU_ARGS+=(-drive "if=pflash,readonly=on,format=raw,file=${OVMF_CODE_SECBOOT}") | 39 | QEMU_ARGS+=(-drive "if=pflash,readonly=on,format=raw,file=${OVMF_CODE_SECBOOT}") | ||
| 34 | QEMU_ARGS+=(-drive "if=pflash,format=raw,file=${vars_copy}") | 40 | QEMU_ARGS+=(-drive "if=pflash,format=raw,file=${vars_copy}") | ||
| @@ -45,7 +51,7 @@ build_qemu_args() { | |||||
| 45 | case "$profile" in | 51 | case "$profile" in | ||
| 46 | desktop) | 52 | desktop) | ||
| 47 | # Type 1: System | 53 | # Type 1: System | ||
| 48 | - | QEMU_ARGS+=(-smbios "type=1,manufacturer=Gigabyte Technology Co. Ltd.,product=B550 AORUS ELITE V2,version=1.0,serial=SN-DESKTOP-001,uuid=$(uuidgen 2>/dev/null || cat /proc/sys/kernel/random/uuid),sku=Default string,family=Desktop") | 54 | + | QEMU_ARGS+=(-smbios "type=1,manufacturer=Gigabyte Technology Co. Ltd.,product=B550 AORUS ELITE V2,version=1.0,serial=SN-DESKTOP-001,uuid=${sys_uuid},sku=Default string,family=Desktop") |
| 49 | # Type 2: Board | 55 | # Type 2: Board | ||
| 50 | QEMU_ARGS+=(-smbios "type=2,manufacturer=Gigabyte Technology Co. Ltd.,product=B550 AORUS ELITE V2,version=x.x,serial=SN-BOARD-DESKTOP,asset=Base Board Asset Tag,location=Default string") | 56 | QEMU_ARGS+=(-smbios "type=2,manufacturer=Gigabyte Technology Co. Ltd.,product=B550 AORUS ELITE V2,version=x.x,serial=SN-BOARD-DESKTOP,asset=Base Board Asset Tag,location=Default string") | ||
| 51 | # Type 3: Chassis — desktop (type 3) | 57 | # Type 3: Chassis — desktop (type 3) | ||
| @@ -53,7 +59,7 @@ build_qemu_args() { | |||||
| 53 | ;; | 59 | ;; | ||
| 54 | laptop) | 60 | laptop) | ||
| 55 | # Type 1: System — ThinkPad X1 Carbon Gen 10 | 61 | # Type 1: System — ThinkPad X1 Carbon Gen 10 | ||
| 56 | - | QEMU_ARGS+=(-smbios "type=1,manufacturer=LENOVO,product=21CB,version=ThinkPad X1 Carbon Gen 10,serial=SN-LAPTOP-001,uuid=$(uuidgen 2>/dev/null || cat /proc/sys/kernel/random/uuid),sku=LENOVO_MT_21CB,family=ThinkPad X1 Carbon Gen 10") | 62 | + | QEMU_ARGS+=(-smbios "type=1,manufacturer=LENOVO,product=21CB,version=ThinkPad X1 Carbon Gen 10,serial=SN-LAPTOP-001,uuid=${sys_uuid},sku=LENOVO_MT_21CB,family=ThinkPad X1 Carbon Gen 10") |
| 57 | # Type 2: Board | 63 | # Type 2: Board | ||
| 58 | QEMU_ARGS+=(-smbios "type=2,manufacturer=LENOVO,product=21CB,version=SDK0J40697 WIN,serial=SN-BOARD-LAPTOP,asset=Not Available,location=Not Available") | 64 | QEMU_ARGS+=(-smbios "type=2,manufacturer=LENOVO,product=21CB,version=SDK0J40697 WIN,serial=SN-BOARD-LAPTOP,asset=Not Available,location=Not Available") | ||
| 59 | # Type 3: Chassis — notebook (type 10) | 65 | # Type 3: Chassis — notebook (type 10) | ||