Last active
September 27, 2023 16:19
-
-
Save raro28/6d6556705e02084bffd996b6b647ff1e to your computer and use it in GitHub Desktop.
Create QEMU based VMs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/sh | |
SHORT=c:,s:,m:,a:,n:,o:,p:,v: | |
LONG=vcpus:,cpuset:,memory:,arch:,node:,outputdir:,project:,version: | |
OPTS=$(getopt --alternative --name mk-node --options $SHORT --longoptions $LONG -- "$@") | |
eval set -- "$OPTS" | |
vcpus=1 | |
cpuset=0 | |
memory=1024 | |
arch=x86_64 | |
node=00 | |
outputdir=/home/$USER/vms | |
project=default | |
version=38-1.6 | |
while : | |
do | |
case "$1" in | |
-c | --vcpus ) | |
vcpus="$2" | |
shift 2 | |
;; | |
-s | --cpuset ) | |
cpuset="$2" | |
shift 2 | |
;; | |
-m | --memory) | |
memory="$2" | |
shift 2 | |
;; | |
-a | --arch ) | |
arch="$2" | |
shift 2 | |
;; | |
-n | --node ) | |
node="$2" | |
shift 2 | |
;; | |
-o | --outputdir ) | |
outputdir="$2" | |
shift 2 | |
;; | |
-p | --project ) | |
project="$2" | |
shift 2 | |
;; | |
-v | --version ) | |
version="$2" | |
shift 2 | |
;; | |
--) | |
shift; | |
break | |
;; | |
*) | |
echo "Unexpected option: $1" | |
;; | |
esac | |
done | |
mkdir -p $outputdir/$arch-$project/disks/ | |
qemu-img create -f qcow2 $outputdir/$arch-$project/disks/node-$node.qcow2 100G | |
qemu-img create -f qcow2 $outputdir/$arch-$project/disks/osd-$node.qcow2 1T | |
virt-install --connect qemu:///system --name=$arch-node-$node \ | |
--vcpus $vcpus,cpuset=$cpuset \ | |
--memory $memory \ | |
--arch $arch \ | |
--disk path=$outputdir/$arch-$project/disks/node-$node.qcow2,driver.type=qcow2,driver.name=qemu,driver.io=threads \ | |
--disk path=$outputdir/$arch-$project/disks/osd-$node.qcow2,driver.type=qcow2,driver.name=qemu,driver.io=threads \ | |
--osinfo fedora37 \ | |
--network type=network,source=default,model.type=virtio,address.type=pci,address.domain=0x0000,address.bus=0x01,address.slot=0x00,address.function=0x0 \ | |
--console pty,target_type=serial \ | |
--location "/var/lib/libvirt/images/Fedora-Server-dvd-$arch-$version.iso" \ | |
--extra-args 'console=ttyS0,115200n8' \ | |
--graphics none | |
--boot uefi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment