30 lines
962 B
Bash
Executable file
30 lines
962 B
Bash
Executable file
#!/usr/bin/bash
|
|
#
|
|
# Start a netboot VM connected to macvtap device and fraction of mem/cpus
|
|
#
|
|
set -eu
|
|
|
|
mac="$(ip link | grep -A1 "vm-macvtap" | \
|
|
sed -nE "s%\s+link/ether ([[:xdigit:]:]{17}) .+%\1%p")"
|
|
|
|
if [[ $# -eq 0 ]] ; then
|
|
mem=$(sed -En "s/^MemTotal:\s+([0-9]+)\s+kB/\1/p" /proc/meminfo)
|
|
cpu=$(sed -En "0,/^cpu cores/s/^cpu cores\s+:\s+([0-9]+)/\1/p" /proc/cpuinfo)
|
|
arg="--memory $((mem/2048)) --vcpu $((cpu/2))"
|
|
echo "Set options: $arg"
|
|
fi
|
|
|
|
loader='/usr/share/OVMF/OVMF_CODE_4M.fd,\
|
|
loader.readonly=yes,loader.type=pflash,\
|
|
nvram.template=/usr/share/OVMF/OVMF_VARS_4M.fd'
|
|
|
|
type="ethernet,mac=${mac},target.dev=vm-macvtap,xpath1.set=./target/@managed=no"
|
|
|
|
XDG_CONFIG_HOME="/tmp/${UID}/.config" \
|
|
exec "virt-install \
|
|
--name bookworm \
|
|
--osinfo debiantesting \
|
|
--nodisks --import \
|
|
--pxe --boot loader=$loader \
|
|
--network type=$type \
|
|
$* ${arg:-}"
|