alpha
Login
or
Join now
lass.pds.lassul.us
/
superconfig
Star
0
Fork
1
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
This repository has no description
Star
0
Fork
1
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
1
Pipelines
tools: add vm-boot for testing ISOs
author
lassulus
date
1 year ago
(Jun 19, 2025, 6:03 PM CEST)
commit
8cf9bff7
8cf9bff7376611da5bf145493ffc3bd5040f8958
parent
684ebcb3
684ebcb3676a8f70d20da2f77a79af933b85cc4f
+176
2 changed files
Expand all
Collapse all
Unified
Split
tools
vm-boot
flake-module.nix
vm-boot.sh
+17
tools/vm-boot/flake-module.nix
View file
Reviewed
···
1
1
+
{ ... }:
2
2
+
{
3
3
+
perSystem =
4
4
+
{ pkgs, ... }:
5
5
+
{
6
6
+
packages.vm-boot = pkgs.writeShellApplication {
7
7
+
name = "vm-boot";
8
8
+
runtimeInputs = with pkgs; [
9
9
+
qemu
10
10
+
file
11
11
+
util-linux
12
12
+
nix
13
13
+
];
14
14
+
text = builtins.readFile ./vm-boot.sh;
15
15
+
};
16
16
+
};
17
17
+
}
+159
tools/vm-boot/vm-boot.sh
View file
Reviewed
···
1
1
+
#!/usr/bin/env bash
2
2
+
set -euo pipefail
3
3
+
set -x
4
4
+
5
5
+
# Default values
6
6
+
ISO_FILE=""
7
7
+
MEMORY="2048"
8
8
+
CPUS="2"
9
9
+
ARCH=""
10
10
+
11
11
+
usage() {
12
12
+
cat <<EOF
13
13
+
Usage: $0 [OPTIONS] ISO_FILE
14
14
+
15
15
+
Boot an ISO file in a VM with automatic architecture detection.
16
16
+
17
17
+
OPTIONS:
18
18
+
-m, --memory SIZE Memory in MB (default: 2048)
19
19
+
-c, --cpus COUNT Number of CPU cores (default: 2)
20
20
+
-a, --arch ARCH Force architecture (x86_64 or aarch64)
21
21
+
-h, --help Show this help message
22
22
+
23
23
+
EXAMPLE:
24
24
+
$0 installer.iso
25
25
+
$0 -m 4096 -c 4 installer.iso
26
26
+
$0 -a x86_64 installer.iso
27
27
+
EOF
28
28
+
}
29
29
+
30
30
+
# Parse arguments
31
31
+
while [[ $# -gt 0 ]]; do
32
32
+
case $1 in
33
33
+
-m|--memory)
34
34
+
MEMORY="$2"
35
35
+
shift 2
36
36
+
;;
37
37
+
-c|--cpus)
38
38
+
CPUS="$2"
39
39
+
shift 2
40
40
+
;;
41
41
+
-a|--arch)
42
42
+
ARCH="$2"
43
43
+
shift 2
44
44
+
;;
45
45
+
-h|--help)
46
46
+
usage
47
47
+
exit 0
48
48
+
;;
49
49
+
-*)
50
50
+
echo "Unknown option: $1"
51
51
+
usage
52
52
+
exit 1
53
53
+
;;
54
54
+
*)
55
55
+
if [ -z "$ISO_FILE" ]; then
56
56
+
ISO_FILE="$1"
57
57
+
else
58
58
+
echo "Multiple ISO files specified"
59
59
+
usage
60
60
+
exit 1
61
61
+
fi
62
62
+
shift
63
63
+
;;
64
64
+
esac
65
65
+
done
66
66
+
67
67
+
# Check if ISO file is provided
68
68
+
if [ -z "$ISO_FILE" ]; then
69
69
+
echo "Error: ISO file not specified"
70
70
+
usage
71
71
+
exit 1
72
72
+
fi
73
73
+
74
74
+
# Check if ISO file exists
75
75
+
if [ ! -f "$ISO_FILE" ]; then
76
76
+
echo "Error: ISO file '$ISO_FILE' not found"
77
77
+
exit 1
78
78
+
fi
79
79
+
80
80
+
# Detect architecture if not specified
81
81
+
if [ -z "$ARCH" ]; then
82
82
+
echo "Detecting ISO architecture..."
83
83
+
ISO_INFO=$(file "$ISO_FILE")
84
84
+
if echo "$ISO_INFO" | grep -q "aarch64"; then
85
85
+
ARCH="aarch64"
86
86
+
elif echo "$ISO_INFO" | grep -q "x86-64\|x86_64"; then
87
87
+
ARCH="x86_64"
88
88
+
else
89
89
+
# Try to extract more info from the ISO
90
90
+
ISO_LABEL=$(blkid -o value -s LABEL "$ISO_FILE" 2>/dev/null || echo "")
91
91
+
if echo "$ISO_LABEL" | grep -q "aarch64"; then
92
92
+
ARCH="aarch64"
93
93
+
elif echo "$ISO_LABEL" | grep -q "x86"; then
94
94
+
ARCH="x86_64"
95
95
+
else
96
96
+
echo "Could not detect architecture from ISO. Please specify with -a option."
97
97
+
echo "Supported architectures: x86_64, aarch64"
98
98
+
exit 1
99
99
+
fi
100
100
+
fi
101
101
+
fi
102
102
+
103
103
+
echo "Booting $ISO_FILE with $ARCH architecture..."
104
104
+
echo "Memory: $MEMORY MB, CPUs: $CPUS"
105
105
+
106
106
+
# Build QEMU command based on architecture
107
107
+
if [ "$ARCH" = "x86_64" ]; then
108
108
+
echo "Starting x86_64 VM with EFI..."
109
109
+
# Get the x86_64-linux UEFI firmware
110
110
+
echo "Building x86_64-linux UEFI firmware..."
111
111
+
UEFI_STORE_PATH=$(nix build --no-link --print-out-paths --system x86_64-linux nixpkgs#OVMF.fd)
112
112
+
UEFI_FW="$UEFI_STORE_PATH/FV/OVMF.fd"
113
113
+
if [ ! -f "$UEFI_FW" ]; then
114
114
+
echo "Error: Could not find x86_64 UEFI firmware at $UEFI_FW"
115
115
+
exit 1
116
116
+
fi
117
117
+
echo "Using UEFI firmware: $UEFI_FW"
118
118
+
exec qemu-system-x86_64 \
119
119
+
-machine q35 \
120
120
+
-cpu qemu64 \
121
121
+
-m "$MEMORY" \
122
122
+
-smp "$CPUS" \
123
123
+
-accel tcg \
124
124
+
-bios "$UEFI_FW" \
125
125
+
-cdrom "$ISO_FILE" \
126
126
+
-boot d \
127
127
+
-nographic \
128
128
+
-serial mon:stdio
129
129
+
elif [ "$ARCH" = "aarch64" ]; then
130
130
+
echo "Starting aarch64 VM..."
131
131
+
# Get the aarch64-linux UEFI firmware
132
132
+
echo "Building aarch64 UEFI firmware..."
133
133
+
# Use the pre-built firmware path we know works
134
134
+
UEFI_FW="/nix/store/2ciakp99mrcb3fx98j6ji0nxkxcyq5gy-OVMF-202505-fd/FV/QEMU_EFI.fd"
135
135
+
if [ ! -f "$UEFI_FW" ]; then
136
136
+
echo "Firmware not found in store, building..."
137
137
+
UEFI_STORE_PATH=$(nix build --no-link --print-out-paths nixpkgs#OVMF-fd.aarch64-linux)
138
138
+
UEFI_FW="$UEFI_STORE_PATH/FV/QEMU_EFI.fd"
139
139
+
fi
140
140
+
if [ ! -f "$UEFI_FW" ]; then
141
141
+
echo "Error: Could not find aarch64 UEFI firmware at $UEFI_FW"
142
142
+
exit 1
143
143
+
fi
144
144
+
echo "Using UEFI firmware: $UEFI_FW"
145
145
+
exec qemu-system-aarch64 \
146
146
+
-machine virt \
147
147
+
-cpu cortex-a57 \
148
148
+
-m "$MEMORY" \
149
149
+
-smp "$CPUS" \
150
150
+
-accel tcg \
151
151
+
-bios "$UEFI_FW" \
152
152
+
-cdrom "$ISO_FILE" \
153
153
+
-boot d \
154
154
+
-nographic
155
155
+
else
156
156
+
echo "Error: Unsupported architecture '$ARCH'"
157
157
+
echo "Supported architectures: x86_64, aarch64"
158
158
+
exit 1
159
159
+
fi