19.6 C
Texas
angeloma
Senior Writer and partner

How to create a new KVM virtual Machine on Debian 10 / Ubuntu 20.04?

In the previous post, we explained How to install KVM on Debian 10 / Ubuntu 20.04. Now it’s time to create a KVM Virtual Machine.

Creating a new KVM Virtual Machine on Debian 10 / Ubuntu 20.04

Creating a network bridge

Before creating a virtual machine, the following must be taken into account. A new network interface is created when installing KVMs. If you are going to test some systems this is enough, but if you want the virtual machine to be accessible from the whole network then you have to create a Bridge.

To do this, edit the interfaces file:

:~$ sudo nano /etc/network/interfaces
- Advertisement -

And add the following:

auto ens33
iface ens33 inet manual

auto br0
iface br0 inet static
address x.x.x.x
netmask x.x.x.x
network x.x.x.x
broadcast x.x.x.x
gateway x.x.x.x
bridge_ports ens33
bridge_stp off
bridge_fd 0
bridge_maxwait 0
dns-nameservers x.x.x.x

In my case, the physical network interface is ens33. Remember you can find out your network interface by typing:

:~$ ip addr

And the network parameters depend on each case. And you have to replace them with your own.

Save the changes, exit the editor, and reboot your computer.

In case you are doing this tutorial on a Debian 10 / Ubuntu 20.04 system that has a desktop environment installed, you can do it through the Network options. There the process is more intuitive and easier to do on GNOME, KDE, or Cinnamon.

Remember that this step is optional.

Creating the KVM Virtual Machine using Virt-Manager

Virt-Manager is a program that allows us from a graphic interface to create a KVM Virtual Machine. If you are using Debian with a desktop environment then this section of the tutorial is for you.

So, install it with the following command

:~$ sudo apt install virt-manager
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
gir1.2-gtk-vnc-2.0 gir1.2-libvirt-glib-1.0 gir1.2-spiceclientglib-2.0
gir1.2-spiceclientgtk-3.0 python-asn1crypto python-certifi
python-cffi-backend python-chardet python-cryptography python-enum34
python-idna python-ipaddress python-openssl python-requests python-urllib3
Suggested packages:
python-cryptography-doc python-cryptography-vectors python-enum34-doc
python-openssl-doc python-openssl-dbg python-socks python-ntlm
python3-guestfs
The following NEW packages will be installed:
gir1.2-gtk-vnc-2.0 gir1.2-libvirt-glib-1.0 gir1.2-spiceclientglib-2.0
gir1.2-spiceclientgtk-3.0 python-asn1crypto python-certifi
python-cffi-backend python-chardet python-cryptography python-enum34
python-idna python-ipaddress python-openssl python-requests python-urllib3
virt-manager
0 upgraded, 16 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,400 kB of archives.
After this operation, 12.1 MB of additional disk space will be used.
Do you want to continue? [Y/n]
1.- Installing Virt-manager on Debian 10 / Ubuntu 20.04
1.- Installing Virt-manager on Debian 10 / Ubuntu 20.04

It will then be available from the main menu. When you start it, you will be asked for the root password.

And you will see the main screen:

2.- Virt-manager main screen
2.- Virt-manager main screen

Press the button to create a new virtual machine.

Then, select how you want to get the image of the virtual machine. It can be local or remote. In my case, I will choose local because I already downloaded it.

3.- Creating a new KVM Virtual Machine
3.- Creating a new KVM Virtual Machine

Clicking the Browser button and then the Browse Local button you can choose the system image from your computer.

4.- Select the OS image
4.- Select the OS image

Then set how much RAM and CPU memory the new virtual machine will use.

5.- KVM Virtual Machine settings
5.- KVM Virtual Machine settings

On the next screen, set the storage disk of the virtual machine. In this section you can set the size or disable the storage. Useful for LIVE images of distributions.

6.- Disks options
6.- Disks options

Then you will see the virtual machine summary and on this screen, you can choose the network to use.

7.- Creating a new KVM virtual machine on Debian 10 / Ubuntu 20.04
7.- Creating a new KVM virtual machine on Debian 10 / Ubuntu 20.04

And that’s it, the virtual machine will start.

8.- A KVM Virtual Machine running
8.- A KVM Virtual Machine running

Creating the KVM Virtual Machine from the terminal

Sure, the above step works if there is a desktop environment installed, but what if not? Well, you can also create it using the terminal.

To do this, you should create a folder where the files of this virtual machine will be. Inside this folder, you can create two more, one for the image and another for the storage.

:~$ mkdir -p virtual/{iso,storage}

In that ISO folder should be the image of the operating system you want to install in the virtual machine. Remember that using the wget command you can get one.

And now the command that creates the virtual machine is this:

:~$ sudo virt-install --name [name] --os-type linux --os-variant [linux-distribution] --ram [size] --vcpu [number] --disk path=[path]/[name].qcow2,size=10 --graphics vnc,listen=0.0.0.0 --noautoconsole --hvm --cdrom [path] --boot cdrom,hd

Remember to change the values in [] to the ones that are right for you.

If there is no error in the screen output, it means that the machine has been successfully created.

To access it, use a VNC client and use your IP address and port 0.

Conclusion

KVM is a wonderful technology that allows you to create virtual machines quickly. Whether using a graphical interface or the terminal the result is the same.

So, share this post and join our Telegram Channel.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article