provision/kvm/kvm-setup
2024-10-17 15:04:16 -07:00

55 lines
1.8 KiB
Bash
Executable file

#!/bin/bash
# Some notes:
#
# Prior to running this script it is recommended to update the osinfo-db:
# git clone https://gitlab.com/libosinfo/osinfo-db.git
# apt install gettext osinfo-db-tools libosinfo-bin
# cd osinfo-db
# make && make install
# osinfo-query os
#
# Some ISO images are not in the osinfo-db and therefore require initrd= and kernel= arguments provided to --location, for example:
# --location $isoImage,initrd=install.amd/initrd.gz,kernel=install.amd/vmlinuz
#
# To find them in the ISO image use:
# isoinfo -J -i <ISO image> -l | grep -e '(initrd|vmlinuz)'
# and:
# isoinfo -J -i <ISO image> -l | less
# to find what directory they are in. `isoinfo` is provided by the `genisoimage` package.
#
# The --boot line below selects UEFI non-secure-boot and requires `ovmf` to be installed
#
# The --extra-args allows console access to the installation
#
# This script assumes you have a bridge named 'br0'. Otherwise you might want to use:
# --network network:default
machineName="rock9-base"
isoImage="/mnt/e/Downloads/ISO/Rocky-9.4-x86_64-dvd.iso"
machineMemory=2 # in GB
diskSize=20
cpuNumber=2
# run `osinfo-query os` to get the name of the OS variant
osVariant="rocky9"
#--location $isoImage,initrd=install.amd/initrd.gz,kernel=install.amd/vmlinuz \
virt-install \
--connect qemu:///system \
--virt-type kvm \
--name "$machineName" \
--hvm \
--memory $(( $machineMemory * 1024 )) \
--boot loader=/usr/share/OVMF/OVMF_CODE.fd,loader.readonly=yes,loader.type=pflash,nvram.template=/usr/share/OVMF/OVMF_VARS.fd,loader_secure=no \
--disk size="$diskSize",bus=virtio,format=qcow2 \
--location $isoImage \
--vcpus $cpuNumber \
--cpu host \
--osinfo detect=on \
--os-variant "$osVariant" \
--network bridge=br1 \
--graphics none \
--console pty,target_type=serial \
--extra-args 'console=ttyS0,115200n8 --- console=ttyS0,115200n8'