-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup-kvm.sh
executable file
·83 lines (67 loc) · 2.45 KB
/
setup-kvm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
# quick and dirty setup of KVM to be used by packer
set -e
xiterr() { [[ $1 =~ ^[0-9]+$ ]] && { XIT=$1; shift; } || XIT=1; printf "FATAL: $*\n"; exit $XIT; }
main() {
source /etc/os-release
osfamily=$(echo "$ID" | tr -d '"' | cut -d '=' -f 2)
case $osfamily in
centos|redhat|rhel|fedora|oel)
inst=$(which yum 2> /dev/null)
[[ -z "$inst" ]] && inst=$(which dnf 2> /dev/null)
[[ -z "$inst" ]] && xiterr 1 "oops, how to install on '$osfamily'? (it ain't 'yum' or 'dnf')."
PKGS="libvirt libvirt-python iptables-services virt-install OVMF"
setup_redhat $VERSION_ID
POST="ln -s /usr/share/OVMF/x86/OVMF_CODE.fd /usr/share/OVMF/OVMF.fd"
;;
debian|ubuntu)
inst=apt
PKGS="qemu libvirt-bin python-libvirt vagrant-libvirt libvirt-clients libvirt-daemon-system virtinst ovmf"
add-apt-repository -y ppa:jacob/virtualisation
setup_debian $VERSION_ID
POST="echo 'nothing to do in POST'"
;;
*) xiterr 1 "Ask my masters for help, I don't know what to do for '$osfamily'."
;;
esac
$inst -y install qemu-kvm libguestfs-tools bridge-utils iptables util-linux unbound curl wget jq virt-viewer spice-vdagent $PKGS
eval $POST
virt-host-validate
}
setup_redhat() {
case $1 in
7)
cat << EOF-REPO > /etc/yum.repos.d/CentOS-Virt.repo
# CentOS-Virt
[virt-libvirt-latest]
name=CentOS-$releasever - Virt Libvirt Latest
baseurl=http://mirror.centos.org/centos/7/virt/x86_64/libvirt-latest/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[virt-kvm-common]
name=CentOS-$releasever - Virt KVM Common
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=virt&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/virt/$basearch/
baseurl=http://mirror.centos.org/centos/7/virt/x86_64/kvm-common/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EOF-REPO
yum -y makecache
yum -y install epel-release
;;
*)
xiterr 1 "Don't know how to do '$ID' version '$1' package repo setup for KVM. [in setup_redhat()]"
;;
esac
}
setup_debian() {
apt update
}
main $*
echo ""
echo "COMPLETE"
echo "Example VM launch to test libvirt (PXE boot):"
echo ""
echo "virt-install --name=foobar --ram=4096 --cpu host --hvm --vcpus=2 --os-type=linux --disk /var/lib/libvirt/images/disk.qcow2,size=20,bus=ide --network bridge=virbr0,model=e1000 --pxe --graphics vnc,listen=0.0.0.0,password=foobar --check all=off"
echo ""
exit $?