TODO
Use the "system" session by defaul:
export LIBVIRT_DEFAULT_URI="qemu:///system"
Create parameters for the setup:
export NAME=my-vm
export OSVERSION=fedora-35
export OSVARIANT=fedora35
export ARCHITECTURE=x86_64
export DISK_SIZE=30G
export CPUS=8
export RAM=8192
export POOL=vms
export POOL_DIR=~/$POOL
export DOMAIN="$NAME"-"$OSVERSION"-"$ARCHITECTURE"
export IMAGE_FILE_A="$NAME"-"$OSVERSION"-"$ARCHITECTURE"-sda.qcow2
export IMAGE_FILE_B="$NAME"-"$OSVERSION"-"$ARCHITECTURE"-sdb.qcow2
build the "vms" pool if does not exists:
mkdir -p $POOL_DIR
build an image file and store it locally:
virt-builder "$OSVERSION" -o "$POOL_DIR"/"$IMAGE_FILE_A" \
--no-network --format qcow2 --arch "$ARCHITECTURE" --size "$DISK_SIZE" --root-password=password:fedora \
--hostname "$NAME"
add another disk (needed for the storage software):
qemu-img create -f raw "$POOL_DIR"/"$IMAGE_FILE_B" 30G
add myself to the libvirt group:
sudo usermod --append --groups libvirt `whoami`
since the files are stored in the home directory, we want to give the "qemu" user access:
sudo setfacl -m u:qemu:rx $HOME
install the VM:
virt-install -n "$DOMAIN" --vcpus "$CPUS" --cpu host-passthrough,cache.mode=passthrough \
--arch "$ARCHITECTURE" --memory "$RAM" --import --os-variant "$OSVARIANT" --controller scsi,model=virtio-scsi \
--disk path="$POOL_DIR"/"$IMAGE_FILE_A",device=disk,bus=scsi,discard=unmap \
--disk path="$POOL_DIR"/"$IMAGE_FILE_B",device=disk,bus=scsi,discard=unmap \
--network network=default,model=virtio \
--graphics spice --channel unix,name=org.qemu.guest_agent.0 --noautoconsole --noreboot
start the VM:
virsh start my-vm-fedora-35-x86_64
open console to the VM, to allow for root ssh using password (password is "fedora"):
virsh console "$DOMAIN"
edit /etc/ssh/sshd_config and set:
PermitRootLogin yes
then restart ssh service:
systemctl restart sshd
get its IP address:
MAC=$(virsh dumpxml ${NAME}-${OSVERSION}-${ARCHITECTURE} | grep 'mac address' | cut -d\' -f2)
virsh net-dhcp-leases default --mac ${MAC} | grep ipv4 | awk '{print $5}' | cut -d/ -f1
and ssh to the VM as root
create a snapshot only for main disk (e.g. after installing microshift):
virsh snapshot-create-as --domain $DOMAIN --name "$DOMAIN-microshift" --atomic --disk-only --no-metadata --diskspec sda
- in virt-builder define a non-root user with sudo privilages and a password so we skip the step to allow ssh to root
- use static IP, so it does not change:
virsh net-update default add ip-dhcp-host \
"<host mac='$MAC' \
name='$NAME' ip='$IP' />" \
--live --config
if iso is manually downloaded, e.g.
Fedora-Server-netinst-x86_64-36-1.5.isois downloaded to theisodirectory. use: