2016-03-26 21:49:41 +01:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
2017-04-27 22:58:43 +02:00
|
|
|
set -o pipefail
|
2016-03-26 21:49:41 +01:00
|
|
|
|
|
|
|
# add the correct user perms
|
2019-12-03 19:21:09 +01:00
|
|
|
echo "Adding the user groups..."
|
2016-03-26 21:49:41 +01:00
|
|
|
gpasswd -a root libvirt
|
|
|
|
gpasswd -a root kvm
|
|
|
|
chown root:kvm /dev/kvm
|
|
|
|
|
2019-12-03 19:21:09 +01:00
|
|
|
# allow root user to use qemu
|
|
|
|
echo 'user = "root"' >> /etc/libvirt/qemu.conf
|
|
|
|
echo 'group = "root"' >> /etc/libvirt/qemu.conf
|
|
|
|
|
2016-03-26 21:49:41 +01:00
|
|
|
# create the bridge for networking
|
2019-12-03 19:21:09 +01:00
|
|
|
echo "Creating the bridge for networking..."
|
2016-03-26 21:49:41 +01:00
|
|
|
ip link add name virt0 type bridge
|
2016-03-26 22:41:58 +01:00
|
|
|
ip link set dev virt0 up
|
2016-03-26 21:49:41 +01:00
|
|
|
bridge link
|
2016-03-26 22:41:58 +01:00
|
|
|
ip addr add dev virt0 172.20.0.1/16
|
|
|
|
iptables -t nat -A POSTROUTING -s 172.20.0.1/16 -j MASQUERADE
|
2016-03-26 21:49:41 +01:00
|
|
|
|
|
|
|
# start the virtlogd daemon
|
2019-12-03 19:21:09 +01:00
|
|
|
echo "Starting virtlogd..."
|
|
|
|
virtlogd &
|
|
|
|
|
|
|
|
# start libvirtd
|
|
|
|
echo "Starting libvirtd..."
|
|
|
|
libvirtd &
|
|
|
|
|
|
|
|
# put in a sleep for services to start
|
|
|
|
echo "Sleeping while services start..."
|
|
|
|
sleep 5
|
2016-03-26 21:49:41 +01:00
|
|
|
|
2019-12-03 18:20:28 +01:00
|
|
|
# start the default networking
|
2019-12-03 19:21:09 +01:00
|
|
|
echo "Creating the default networking..."
|
|
|
|
virsh net-start default
|
|
|
|
|
|
|
|
# import existing vms
|
|
|
|
echo "Importing any existing VMs..."
|
|
|
|
for f in /root/kvm/*.xml; do
|
2019-12-03 20:08:17 +01:00
|
|
|
echo "Importing $(basename "$f")..."
|
2019-12-03 19:21:09 +01:00
|
|
|
virsh define "$f"
|
|
|
|
done
|
2019-12-03 18:20:28 +01:00
|
|
|
|
2019-12-03 19:21:09 +01:00
|
|
|
echo "Starting virt-manager..."
|
2018-09-25 01:17:06 +02:00
|
|
|
# shellcheck disable=SC2068
|
2016-03-26 21:49:41 +01:00
|
|
|
exec $@
|