# setup on alpine hosts
apk add virt-manager libvirt-qemu qemu-system-x86_64 ovmf
service libvirtd start
modprobe tun
virt-manager -c qemu:///system


# setup on arch hosts
pacman -Syu ebtables dnsmasq firewalld virt-manager libvirt ovmf qemu
systemctl start ebtables
systemctl restart firewalld
systemctl restart libvirtd
virsh net-start default
systemctl start libvirtd
# and maybe these too
systemctl start virtqemud
systemctl start virtstoraged
systemctl start virtnetworkd
systemctl start virtinterfaced virtlockd virtlogd virtlxcd virtnodedevd virtnwfilterd virtproxyd virtsecretd


# add images
cd /var/lib/libvirt/images
wget https://mirrors.edge.kernel.org/archlinux/iso/latest/archlinux-$(date +%Y.%m).01-x86_64.iso


# create vm without "enable storage" and then
qemu-img create -f qcow2 arch-efi.qcow2 128G


# recommended settings
display spice
  listen type: none
add new storage device (sda)
  bus type: scsi
  discard mode: unmap
  detect zeroes: unmap
controller scsi 0
  model: virtio scsi


# host-only network
cat >host-only.xml <<'EOF'
<network>
  <name>virhost0</name>
  <bridge name="virhost0" stp="on" delay="0" />
  <ip address="192.168.123.1" netmask="255.255.255.0">
    <dhcp>
      <range start="192.168.123.100" end="192.168.123.254" />
    </dhcp>
  </ip>
</network>
EOF
virsh net-define host-only.xml
virsh net-start virhost0
virsh net-autostart virhost0


# if efi, modify xml to allow snapshots
 bad: <loader readonly="yes" type="pflash">/usr/share/qemu/edk2-x86_64-code.fd</loader>
good: <loader readonly="yes" type="rom">/usr/share/qemu/edk2-x86_64-code.fd</loader>
#
# nevermind that doesnt work, use external snapshots
s=s7; d=win10; p="/var/lib/libvirt/qemu/snapshot/$d/$s"; mkdir -p "$p"; virsh snapshot-create-as "$d" --name "$s" --live --atomic --diskspec sda,snapshot=external,file="$p/disk.qcow2" --memspec file="$p/mem.qcow2",snapshot=external
#
# nevermind that doesnt work, use save/retore
s=s9; d=win10; p="/var/lib/libvirt/qemu/snapshot/$d"; mkdir -p "$p"; virsh save $d "$p/$s.qcow2" --running --verbose 
virsh restore "$p/$s.qcow2" --running            


# setup nfs-server in vm
pacman -S nfs-utils
mkdir /srv/nfs4
cat >>/etc/exports <<'EOF'
/home/ed 192.168.123.1(rw,sync,no_subtree_check)
EOF
exportfs -arv
systemctl enable --now nfs-server


# connect from host
mount -t nfs4 192.168.123.2:/home/ed /home/ed/r/arch/

