1
0
Fork 0
mirror of https://github.com/foxlet/macOS-Simple-KVM.git synced 2024-11-23 11:39:42 +01:00

[TOOLS] More options for defining VM templates

The make script now contains more command-line options when generating
the VM template, including defining a different name, fresh UUID, and
CPU/memory count.
This commit is contained in:
George Cave 2020-11-14 11:22:20 -05:00
parent 527588d5a2
commit 9047a51ca1
2 changed files with 50 additions and 15 deletions

49
make.sh
View file

@ -5,6 +5,10 @@
VMDIR=$PWD VMDIR=$PWD
MACHINE="$(qemu-system-x86_64 --machine help | grep q35 | cut -d" " -f1 | grep -Eoe ".*-[0-9.]+" | sort -rV | head -1)" MACHINE="$(qemu-system-x86_64 --machine help | grep q35 | cut -d" " -f1 | grep -Eoe ".*-[0-9.]+" | sort -rV | head -1)"
VMNAME="macOS-Simple-KVM"
VMUUID="d06d502a-904a-4b34-847d-debf1a3d76c7"
VMCPUS=4
VMMEM=2097152
OUT="template.xml" OUT="template.xml"
print_usage() { print_usage() {
@ -12,6 +16,10 @@ print_usage() {
echo "Usage: $0" echo "Usage: $0"
echo echo
echo " -a, --add Add XML to virsh (uses sudo)." echo " -a, --add Add XML to virsh (uses sudo)."
echo " -n, --name <str> Name of the VM (default 'macOS-Simple-KVM')"
echo " -u, --uuid Generates a new UUID for the VM"
echo " -c, --cpu <int> VM CPU count (default 4)"
echo " -m, --mem <int> VM memory in KiB (default 2097152)"
echo echo
} }
@ -21,18 +29,45 @@ error() {
} }
generate(){ generate(){
sed -e "s|VMDIR|$VMDIR|g" -e "s|MACHINE|$MACHINE|g" tools/template.xml.in > $OUT sed -e "s|macOS-Simple-KVM|$VMNAME|g" -e "s|d06d502a-904a-4b34-847d-debf1a3d76c7|$VMUUID|g" -e "s|VMCPUS|$VMCPUS|g" -e "s|VMMEM|$VMMEM|g" -e "s|VMDIR|$VMDIR|g" -e "s|MACHINE|$MACHINE|g" tools/template.xml.in > $OUT
echo "$OUT has been generated in $VMDIR" echo "$OUT has been generated in $VMDIR"
} }
generate while [[ $# -gt 0 ]]; do
argument="$1"
argument="$1" case $argument in
case $argument in
-a|--add) -a|--add)
sudo virsh define $OUT ADD=1
shift
;;
-n|--name)
VMNAME="$2"
shift
shift
;;
-u|--uuid)
VMUUID="$(uuidgen)"
shift
;;
-c|--cpu)
VMCPUS=$2
shift
shift
;;
-m|--mem)
VMMEM=$2
shift
shift
;; ;;
-h|--help) -h|--help)
print_usage print_usage
shift
;; ;;
esac esac
done
generate
if [[ $ADD -eq 1 ]]; then
sudo virsh define $OUT
fi

View file

@ -1,9 +1,9 @@
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'> <domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>macOS-Simple-KVM</name> <name>macOS-Simple-KVM</name>
<uuid>d06d502a-904a-4b34-847d-debf1a3d76c7</uuid> <uuid>d06d502a-904a-4b34-847d-debf1a3d76c7</uuid>
<memory unit='KiB'>2097152</memory> <memory unit='KiB'>VMMEM</memory>
<currentMemory unit='KiB'>2097152</currentMemory> <currentMemory unit='KiB'>VMMEM</currentMemory>
<vcpu placement='static'>4</vcpu> <vcpu placement='static'>VMCPUS</vcpu>
<os> <os>
<type arch='x86_64' machine='MACHINE'>hvm</type> <type arch='x86_64' machine='MACHINE'>hvm</type>
<loader readonly='yes' type='pflash'>VMDIR/firmware/OVMF_CODE.fd</loader> <loader readonly='yes' type='pflash'>VMDIR/firmware/OVMF_CODE.fd</loader>
@ -16,7 +16,7 @@
<vmport state='off'/> <vmport state='off'/>
</features> </features>
<cpu> <cpu>
<topology sockets='1' cores='4' threads='1'/> <topology sockets='1' cores='VMCPUS' threads='1'/>
</cpu> </cpu>
<clock offset='utc'> <clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/> <timer name='rtc' tickpolicy='catchup'/>