Calculate memory and number of CPUs for the VM.
This commit is contained in:
parent
138c4f7d7e
commit
1622106e3c
1 changed files with 19 additions and 13 deletions
|
@ -1,24 +1,30 @@
|
||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
#
|
#
|
||||||
# Start a netboot VM
|
# Start a netboot VM connected to macvtap device and fraction of mem/cpus
|
||||||
#
|
#
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
if [[ $# -eq 0 ]] ; then
|
mac="$(ip link | grep -A1 "vm-macvtap" | \
|
||||||
arg="--memory 4096 --vcpu 4"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# find macvtap interface MAC address:
|
|
||||||
MAC="$(ip link | grep -A1 "vm-macvtap" | \
|
|
||||||
sed -nE "s%\s+link/ether ([[:xdigit:]:]{17}) .+%\1%p")"
|
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" \
|
XDG_CONFIG_HOME="/tmp/${UID}/.config" \
|
||||||
exec virt-install \
|
exec "virt-install \
|
||||||
--name bookworm \
|
--name bookworm \
|
||||||
--osinfo debiantesting \
|
--osinfo debiantesting \
|
||||||
--nodisks --import \
|
--nodisks --import \
|
||||||
--pxe --boot loader=/usr/share/OVMF/OVMF_CODE_4M.fd,\
|
--pxe --boot loader=$loader \
|
||||||
loader.readonly=yes,loader.type=pflash,\
|
--network type=$type \
|
||||||
nvram.template=/usr/share/OVMF/OVMF_VARS_4M.fd \
|
$* ${arg:-}"
|
||||||
--network type=ethernet,mac=${MAC},\
|
|
||||||
target.dev=vm-macvtap,xpath1.set=./target/@managed=no $@ ${arg:-}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue