Categories

Start the box

BOX_NAME=""

sudo virt-install --virt-type=kvm --name $BOX_NAME --ram=2048 --vcpus=2 --os-variant=centos7.0 --cdrom=/var/lib/libvirt/boot/CentOS-7-x86_64-Minimal-1804.iso --network=bridge=br0,model=virtio --graphics vnc --disk path=/var/lib/libvirt/images/$BOX_NAME.qcow2,size=50,bus=virtio,format=qcow2

After the box started, the OS image will be loaded and the linux installation can be done using VNC. This command will not exit until the installation have completed. The client OS will reboot and after the command exited, the client OS will continue running since then.

Looking for which port VNC binds to

Open an another shell session, and run

sudo virsh dumpxml $BOX_NAME | grep vnc

The command will return something like this.

<graphics type='vnc' port='5902' autoport='yes' listen='127.0.0.1'>
ssh -L 0.0.0.0:5901:127.0.0.1:5902 kvm-server

then use vnc-viewer to see the pseudo screen by connecting to 127.0.0.1:5901.

Install Operating System

In the pseudo screen provided by vnc-viewer, install CentOS or Ubuntu using GUI, after the installation completed, click restart the computer in installation GUI.

Get the list of boxes

sudo virsh list

Setup Network

Use VNC screenshot to config the network

vi /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.0.100
GATEWAY=192.168.0.1
NETMASK=255.255.255.0
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=a7xxxxaf-11c5-4249-9673-2e0693993969
DEVICE=eth0
ONBOOT=yes
vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
service network restart

Remove the box

sudo virsh destroy $BOX_NAME
sudo virsh undefine $BOX_NAME
sudo rm /var/lib/libvirt/images/$BOX_NAME.qcow2

Reference