How to linux virtual machine

How to Install QEMU/KVM on Ubuntu to Create Virtual Machines

Virtualization is one of the most widely used technologies both in enterprise and home environments. Whether you are a seasoned IT expert, a programmer, or an IT novice, virtualization can be one of your greatest friends.

Virtualization is the abstraction of a computer’s hardware resources using a software application known as a hypervisor. The hypervisor creates an abstraction layer over computer hardware and virtualizes various components of the system including but not limited to memory, processor, storage, USB devices, etc.

In doing so, it allows you to create virtual computers also known as virtual machines off of the virtualized elements, and each virtual machine, also known as a guest, runs independently from the host system.

KVM, short for Kernel-based Virtual Machine is an open-source type 1 hypervisor (bare metal hypervisor) that is integrated into the Linux kernel. It allows you to create and manage virtual machines running Windows, Linux, or UNIX variants such as FreeBSD, and OpenBSD.

As mentioned earlier, each virtual machine has its own virtual resources such as storage, memory, CPU, network interfaces, USB interfaces, and video graphics to mention a few.

QEMU (Quick Emulator) is a software module that emulates various components of computer hardware. It supports full virtualizations and works alongside KVM to provide a holistic virtualization experience.

In this guide, we will demonstrate how to install QEMU/KVM on Ubuntu 20.04 / 22.04 distributions.

Step 1: Check Virtualization Enabled in Ubuntu

To start off check if your CPU supports virtualization technology. Your system needs to have an Intel VT-x (vmx) processor or AMD-V (svm) processor.

To verify this, run the following egrep command.

$ egrep -c '(vmx|svm)' /proc/cpuinfo

If Virtualization is supported, the output should be greater than 0, for example, 2,4,6, etc.

Alternatively, you can run the following grep command to display the type of processor your system supports. In our case, we are running Intel VT-x denoted by the vmx parameter.

$ grep -E --color '(vmx|svm)' /proc/cpuinfo

Enable Virtualization in Ubuntu

Equally important, check if KVM virtualization is supported by running the following command:

Check KVM Virtualization in Ubuntu

If the kvm-ok utility is missing, install the cpu-checker package as follows.

$ sudo apt install cpu-checker -y

Now that we have verified that our system supports KVM virtualization, let us proceed and install QEMU.

Step 2: Install QEMU/KVM on Ubuntu 20.04/22.04

Next up, update the package lists and repositories as follows.

Thereafter, install QEMU/KVM alongside other virtualization packages as follows:

$ sudo apt install qemu-kvm virt-manager virtinst libvirt-clients bridge-utils libvirt-daemon-system -y

Install Qemu in Ubuntu

Let us examine what role each of these packages plays.

  • qemu-kvm – This is an open-source emulator that emulates the hardware resources of a computer.
  • virt-manager – A Qt-based GUI interface for creating and managing virtual machines using the libvirt daemon.
  • virtinst – A collection of command-line utilities for creating and making changes to virtual machines.
  • libvirt-clients – APIs and client-side libraries for managing virtual machines from the command line.
  • bridge-utils – A set of command-line tools for managing bridge devices.
  • libvirt-daemon-system – Provides configuration files needed to run the virtualization service.
Читайте также:  Drivers intel hd graphics 4000 linux

At this point, we have installed QEMU and all the essential virtualization packages. The next step is to start and enable the libvirtd virtualization daemon.

So, run the following commands:

$ sudo systemctl enable --now libvirtd $ sudo systemctl start libvirtd

Next, verify if the virtualization service is running as shown.

$ sudo systemctl status libvirtd

Start libvirtd Virtualization Service

From the output above, the libvirtd daemon is up and running as expected. Additionally, add the currently logged-in user to the kvm and libvirt groups as shown.

$ sudo usermod -aG kvm $USER $ sudo usermod -aG libvirt $USER

Step 3: Launch Virtual Machine Manager in Ubuntu

The next step is to launch the QEMU/KVM GUI tool which is the Virtual Machine Manager.

The Virtual Machine Manager will pop up as shown. From here, you can start creating and managing virtual machines as we shall demonstrate shortly.

Qemu Virtual Machine Manager

Step 4: Create Virtual Machine with QEMU/KVM in Ubuntu

In this section, we will demonstrate how you can create a virtual machine using an ISO image. For demonstration purposes, we will use a Fedora Live ISO image. You can use an ISO image of your preferred OS and follow along.

To begin, click on the icon at the top left corner as shown below.

Create Virtual Machine in Qemu

Since we are creating a virtual machine from an ISO file, select the first option – ‘Local install media (ISO image or CDROM)‘. Then click ‘Forward‘.

Choose VM Install Type

Next, click ‘Browse’ to navigate to the location of the ISO file.

Choose VM ISO File

Since the ISO file is saved locally on your system, we will click ‘Browse Local’.

Browse Local Filesystem

Be sure to navigate to the location of your ISO file. Click it and then click ‘Open’.

Choose OS ISO File

Before proceeding, ensure that you have selected the operating system from the drop-down menu. Then click ‘Forward’.

Choose VM Operating System

Click ‘Yes’ on the pop-up to grant the emulator search permissions to the ISO file.

Grant Permission on Emulator

Next, select the Memory size and the number of CPU cores and click ‘Forward’.

Choose VM Memory and CPU Settings

In the next step, enable storage for the virtual machine and specify the virtual disk size. Then click ‘Forward’.

Choose VM Disk Size

Finally, review all the settings that you have defined, and if all looks good, click ‘Finish’ to create the virtual machine. Else, click ‘back’ and make the necessary changes.

Review VM Settings

