dotfiles/devel/kvm.sh

55 lines
1.5 KiB
Bash
Raw Normal View History

2020-11-02 04:08:18 +00:00
#!/bin/sh
2020-10-20 03:01:59 +00:00
2020-11-21 18:07:26 +00:00
set -e
2020-11-08 16:26:14 +00:00
DIR=$(dirname "$(readlink -f "$0")")
2020-11-02 04:08:18 +00:00
. "$DIR/../env.sh"
2020-10-20 03:01:59 +00:00
# tips
# 1. to relocate default pool
# ```
# virsh pool-destroy default
# virsh pool-edit default # modify the `update` node
# virsh pool-start default
# ```
# 2. create non-preallocated storage image file (slower performance but smaller size for copying)
# `qemu-img create -o preallocation=off -f qcow2 /path/to/img.qcow2 10G`
# 3. connecting to guest os prerequiste: use system session / guest nic source uses NAT
# install tools for kvm
case "$PM" in
apt)
2021-01-08 09:35:17 +00:00
#sudo apt install libvirt-daemon-system libvirt-clients virt-manager bridge-utils
# cli
2021-01-11 09:15:01 +00:00
case "$DISTRIB_CODENAME" in
xenial)
2021-01-13 01:43:42 +00:00
sudo apt install -y qemu-kvm libvirt-bin bridge-utils cpu-checker
2021-01-11 09:15:01 +00:00
;;
2021-01-13 01:43:42 +00:00
focal|bionic)
2021-01-11 09:15:01 +00:00
sudo apt install -y libvirt-daemon-system libvirt-clients cpu-checker
;;
*)
echo "unsupported os"
exit 1
;;
esac
kvm-ok
2021-01-08 09:35:17 +00:00
# gui
2021-01-11 09:15:01 +00:00
if [ -n "$DISPLAY" ] ;then
sudo apt install -y virt-manager
2021-01-13 01:43:42 +00:00
else
sudo apt install -y virtinst
2021-01-11 09:15:01 +00:00
fi
2020-10-20 03:01:59 +00:00
;;
pacman)
# TODO
2021-08-28 09:55:01 +00:00
sudo pacman -S --noconfirm --needed \
2021-08-28 14:16:37 +00:00
ebtables dnsmasq qemu libvirt virt-manager
2020-10-20 03:01:59 +00:00
;;
esac
# configuration
2020-11-02 04:08:18 +00:00
sudo usermod -aG libvirt "$USER"
2021-08-28 09:55:01 +00:00
echo install [spice-guest-tools] on guest os for auto resolution adjustment