ゴジラ

KVM on CentOS 7

Install libvirt and related packages,

yum install qemu-kvm libvirt virt-install bridge-utils

Enable IP forwarding,

echo "net.ipv4.ip_forward = 1"|sudo tee /etc/sysctl.d/99-ipforward.conf
sysctl -p /etc/sysctl.d/99-ipforward.conf

Create the network bridge,

bash -c 'cat > /etc/sysconfig/network-scripts/ifcfg-br0 << EOF
DEVICE=br0
TYPE=Bridge
BOOTPROTO=none
ONBOOT=yes
IPADDR=NETWORK_IP
NETMASK=NETWORK_NETMASK
GATEWAY=NETWORK_GATEWAY
DNS1=8.8.8.8
EOF'

bash -c 'cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
NAME=eth0
TYPE=Ethernet
ONBOOT=yes
HWADDR=ab:ab:ab:ab:ab:ab
BRIDGE=br0
EOF'

Restart network to activate the bridge/changes made above,

service network restart

Start and enable libvirt to start on boot,

systemctl enable libvirtd
systemctl start libvirtd

Creating our first Virtual Machine/Guest

Finally we get,

virt-install \
    --name $GUEST \
    --ram $RAM \
    --disk path=/var/lib/libvirt/images/$GUEST.qcow2,size=$HDD \
    --vcpus $CPU \
    --cdrom /var/lib/libvirt/images/$ISO \
    --boot cdrom \
    --graphics=vnc,password=$VNC_PASSWORD,listen=0.0.0.0,port=$VNC_PORT \
    --os-type linux \
    --network bridge=br0 \
    --mac $MAC

Last modified: December 06 2019 14:21:55