-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvm-core.func
More file actions
2147 lines (1882 loc) · 80.8 KB
/
Copy pathvm-core.func
File metadata and controls
2147 lines (1882 loc) · 80.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# Copyright (c) 2021-2026 community-scripts ORG
# License: MIT | https://raw.githubusercontent.com/community-scripts/core/main/LICENSE
# ==============================================================================
# INCUS/VM-CORE.FUNC - VIRTUAL MACHINE CREATION ON AN INCUS HOST
# ==============================================================================
# Counterpart to pve/vm-core.func. A VM script describes how the machine is
# built, and that is genuinely different per platform: Proxmox drives qm and
# imports a downloaded cloud image, Incus launches a VM image from a remote and
# configures it through native keys. So VM scripts are NOT shared between the
# two the way ct/ scripts are.
#
# Entry point: incus_vm_create <image> <name> <disk-size>
# ==============================================================================
[[ -n "${_INCUS_VM_CORE_LOADED:-}" ]] && return
_INCUS_VM_CORE_LOADED=1
_CORE_BASE="${COMMUNITY_SCRIPTS_CORE_URL:-https://raw.githubusercontent.com/community-scripts/core/main}"
# Repeated per file rather than shared: there is nowhere to put a shared copy
# that does not itself need downloading first. See core/build.func.
_CS_CURL_RETRY=(--retry 3 --retry-delay 1 --retry-connrefused --connect-timeout 10)
# Prefer the dispatcher's resolver so a local checkout and forks keep working.
_incus_vm_source() {
local rel="$1"
if declare -f _cs_source_func >/dev/null 2>&1; then
_cs_source_func "$rel"
return
fi
if [[ -n "${COMMUNITY_SCRIPTS_CORE_DIR:-}" && -f "${COMMUNITY_SCRIPTS_CORE_DIR}/${rel}" ]]; then
# shellcheck disable=SC1090
source "${COMMUNITY_SCRIPTS_CORE_DIR}/${rel}"
return
fi
# shellcheck disable=SC1090
source <(curl -fsSL "${_CS_CURL_RETRY[@]}" "${_CORE_BASE}/${rel}")
}
# core/core.func first: it owns prompt_confirm/prompt_input/prompt_select,
# which every prompt below needs and which incus/core.func does not provide.
_incus_vm_source "core/core.func"
# Value checks that do not depend on the platform — the Proxmox VE VM path
# loads the same file, so an MTU means the same thing on both.
_incus_vm_source "host/validate.func"
_incus_vm_source "incus/core.func"
load_incus_functions
incus_install_compat_aliases
incus_catch_errors
load_incus_vm_functions() {
[[ -n "${__INCUS_VM_FUNCTIONS_LOADED:-}" ]] && return
__INCUS_VM_FUNCTIONS_LOADED=1
color
formatting
icons
default_vars
set_std_mode
}
load_functions() { load_incus_vm_functions; }
header_info() {
# get_header derives the slug from APP and APP_TYPE itself. Same contract as
# the Proxmox path: no banner means draw nothing. The text fallback this used
# to print ("Incus VM :: Home Assistant OS") read like the banner had been
# replaced on purpose, so a header that simply failed to fetch looked like a
# deliberate design rather than the missing artwork it is.
local header_content=""
APP_TYPE="${APP_TYPE:-vm}"
if declare -f get_header >/dev/null 2>&1; then
header_content=$(get_header 2>/dev/null || true)
fi
_cs_clear
[[ -n "$header_content" ]] && echo "$header_content"
return 0
}
check_root() { incus_root_check; }
pve_check() { incus_check; }
arch_check() {
# uname, not dpkg: an Incus host is not necessarily Debian-based.
local arch
arch="$(uname -m 2>/dev/null || echo unknown)"
case "$arch" in
x86_64 | amd64 | aarch64 | arm64) ;;
*) fatal "Unsupported architecture for Incus VMs: $arch" ;;
esac
}
# An Incus host without KVM can only run containers.
kvm_check() {
if [[ ! -e /dev/kvm ]]; then
fatal "No /dev/kvm on this host - Incus cannot run virtual machines here."
fi
}
ssh_check() { :; }
exit_script() {
# No screen clear: it wiped the line explaining why we stopped. Callers that
# are validation failures can pass their own reason.
echo -e "\n${CROSS}${RD}${1:-User exited script}${CL}\n"
exit 1
}
# One call for provisioning, whichever engine is underneath. Both wizards fill
# the same CLOUDINIT_* variables; what differs is the applying -- config keys
# here, a drive and qm flags on Proxmox. pve/vm-core.func defines its own
# vm_provision with the same contract.
#
# The two engines disagreed on one name: CLOUDINIT_SSH_KEYS on Proxmox,
# CLOUDINIT_SSHKEY here. Both are accepted so a script can use either.
vm_provision() {
local target="${1:?instance}" ud nc
[[ "${USE_CLOUD_INIT:-no}" == "yes" ]] || return 0
CLOUDINIT_SSHKEY="${CLOUDINIT_SSHKEY:-${CLOUDINIT_SSH_KEYS:-}}"
CLOUDINIT_SSH_KEYS="${CLOUDINIT_SSH_KEYS:-${CLOUDINIT_SSHKEY:-}}"
ud="$(_vm_cloud_init_user_data)"
# Newer images read cloud-init.*, older ones user.*. Setting both removes the
# guesswork about which an image supports.
incus config set "$target" cloud-init.user-data "$ud" >/dev/null || return 1
incus config set "$target" user.user-data "$ud" >/dev/null 2>&1 || true
if [[ -n "${CLOUDINIT_VENDOR_DATA:-}" ]]; then
incus config set "$target" cloud-init.vendor-data "$CLOUDINIT_VENDOR_DATA" >/dev/null || true
incus config set "$target" user.vendor-data "$CLOUDINIT_VENDOR_DATA" >/dev/null 2>&1 || true
fi
if [[ "${CLOUDINIT_NETWORK_MODE:-dhcp}" == "static" && -n "${CLOUDINIT_IP:-}" && -n "${CLOUDINIT_GW:-}" ]]; then
nc="$(_vm_cloud_init_network_config)"
incus config set "$target" cloud-init.network-config "$nc" >/dev/null || true
incus config set "$target" user.network-config "$nc" >/dev/null 2>&1 || true
fi
}
# Call once the instance exists. Everything after is optional and should not
# take the instance with it when it fails.
vm_mark_created() {
VM_CREATED=1
trap 'vm_post_create_error $LINENO "$BASH_COMMAND"' ERR
}
vm_post_create_error() {
local rc=$? line="${1:-unknown}" cmd="${2:-unknown}"
msg_warn "A step after instance creation failed (line ${line}, exit ${rc}): ${cmd}"
msg_warn "Instance ${CT_NAME:-${VM_NAME:-?}} is left in place -- finish the rest by hand."
declare -f post_update_to_api >/dev/null 2>&1 && post_update_to_api "failed" "$rc"
exit "$rc"
}
sanitize_vm_hostname() {
local hostname="${1,,}"
hostname=$(echo "$hostname" | tr -cs 'a-z0-9-' '-' | sed 's/^-//;s/-$//')
echo "${hostname:0:63}"
}
# ==============================================================================
# SECTION 0: PARITY WITH pve/vm-core.func
# ==============================================================================
# Everything below carries the same name and argument order as its counterpart
# in pve/vm-core.func, so a VM script calls the same thing on either host. Where
# Incus has no equivalent at all the function still exists, says so once through
# msg_warn, and leaves the variables it owns defined -- a script that
# interpolates ${MACHINE} or ${VMID} must not die on an unset variable just
# because the concept is Proxmox-only.
load_api_functions() {
declare -f post_to_api >/dev/null 2>&1 && return 0
_incus_vm_source "api/api.func"
}
# vm/cloud-init.func builds a Proxmox cloudinit drive with qm and pvesm, so it
# cannot run here. Incus is provisioned through the cloud-init.* instance keys
# instead, which vm_provision sets. Returning non-zero is what keeps a
# Proxmox-shaped script on its "helpers unavailable" branch rather than letting
# it call setup_cloud_init and die.
_VM_CLOUD_INIT_WARNED=0
load_cloud_init_functions() {
if ((_VM_CLOUD_INIT_WARNED == 0)); then
_VM_CLOUD_INIT_WARNED=1
msg_warn "The Proxmox Cloud-Init helpers do not run on Incus - vm_provision applies cloud-init through instance config instead"
fi
return 1
}
# Incus addresses instances by name and has no numeric IDs. Scripts still put
# ${VMID} in log lines, telemetry and disk names, so hand back the lowest number
# from 100 up that is not already an instance name instead of an empty string.
get_valid_nextid() {
local taken id=100
taken=$(incus list -f csv,noheader -c n 2>/dev/null || true)
while grep -qx "$id" <<<"$taken"; do id=$((id + 1)); done
printf '%s' "$id"
}
vm_preflight() {
[[ -n "${_CS_VM_PREFLIGHT_DONE:-}" ]] && return 0
_CS_VM_PREFLIGHT_DONE=1
check_root
[[ "${var_arm64:-no}" == "yes" ]] || arch_check
pve_check
ssh_check
# Not in the Proxmox counterpart because a PVE host is a hypervisor by
# definition. An Incus host without /dev/kvm only runs containers, and finding
# that out after the wizard wastes the operator's time.
kvm_check
}
VM_DIALOG_RESULT=""
vm_dialog() {
local box="${1:?box type}" title="${2:-}"
shift 2
local rc=0 out="" cols rows
declare -f stop_spinner >/dev/null 2>&1 && stop_spinner
VM_DIALOG_RESULT=""
case "$box" in
yesno | msgbox | gauge)
whiptail --backtitle "${VM_BACKTITLE:-Community Scripts :: Incus VM}" --title "$title" "--$box" "$@" || rc=$?
;;
*)
out=$(whiptail --backtitle "${VM_BACKTITLE:-Community Scripts :: Incus VM}" --title "$title" "--$box" "$@" 3>&1 1>&2 2>&3) || rc=$?
VM_DIALOG_RESULT="$out"
;;
esac
((rc <= 1)) && return $rc
cols=$(tput cols 2>/dev/null || echo "?")
rows=$(tput lines 2>/dev/null || echo "?")
msg_error "The '${title}' dialog could not be shown (whiptail exit ${rc})"
[[ -n "$out" ]] && msg_error "whiptail: ${out}"
msg_error "Terminal is ${cols}x${rows}; the wizard needs at least 60x18."
exit 1
}
vm_check_dialog_env() {
local cols rows
local need_rows=18 need_cols=60
if ! command -v whiptail >/dev/null 2>&1; then
msg_error "whiptail is not installed, so the settings wizard cannot run"
msg_error "Install it with your package manager (Debian/Ubuntu: apt-get install -y whiptail)"
exit 1
fi
if [[ ! -t 2 ]] && [[ ! -r /dev/tty ]]; then
msg_error "No terminal is available for the settings wizard"
msg_error "Run the script directly rather than piping it into a shell:"
msg_error " bash -c \"\$(curl -fsSL <script-url>)\""
exit 1
fi
cols=$(tput cols 2>/dev/null || echo 0)
rows=$(tput lines 2>/dev/null || echo 0)
if ((cols > 0 && rows > 0)) && ((cols < need_cols || rows < need_rows)); then
msg_error "The terminal is ${cols}x${rows}; the wizard needs at least ${need_cols}x${need_rows}"
msg_error "Enlarge the window, or use a smaller console font, and run it again."
exit 1
fi
}
# Same variable names as the Proxmox side, different shape for two of them:
# Incus takes VLAN and MTU as bare values on the nic device, where Proxmox needs
# the ",tag=" / ",mtu=" fragments its -net0 string is concatenated from.
vm_apply_env_overrides() {
[[ -n "${VM_VMID:-}" ]] && VMID="$VM_VMID"
[[ -n "${VM_DISK_SIZE:-}" ]] && DISK_SIZE="$VM_DISK_SIZE"
[[ -n "${VM_DISK_CACHE:-}" ]] && DISK_CACHE="$VM_DISK_CACHE"
[[ -n "${VM_HOSTNAME:-}" ]] && HN="$VM_HOSTNAME"
[[ -n "${VM_CORES:-}" ]] && CORE_COUNT="$VM_CORES"
[[ -n "${VM_RAM:-}" ]] && RAM_SIZE="$VM_RAM"
[[ -n "${VM_BRIDGE:-}" ]] && BRG="$VM_BRIDGE"
[[ -n "${VM_MAC:-}" ]] && MAC="$VM_MAC"
[[ -n "${VM_VLAN:-}" ]] && VLAN="$VM_VLAN"
[[ -n "${VM_MTU:-}" ]] && MTU="$VM_MTU"
[[ -n "${VM_START:-}" ]] && START_VM="$VM_START"
[[ -n "${VM_STORAGE:-}" ]] && STORAGE="$VM_STORAGE"
[[ -n "${VM_MACHINE:-}" ]] && vm_apply_machine_type "$VM_MACHINE"
[[ -n "${VM_CPU:-}" ]] && vm_apply_cpu_model "$VM_CPU"
return 0
}
vm_echo_default_settings() {
local cpu_label="${CPU_MODEL:-default}"
local cache_label="${DISK_CACHE:-none}"
local machine_label
machine_label="$(vm_machine_type_label "${MACHINE_TYPE:-q35}")"
echo -e "${CONTAINERID}${BOLD}${DGN}Virtual Machine ID: ${BGN}${VMID:-n/a}${CL}"
echo -e "${CONTAINERTYPE}${BOLD}${DGN}Machine Type: ${BGN}${machine_label}${CL}"
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}${DISK_SIZE}${CL}"
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Cache: ${BGN}${cache_label}${CL}"
echo -e "${HOSTNAME}${BOLD}${DGN}Hostname: ${BGN}${HN}${CL}"
echo -e "${OS}${BOLD}${DGN}CPU Model: ${BGN}${cpu_label}${CL}"
echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}${CORE_COUNT}${CL}"
echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}${RAM_SIZE} MiB${CL}"
echo -e "${BRIDGE}${BOLD}${DGN}Network: ${BGN}${BRG}${CL}"
echo -e "${MACADDRESS}${BOLD}${DGN}MAC Address: ${BGN}${MAC:-auto}${CL}"
echo -e "${VLANTAG}${BOLD}${DGN}VLAN: ${BGN}${VLAN:-Default}${CL}"
echo -e "${DEFAULT}${BOLD}${DGN}Interface MTU Size: ${BGN}${MTU:-Default}${CL}"
echo -e "${GATEWAY}${BOLD}${DGN}Start VM when completed: ${BGN}${START_VM}${CL}"
echo -e "${SEARCH}${BOLD}${DGN}Verbose Mode: ${BGN}${VERBOSE:-no}${CL}"
echo -e "${CREATING}${BOLD}${DGN}Creating a ${APP:-${NSAPP:-VM}} VM using the above default settings${CL}"
}
# default_settings and advanced_settings are resolved when this runs, not when
# it is defined, so each script still supplies its own.
vm_start_script() {
vm_preflight
if [[ "${VM_UNATTENDED:-0}" == "1" ]]; then
METHOD="unattended"
# This branch returns before vm_choose_settings_mode, where the bridge is
# otherwise resolved, and default_settings below reads var_bridge.
vm_resolve_bridge
default_settings
vm_apply_env_overrides
echo -e "${INFO}${BOLD}${DGN}Unattended: script defaults with environment overrides${CL}"
return 0
fi
vm_check_dialog_env
if vm_choose_settings_mode "$@"; then
header_info
echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings${CL}"
default_settings
else
header_info
echo -e "${ADVANCED}${BOLD}${RD}Using Advanced Settings${CL}"
advanced_settings
fi
}
# ==============================================================================
# SECTION 1: PROMPTS
# ==============================================================================
# Containers on Incus get whiptail through ui/build-ui.func; the VM path
# does not go through it and fell back to plain read prompts. Overriding the
# three primitives here lifts every vm_prompt_* below onto whiptail at once,
# with the text versions kept for non-TTY, missing whiptail, or VM_UI=text.
VM_BACKTITLE="Community Scripts :: Incus VM"
_vm_use_whiptail() {
[[ "${VM_UI:-}" == "text" ]] && return 1
command -v whiptail >/dev/null 2>&1 || return 1
[[ -t 0 && -t 2 ]] || return 1
declare -f is_unattended >/dev/null 2>&1 && is_unattended && return 1
return 0
}
if _vm_use_whiptail; then
_vm_text_prompt_confirm() { :; }
prompt_confirm() {
local message="${1:-Confirm?}" default="${2:-n}"
local defno=()
[[ "${default,,}" != "y" ]] && defno=(--defaultno)
whiptail --backtitle "$VM_BACKTITLE" --title "${APP:-VM}" "${defno[@]}" --yesno "$message" 10 68
}
prompt_input() {
local message="${1:-Enter value:}" default="${2:-}" out rc=0
out=$(whiptail --backtitle "$VM_BACKTITLE" --title "${APP:-VM}" --inputbox "$message" 10 68 "$default" 3>&1 1>&2 2>&3) || rc=$?
# Defaulting is right, doing it silently is not. rc 1 is a real cancel and
# stays quiet; above that, say so on stderr since stdout carries the value.
((rc >= 2)) && echo "Dialog could not be shown (whiptail exit ${rc}); using default '${default}'" >&2
if ((rc != 0)); then
echo "$default"
return 0
fi
echo "${out:-$default}"
}
# Same contract as the text version: message, default index, timeout, then the
# options; echoes the chosen option string.
prompt_select() {
local message="${1:-Select option:}" default="${2:-1}"
shift 3
local options=("$@") menu=() i=1 out rc=0
((${#options[@]} == 0)) && return 1
for o in "${options[@]}"; do
menu+=("$i" "$o")
i=$((i + 1))
done
out=$(whiptail --backtitle "$VM_BACKTITLE" --title "${APP:-VM}" --default-item "$default" --menu "$message" 16 68 "${#options[@]}" "${menu[@]}" 3>&1 1>&2 2>&3) || rc=$?
# As in prompt_input: quiet on cancel, loud when it could not be shown.
((rc >= 2)) && echo "Menu could not be shown (whiptail exit ${rc}); using default '${options[$((default - 1))]}'" >&2
if ((rc != 0)); then
echo "${options[$((default - 1))]}"
return 0
fi
echo "${options[$((out - 1))]}"
}
fi
# Each VM script calls these two from its own start(), not through
# vm_start_script, so the VM_UNATTENDED branch there never runs for them and an
# unattended run sat on a whiptail prompt with nobody to answer it. Same
# short-circuit as pve/vm-core.func's vm_confirm_new_vm, for the same reason.
vm_confirm_new_vm() {
local message="${2:-Create new VM?}"
[[ "${VM_UNATTENDED:-0}" == "1" ]] && return 0
prompt_confirm "$message" "y" 60
}
# ------------------------------------------------------------------------------
# vm_resolve_bridge()
#
# - Fills var_bridge when the script did not pin one, so BRG="$var_bridge" in
# every default_settings() gets a network that exists on THIS host
# - --quiet: pick, but do not ask and do not announce (the advanced wizard is
# about to ask for the network anyway)
#
# The VM scripts used to default to incusbr0 outright. That is the network
# Incus creates at `incus admin init` with ipv4.nat on, so a VM landed behind
# the host's NAT and was unreachable from the LAN - on hosts whose containers
# were sitting on a real LAN bridge two lines further down in `incus network
# list`. Ranking is incus_network_candidates', which the container path already
# uses; this only decides what to do with the result.
# ------------------------------------------------------------------------------
_VM_BRIDGE_RESOLVED=0
vm_resolve_bridge() {
local quiet=0 n
[[ "${1:-}" == "--quiet" ]] && quiet=1
((_VM_BRIDGE_RESOLVED)) && return 0
_VM_BRIDGE_RESOLVED=1
# Both overrides stay absolute: an operator who names a network gets it, even
# if it is the NATed one.
if [[ -n "${VM_BRIDGE:-}" ]]; then
var_bridge="$VM_BRIDGE"
return 0
fi
[[ -n "${var_bridge:-}" ]] && return 0
local -a cands=()
while IFS= read -r n; do
[[ -n "$n" ]] && cands+=("$n")
done < <(incus_network_candidates 2>/dev/null || true)
case "${#cands[@]}" in
0)
# Nothing usable found. incusbr0 is still the name Incus would have
# created, so it is the least surprising thing to fail on.
var_bridge="incusbr0"
msg_warn "No bridge to attach the VM to was found - falling back to incusbr0"
;;
1)
# Nothing to choose between; the settings summary prints it either way.
var_bridge="${cands[0]}"
;;
*)
if [[ "${VM_UNATTENDED:-0}" == "1" ]] || is_unattended || [[ ! -r /dev/tty ]]; then
# msg_info would leave a spinner running over whatever prompts next.
var_bridge="${cands[0]}"
msg_custom "🌉" "${YW}" "Network: ${var_bridge} - picked over ${cands[*]:1}"
elif ((quiet)); then
var_bridge="${cands[0]}"
else
# More than one plausible answer and someone is watching: ask rather than
# decide. Getting this wrong costs a VM that nothing on the LAN can reach.
var_bridge=$(prompt_select "Which network should the VM use? (best guess first; a NATed one is reachable from this host only)" 1 60 "${cands[@]}")
[[ -n "${var_bridge:-}" ]] || var_bridge="${cands[0]}"
fi
;;
esac
return 0
}
vm_choose_settings_mode() {
# Every VM script calls this once, before either settings path reads
# var_bridge - the one place the network default can be resolved for all of
# them instead of eighteen copies of the same line.
if [[ "${VM_UNATTENDED:-0}" == "1" ]]; then
vm_resolve_bridge
return 0
fi
local rc=0
prompt_confirm "Use Default Settings? (No = Advanced)" "y" 60 || rc=$?
if ((rc == 0)); then
VM_SETTINGS_MODE="default"
vm_resolve_bridge
else
VM_SETTINGS_MODE="advanced"
vm_resolve_bridge --quiet
fi
return $rc
}
vm_confirm_advanced_settings() {
prompt_confirm "${1:-Ready to create VM?}" "y" 120
}
# Parity with pve/vm-core.func: a shared template may ask for the host
# architecture on either backend. Incus itself picks the image arch.
vm_arch() {
case "${VM_ARCH:-$(dpkg --print-architecture 2>/dev/null || uname -m)}" in
arm64 | aarch64) echo "arm64" ;;
*) echo "amd64" ;;
esac
}
vm_arch_resolve() {
if [[ "$(vm_arch)" == "arm64" ]]; then
echo "${2:-arm64}"
else
echo "${1:-amd64}"
fi
}
vm_require_arch() {
local want="${1:-amd64}" have
have="$(vm_arch)"
[[ "$have" == "$want" ]] && return 0
msg_error "${APP:-This VM} is only published for ${want}, and this host is ${have}"
exit 106
}
# ── Proxmox-only hardware knobs ───────────────────────────────────────────────
# Incus exposes no QEMU machine type and no CPU model: the instance option list
# has limits.cpu for the count and a topology, and nothing for either of these.
# They are recorded so the summary and any ${MACHINE} / ${CPU_TYPE} a script
# interpolates stay defined, and each says once that it did nothing.
_VM_MACHINE_WARNED=0
vm_apply_machine_type() {
MACHINE_TYPE="${1:-q35}"
MACHINE=""
FORMAT=""
if ((_VM_MACHINE_WARNED == 0)); then
_VM_MACHINE_WARNED=1
msg_warn "Incus has no machine-type setting - '${MACHINE_TYPE}' is recorded but not applied"
fi
}
vm_machine_type_label() {
case "${1:-q35}" in
q35) echo "Q35 (Modern)" ;;
*) echo "i440fx" ;;
esac
}
vm_prompt_machine_type() {
vm_apply_machine_type "${1:-q35}"
echo -e "${CONTAINERTYPE}${BOLD}${DGN}Machine Type: ${BGN}$(vm_machine_type_label "$MACHINE_TYPE")${CL}"
}
_VM_CPU_MODEL_WARNED=0
vm_apply_cpu_model() {
CPU_MODEL="${1:-host}"
CPU_TYPE=""
if ((_VM_CPU_MODEL_WARNED == 0)); then
_VM_CPU_MODEL_WARNED=1
msg_warn "Incus has no CPU-model setting - '${CPU_MODEL}' is recorded but not applied"
fi
}
vm_prompt_cpu_model() {
vm_apply_cpu_model "${1:-host}"
echo -e "${OS}${BOLD}${DGN}CPU Model: ${BGN}${CPU_MODEL}${CL}"
}
_VM_VMID_WARNED=0
vm_prompt_vmid() {
VMID="${1:-$(get_valid_nextid)}"
if ((_VM_VMID_WARNED == 0)); then
_VM_VMID_WARNED=1
msg_warn "Incus instances are addressed by name - ${VMID} is used for logging and telemetry only"
fi
echo -e "${CONTAINERID}${BOLD}${DGN}Virtual Machine ID: ${BGN}${VMID}${CL}"
}
# The one Proxmox firmware choice that does map: security.csm selects the
# firmware for UEFI-incompatible guests, which is what SeaBIOS is picked for.
# It cannot coexist with Secure Boot, so incus_vm_create turns that off with it.
vm_prompt_bios() {
local default_bios="${1:-ovmf}"
if prompt_confirm "Use legacy BIOS (CSM) instead of UEFI?" "$([[ "$default_bios" == "seabios" ]] && echo y || echo n)" 60; then
CSM="yes"
BIOS_UEFI="no"
BIOS_TYPE="seabios"
else
CSM="no"
BIOS_UEFI="yes"
BIOS_TYPE="ovmf"
fi
echo -e "${OS}${BOLD}${DGN}Firmware: ${BGN}$([[ "$CSM" == yes ]] && echo "CSM (legacy BIOS)" || echo "UEFI")${CL}"
}
# The Proxmox SCSI controller and the Incus disk bus are the same decision under
# different names, so this is a rename onto vm_prompt_disk_bus rather than a
# no-op. SCSIHW is kept for a script that prints it.
vm_prompt_scsihw() {
vm_prompt_disk_bus
SCSIHW="$DISK_BUS"
}
_VM_DISPLAY_WARNED=0
vm_prompt_display() {
VGA_TYPE="${1:-serial0}"
if ((_VM_DISPLAY_WARNED == 0)); then
_VM_DISPLAY_WARNED=1
msg_warn "Incus has no display-adapter setting - use 'incus console' for the text console and 'incus console --type vga' for the graphical one"
fi
}
_VM_NIC_MODEL_WARNED=0
vm_prompt_nic_model() {
NIC_MODEL="${1:-virtio}"
if ((_VM_NIC_MODEL_WARNED == 0)); then
_VM_NIC_MODEL_WARNED=1
msg_warn "Incus VMs always get a virtio-net adapter - '${NIC_MODEL}' is recorded but not applied"
fi
}
_VM_BALLOON_WARNED=0
vm_prompt_balloon() {
BALLOON=0
if ((_VM_BALLOON_WARNED == 0)); then
_VM_BALLOON_WARNED=1
msg_warn "Incus has no memory-ballooning setting for VMs - limits.memory is a fixed allocation"
fi
}
vm_prompt_verbose() {
local default_verbose="${1:-${VERBOSE:-no}}"
if prompt_confirm "Show the full output of every command?" "$([[ "$default_verbose" == "yes" ]] && echo y || echo n)" 60; then
VERBOSE="yes"
else
VERBOSE="no"
fi
set_std_mode
echo -e "${SEARCH}${BOLD}${DGN}Verbose Mode: ${BGN}${VERBOSE}${CL}"
}
vm_prompt_hostname() {
local default_hostname="${1:-vm}" in
in=$(prompt_input "Set Hostname" "$default_hostname" 60)
HN=$(sanitize_vm_hostname "${in:-$default_hostname}")
echo -e "${HOSTNAME}${BOLD}${DGN}Hostname: ${BGN}${HN}${CL}"
}
vm_prompt_cpu_cores() {
local default_cores="${1:-2}"
CORE_COUNT=$(prompt_input "Allocate CPU Cores" "$default_cores" 60)
[[ "$CORE_COUNT" =~ ^[1-9][0-9]*$ ]] || CORE_COUNT="$default_cores"
echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}${CORE_COUNT}${CL}"
}
vm_prompt_ram() {
local default_ram="${1:-2048}"
RAM_SIZE=$(prompt_input "Allocate RAM in MiB" "$default_ram" 60)
[[ "$RAM_SIZE" =~ ^[1-9][0-9]*$ ]] || RAM_SIZE="$default_ram"
echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}${RAM_SIZE}${CL}"
}
vm_prompt_disk_size() {
local default_size="${1:-10G}" size
size=$(prompt_input "Set Disk Size in GiB (e.g. 10 or 10G)" "$default_size" 60)
size="${size// /}"
[[ "$size" =~ ^[0-9]+$ ]] && size="${size}G"
[[ "$size" =~ ^[0-9]+G$ ]] || size="$default_size"
DISK_SIZE="$size"
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}${DISK_SIZE}${CL}"
}
vm_prompt_bridge() {
local default_bridge="${1:-${var_bridge:-}}" networks
networks=$(incus_get_networks 2>/dev/null | sed '/^[[:space:]]*$/d')
# head -1 of `incus network list` is whatever sorts first, which on a host
# with a physical NIC in the list is the one network a guest must not be
# given. Ask the ranking instead.
if [[ -z "$default_bridge" ]] || { [[ -n "$networks" ]] && ! grep -qx "$default_bridge" <<<"$networks"; }; then
default_bridge=$(incus_pick_default_network)
fi
BRG=$(prompt_input "Set Network" "$default_bridge" 60)
[[ -z "${BRG:-}" ]] && BRG="$default_bridge"
echo -e "${BRIDGE}${BOLD}${DGN}Network: ${BGN}${BRG}${CL}"
}
vm_prompt_mac() {
local input
while true; do
input=$(prompt_input "Set MAC Address (empty=auto)" "${1:-}" 60)
validate_mac_address "$input" && break
msg_warn "Use XX:XX:XX:XX:XX:XX (e.g. AA:BB:CC:DD:EE:FF), or empty to auto-generate."
done
MAC="$input"
echo -e "${MACADDRESS}${BOLD}${DGN}MAC Address: ${BGN}${MAC:-auto}${CL}"
}
vm_prompt_vlan() {
local input
while true; do
input=$(prompt_input "Set VLAN Tag (empty=none)" "${VLAN:-}" 60)
validate_vlan_tag "$input" && break
msg_warn "VLAN must be a number between 1 and 4094, or empty for none."
done
VLAN="$input"
echo -e "${VLANTAG}${BOLD}${DGN}VLAN: ${BGN}${VLAN:-Default}${CL}"
}
vm_prompt_mtu() {
local input
while true; do
input=$(prompt_input "Set Interface MTU (empty=default)" "${MTU:-}" 60)
validate_mtu "$input" && break
msg_warn "MTU must be a number between 576 and 65520, or empty for the default."
done
MTU="$input"
echo -e "${DEFAULT}${BOLD}${DGN}Interface MTU: ${BGN}${MTU:-Default}${CL}"
}
vm_prompt_start_vm() {
local default_start="${1:-yes}"
if prompt_confirm "Start VM when completed?" "$([[ "$default_start" == "yes" ]] && echo y || echo n)" 60; then
START_VM="yes"
else
START_VM="no"
fi
echo -e "${GATEWAY}${BOLD}${DGN}Start VM when completed: ${BGN}${START_VM}${CL}"
}
# Secure Boot is on by default for Incus VMs and stops images whose bootloader
# is not signed for it. Offer the escape hatch rather than let the VM hang.
vm_prompt_secureboot() {
if prompt_confirm "Enable Secure Boot? (No is safer for most images)" "n" 60; then
SECUREBOOT="yes"
else
SECUREBOOT="no"
fi
echo -e "${DEFAULT}${BOLD}${DGN}Secure Boot: ${BGN}${SECUREBOOT}${CL}"
}
# Whether to use Cloud-Init at all, and the account to log in with. Everything
# else has a default worth keeping and is asked by vm_prompt_cloud_init_advanced
# instead -- see the note there.
vm_prompt_cloud_init() {
local default_user="${1:-ubuntu}"
if prompt_confirm "Enable Cloud-Init?" "n" 60; then
USE_CLOUD_INIT="yes"
CLOUDINIT_USER=$(prompt_input "Cloud-Init user" "$default_user" 60)
CLOUDINIT_PASSWORD=$(prompt_input "Cloud-Init password (empty=SSH key only)" "" 60)
CLOUDINIT_SSHKEY="${CLOUDINIT_SSHKEY:-}"
CLOUDINIT_NETWORK_MODE="${CLOUDINIT_NETWORK_MODE:-dhcp}"
CLOUDINIT_DNS="${CLOUDINIT_DNS:-1.1.1.1 8.8.8.8}"
else
USE_CLOUD_INIT="no"
fi
echo -e "${CLOUD}${BOLD}${DGN}Cloud-Init: ${BGN}${USE_CLOUD_INIT}${CL}"
# Called from inside advanced_settings, the extra questions belong here, next
# to the one that opened the subject. A script that asks before the
# Default/Advanced fork calls vm_prompt_cloud_init_advanced itself afterwards.
[[ "${VM_SETTINGS_MODE:-}" == "advanced" ]] && vm_prompt_cloud_init_advanced
return 0
}
# SSH key, network mode and DNS: the Cloud-Init settings with defaults worth
# keeping. Runs once per script, on the Advanced path only.
vm_prompt_cloud_init_advanced() {
[[ "${VM_UNATTENDED:-0}" == "1" ]] && return 0
[[ "${USE_CLOUD_INIT:-no}" == "yes" ]] || return 0
[[ -n "${_CS_CI_ADVANCED_DONE:-}" ]] && return 0
_CS_CI_ADVANCED_DONE=1
CLOUDINIT_SSHKEY=$(prompt_input "SSH public key (empty=none)" "${CLOUDINIT_SSHKEY:-}" 60)
CLOUDINIT_NETWORK_MODE=$(prompt_select "Cloud-Init network mode" "1" 60 "dhcp" "static")
if [[ "$CLOUDINIT_NETWORK_MODE" == "static" ]]; then
CLOUDINIT_IP=$(prompt_input "Static IP/CIDR (e.g. 10.0.0.10/24)" "${CLOUDINIT_IP:-}" 60)
CLOUDINIT_GW=$(prompt_input "Gateway IPv4" "${CLOUDINIT_GW:-}" 60)
CLOUDINIT_DNS=$(prompt_input "DNS servers (space separated)" "${CLOUDINIT_DNS:-1.1.1.1 8.8.8.8}" 60)
fi
return 0
}
# LC_ALL=C because incus translates this output: a German host reports
# "Gesamter Speicherplatz", which no English pattern matches. Same reason
# incus_storage_pool_free_gb in incus/backend.func does it. Prints nothing and
# returns non-zero when the figure cannot be read, so the caller shows the pool
# without a number rather than a wrong one.
_vm_pool_free_gib() {
local pool="${1:?pool}" free src
# Only a bare integer is accepted. --bytes is what makes it one; an Incus that
# ignored the flag would report "9.32GiB", and stripping the non-digits out of
# that would turn 9.32 GiB into "932" -- a wrong number, which is worse than
# none.
free=$(LC_ALL=C incus storage info --bytes "$pool" 2>/dev/null |
awk -F': *' '/space free:/ {print $2; exit}' | tr -d '[:space:]')
[[ "$free" =~ ^[0-9]+$ ]] || free=""
if [[ -z "$free" ]]; then
src="$(LC_ALL=C incus storage get "$pool" source 2>/dev/null || true)"
[[ -n "$src" && -d "$src" ]] &&
free="$(df -PB1 "$src" 2>/dev/null | awk 'NR==2 {print $4}')"
fi
[[ "$free" =~ ^[0-9]+$ ]] && ((free > 0)) || return 1
echo $((free / 1024 / 1024 / 1024))
}
_vm_pool_driver() {
LC_ALL=C incus storage list -f csv,noheader -c nD 2>/dev/null |
awk -F, -v p="${1:?pool}" '$1 == p {print $2; exit}'
}
# Same contract as the Proxmox counterpart: a preselected STORAGE is accepted
# without asking, a single pool is taken silently, and STORAGE_TYPE plus the
# disk-layout variables are set on every path -- skipping that on the
# preselected path is what once left DISK_IMPORT_FORMAT unset.
vm_select_storage() {
local hostname="${1:-${HN:-vm}}"
local pools count pool free label
local -a menu=()
if [[ -n "${STORAGE:-}" ]]; then
if incus storage info "$STORAGE" &>/dev/null; then
STORAGE_TYPE="$(_vm_pool_driver "$STORAGE")"
vm_apply_storage_layout "$STORAGE_TYPE"
msg_ok "Using ${CL}${BL}${STORAGE}${CL} ${GN}for Storage Location."
return 0
fi
msg_error "Storage pool '${STORAGE}' does not exist on this host"
exit 119
fi
pools=$(incus_get_storage_pools | sed '/^[[:space:]]*$/d')
if [[ -z "$pools" ]]; then
msg_error "No Incus storage pool found. Create one with: incus storage create default dir"
exit 119
fi
count=$(wc -l <<<"$pools")
if ((count == 1)); then
STORAGE="$pools"
else
while IFS= read -r pool; do
[[ -z "$pool" ]] && continue
free="$(_vm_pool_free_gib "$pool" 2>/dev/null || echo "")"
if [[ -n "$free" ]]; then
label="$pool ($(_vm_pool_driver "$pool"), ~${free} GiB free)"
else
label="$pool ($(_vm_pool_driver "$pool"), free space unknown)"
fi
menu+=("$label")
done <<<"$pools"
label="$(prompt_select "Which storage pool would you like to use for ${hostname}?" "1" 60 "${menu[@]}")"
STORAGE="${label%% (*}"
fi
[[ -z "${STORAGE:-}" ]] && exit_script "No storage pool selected"
msg_ok "Using ${CL}${BL}${STORAGE}${CL} ${GN}for Storage Location."
STORAGE_TYPE="$(_vm_pool_driver "$STORAGE")"
vm_apply_storage_layout "$STORAGE_TYPE"
}
# The Proxmox counterpart picks a disk format from the storage type because qm
# importdisk has to be told one. Incus decides the on-pool layout itself and
# never exposes it, so the only thing left to decide is the format the image
# has to be in on the way in -- and that is always qcow2, because that is the
# magic incus image import looks for to classify an image as a virtual machine
# rather than a container root filesystem.
vm_apply_storage_layout() {
STORAGE_DRIVER="${1:-${STORAGE_TYPE:-}}"
DISK_IMPORT_FORMAT="qcow2"
DISK_EXT=""
DISK_REF=""
FORMAT=""
THIN=""
}
# Names only, exactly like the Proxmox counterpart -- nothing is allocated here.
# The names are usable as Incus custom volumes: DISK0 is the root device, which
# Incus creates with the instance, and DISK1 upwards are what a script would
# pass to `incus storage volume create <pool> <name> --type=block`.
vm_define_disk_references() {
local disk_count="${1:-2}"
local i disk_name
for ((i = 0; i < disk_count; i++)); do
disk_name="${HN:-vm}-disk-${i}"
printf -v "DISK${i}" '%s' "$disk_name"
printf -v "DISK${i}_REF" '%s' "${STORAGE:-default}:${disk_name}"
done
}
# Incus takes a size with an explicit unit; a bare "8G" is rejected because G is
# not one of its suffixes (kB/MB/GB or KiB/MiB/GiB). "8", "8G" and "8GiB" all
# mean GiB to the callers, so normalise all three.
_vm_size_to_incus() {
local size="${1:-}"
size="${size// /}"
[[ -z "$size" ]] && return 1
case "$size" in
*[iI]B | *B) printf '%s' "$size" ;;
*[gG]) printf '%sGiB' "${size%[gG]}" ;;
*[0-9]) printf '%sGiB' "$size" ;;
*) return 1 ;;
esac
}
# ── Storage / disk ────────────────────────────────────────────────────────────
# virtio-blk is the Incus default. virtio-scsi allows discard/TRIM passthrough,
# nvme is fastest on modern guests but needs a driver the guest actually has.
vm_prompt_disk_bus() {
DISK_BUS=$(prompt_select "Disk bus" "1" 60 "virtio-blk" "virtio-scsi" "nvme")
[[ -z "${DISK_BUS:-}" ]] && DISK_BUS="virtio-blk"
echo -e "${DISKBUS}${BOLD}${DGN}Disk Bus: ${BGN}${DISK_BUS}${CL}"
}
vm_prompt_disk_cache() {
DISK_CACHE=$(prompt_select "Disk cache mode" "1" 60 "none" "writeback" "unsafe")
[[ -z "${DISK_CACHE:-}" ]] && DISK_CACHE="none"
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Cache: ${BGN}${DISK_CACHE}${CL}"
}
# A second disk is attached as a raw block device: without the agent running,
# Incus cannot mount it inside the guest for you.
vm_prompt_extra_disk() {
EXTRA_DISK_SIZE=""
if prompt_confirm "Attach a second disk?" "n" 60; then
local size
size=$(prompt_input "Extra disk size in GiB (e.g. 50)" "50" 60)
size="${size// /}"
[[ "$size" =~ ^[0-9]+G?$ ]] && EXTRA_DISK_SIZE="${size%G}"
fi
echo -e "${DISKSIZE}${BOLD}${DGN}Extra Disk: ${BGN}${EXTRA_DISK_SIZE:+${EXTRA_DISK_SIZE} GiB}${EXTRA_DISK_SIZE:-none}${CL}"
}
# ── Firmware ──────────────────────────────────────────────────────────────────
# CSM swaps UEFI for legacy BIOS. Needed by images with no EFI bootloader, and
# mutually exclusive with Secure Boot.
vm_prompt_csm() {
if prompt_confirm "Use legacy BIOS instead of UEFI (CSM)?" "n" 60; then
CSM="yes"
SECUREBOOT="no"
else
CSM="no"
fi
echo -e "${OS}${BOLD}${DGN}Firmware: ${BGN}$([[ "$CSM" == "yes" ]] && echo "Legacy BIOS (CSM)" || echo "UEFI")${CL}"
}
# Windows 11 and anything doing measured boot needs a TPM 2.0 device.
vm_prompt_vtpm() {
if prompt_confirm "Add a virtual TPM (needed for Windows 11)?" "n" 60; then
VTPM="yes"
else
VTPM="no"
fi
echo -e "${VTPM_ICON:-${DEFAULT}}${BOLD}${DGN}Virtual TPM: ${BGN}${VTPM}${CL}"
}
# ── Hardware passthrough ──────────────────────────────────────────────────────
vm_prompt_gpu() {
GPU_PASSTHROUGH="no"
GPU_PCI=""
if prompt_confirm "Pass through a GPU?" "n" 60; then
GPU_PASSTHROUGH="yes"
local gpus
gpus=$(incus info --resources 2>/dev/null | awk '/PCI address:/ {print $NF}' | head -8)
if [[ -n "$gpus" ]]; then
GPU_PCI=$(prompt_input "GPU PCI address (empty = first available)" "" 60)
fi
fi
echo -e "${GPU}${BOLD}${DGN}GPU Passthrough: ${BGN}${GPU_PASSTHROUGH}${GPU_PCI:+ (${GPU_PCI})}${CL}"
}
# Incus has a first-class usb device keyed on vendor/product id. Matching on a
# device path instead breaks the moment the guest or host renumbers it, which
# is exactly what happens across a replug or a reboot.
vm_prompt_usb() {
USB_DEVICES=""
local listing
listing=$(incus info --resources 2>/dev/null |
awk '/^ *USB devices:/,/^ *[A-Z][a-z]+ devices:/' |
awk '/Vendor ID|Product ID|Vendor:|Product:/ {print}' | head -40)
if prompt_confirm "Pass through USB devices?" "n" 60; then
USB_DEVICES=$(prompt_input "vendorid:productid pairs, comma separated (e.g. 10c4:ea60)" "" 60)
fi
echo -e "${DEFAULT}${BOLD}${DGN}USB Passthrough: ${BGN}${USB_DEVICES:-none}${CL}"
}
# Raw PCI passthrough. Only meaningful for VMs, and only with the device bound
# to vfio-pci on the host -- otherwise the host is still using it.