This is just a note for docummenting the basic steps to create and start KVM virtual machines on Linux systems
-
Make a plan for virtual machine resources. For this, we should query host resources.
# show available disk spaces df -h # show available memory free -m # CPUs lscpu
-
Assume we are installing an Ubuntu server system. We shall download the ISO image for the system, e.g.,
wget \ https://releases.ubuntu.com/22.04.1/ubuntu-22.04.1-live-server-amd64.iso \ -O /var/lib/libvirt/images/ubuntu-22.04.1-live-server-amd64.iso
-
Create a virtual disk for the virtual machine, e.g.,
sudo truncate --size=10240M /var/lib/libvirt/images/officeservice.img
-
Decide how we should configure the virtual machine network. First, we query
existing ones:
virsh --connect qemu:///system net-list --all
-
Now create a virtual machine and set up Ubuntu Linux on it, e.g.,
sudo virt-install --name ubuntu \ --description 'Ubuntu Server LTS' \ --ram 4096 \ --vcpus 2 \ --disk path=/var/lib/libvirt/images/officeservice.img,size=10 \ --osinfo detect=on,name=ubuntu-lts-latest \ --network network=default \ --graphics vnc,listen=127.0.0.1,port=5901 \ --cdrom /var/lib/libvirt/images/ubuntu-22.04.1-live-server-amd64.iso \ --noautoconsole \ --connect qemu:///system
-
Suppose that you connect to Linux host via
ssh
via a Windows host. We cannot directly access the console of the virtual machine (that is at 127.0.0.1:5901 via VNC). In this case, we tunnel to the Linux host (assume its host name is LinuxHost) from the Windows host:ssh -L 15901:localhost:5901 LinuxHost
- We can now access the control via a VNC Viewer at the Windows host at localhost:15901.
-
Once Ubuntu installation is over, we would lose the VNC connectivity. But, we can
list the virtual machine created.
sudo virsh --connect qemu:///system list --all
-
To start the virtual machine, we run
sudo virsh --connect qemu:///system start ubuntu
-
To make the virtual machine to start when we boot the host, set the
virtual machine to be
autostart
, e.g.,virsh --connect qemu:///system autostart ubuntu
References
- https://docs.fedoraproject.org/en-US/quick-docs/getting-started-with-virtualization/
- https://ubuntu.com/blog/kvm-hyphervisor
- https://askubuntu.com/questions/160152/virt-install-says-name-is-in-use-but-virsh-list-all-is-empty-where-is-virt-i
- https://www.cyberciti.biz/faq/rhel-centos-linux-kvm-virtualization-start-virtual-machine-guest/
- https://www.cyberciti.biz/faq/howto-linux-delete-a-running-vm-guest-on-kvm/
No comments:
Post a Comment