Once you click ‘Finish’ the virtual machine manager will start creating the virtual machine based on the set configurations.

Creating Virtual Machine in Qemu

And in a matter of seconds, the virtual machine installation wizard will pop up. You can proceed with the installation as you would on a physical system.

Virtual Machine Installation

In addition, your virtual machine will be listed on the Virtual machine manager as shown. By right-clicking on your VM, you can perform a variety of tasks including pausing, rebooting, resetting, and deleting the virtual machine among many others.

Читайте также:  Kali linux bluetooth attacks

Virtual Machine Manager VM Settings

In this guide, we have demonstrated how to install QEMU/KVM on Ubuntu 20.04 / 22.04. In addition, we went a step further and created a virtual machine using an ISO image file.

To manage KVM virtual machines, read our following articles:

Источник

How to run an Ubuntu Desktop virtual machine using VirtualBox 7

In this tutorial, we’ll walk you through one of the easiest ways to try out Ubuntu Desktop on a virtual machine. VirtualBox is a general purpose virtualiser that is available across Linux, Mac OS and Windows. It’s a great way to experience Ubuntu regardless of your current operating system.

VirtualBox 7 and above includes a new feature called Unattended Guest OS Install which significantly streamlines the setup experience for common operating systems like Ubuntu, making it easier than ever to get started.

Note: This tutorial will also work for other distributions, so try it out with some of the Ubuntu flavours as well!

What you’ll learn

  • How to install and configure VirtualBox
  • How to import an Ubuntu image
  • How to run a virtual instance of Ubuntu Desktop
  • Further configuration options

What you’ll need

Download an Ubuntu Image

You can download an Ubuntu image here. Make sure to save it to a memorable location on your PC! For this tutorial, we will use the latest Ubuntu 22.10 release.

image

Download and install VirtualBox

You can download VirtualBox from the downloads page here. This page includes instructions on how to install VirtualBox for your specific OS so we won’t repeat those here.

Once you have completed the installation, go ahead and run VirtualBox.

2. Create a new virtual machine

Click New to create a new virtual machine. Fill in the appropriate details:

  • Name: If you include the word Ubuntu in your name the Type and Version will auto-update.
  • Machine Folder: This is where your virtual machines will be stored so you can resume working on them whenever you like.
  • ISO Image: Here you need to add a link to the ISO you downloaded from the Ubuntu website.

We want to install Ubuntu unattendedly so we can leave the checkbox to skip unchecked.

Create a user profile

To enable the automatic install we need to prepopulate our username and password here in addition to our machine name so that it can be configured automatically during first boot.

The default credentials are:

It is important to change these values since the defaults will create a user without sudo access.

Ensure your Hostname has no spaces to proceed!

It is also recommended to check the Guest Additions box to install the default Guest Additions ISO that is downloaded as part of VirtualBox. Guest additions enables a number of quality of life features such as changing resolution and dynamic screen resizing so it is highly recommended!

Note: If you choose not to use unattended install then this step will be skipped and you will go straight to the following screen. Once your machine has been created you will be able to create a username and password by proceeding through the standard Ubuntu Desktop installation flow on first boot.

Define the Virtual Machine’s resources

In the next section we can specifiy how much of our host machine’s memory and processors the virtual machine can use. For good performance it’s recommended to provide your VM with around 8GB of RAM (althought 4GB will still be usable) and 4 CPUs. Try to remain in the green areas of each slider to prevent issues with your machine running both the VM and the host OS.

Читайте также:  How to update vs code linux

Then we need to specify the size of the hard disc for the virtual machine. For Ubuntu we recommend around 25 GB as a minimum. By default the hard disk will scale dynamically as more memory is required up to the defined limit. If you want to pre-allocate the full amount, check the ‘Pre-allocate Full Size’ check box. This will improve performance but may take up unnecessary space.

Click Next to continue and view a summary of your machine setting.

After this click Finish to initialize the machine!

3. Install your image

Click Start to launch the virtual machine.

You will see a message saying ‘Powering VM up …’ and your desktop window will appear.

On first boot the unattended installation will kick in so do not interact with the prompt to ‘Try and Install Ubuntu’ and let it progress automatically to the splash screen and into the installer.

Note: If you chose not to use unattended install then you will need to progress through the Ubuntu install manually. Check out our Ubuntu Desktop installation tutorial for more details.

You will notice at this stage that the resolution of the window is fixed at 800×600. This is because the Guest Additions features are not installed until after the Ubuntu installation has completed.

Once the installation completes, the machine will automatically reboot to complete the installation.

Finally you will be greeted with the Ubuntu log-in screen where you can enter your username and password defined during the initial setup (don’t forget that the default password is ‘changeme’ if you left everything as the default).

4. Explore Virtual Box

Enjoy your shiny new Ubuntu Desktop!

As always we recommend opening a terminal and running sudo apt update && sudo apt upgrade -y and then sudo snap refresh to get everything updated to the latest versions.

Once you’ve finished your session you can close your machine by clicking the X in the top right of the window and choosing whether to keep your machine frozen in its current state or shut it down completely.

As you can probably tell, there are tonnes of further configuration options available in VirtualBox and we’ve only scratched the surface.

VirtualBox allows you to create and configure multiple virtual machines, so don’t be afraid to create new instances of Ubuntu to try out different system and storage configurations to fine tune your performance.

Why not try following the tutorial above with one of the Ubuntu flavours!

image

5. Tell us your thoughts!

Thank you for following this tutorial, we’d love to hear how you got on.

Give us feedback in the Ubuntu Discourse if you have any issues.

To help us improve our tutorials, we’d love to hear more about you:

How will you use this tutorial?

Источник

Оцените статью
Adblock
detector