How to Create Virtual Machine in Ubuntu Server

A virtual machine is a computer created within another computer, called the “host.”

Virtual machines are popular because they allow users to run multiple operating systems (OSes) on a single physical machine.

This can be useful for software development or testing purposes, among other things.

Creating a virtual machine in Ubuntu is fairly simple, and can be done through the use of the built-in “Ubuntu Server” program.

This program will create a virtual machine that can be used to install any OS. In this guide, we’ll walk you through the steps of creating a virtual machine in Ubuntu Server.

How to Create Virtual Machine in Ubuntu Server

What is a Virtual Machine?

A virtual machine (VM) is a software-based emulation of a physical computing environment.

It allows you to run multiple operating systems (OSes) at the same time on a single physical computer.

Each OS runs in its own VM and has full access to the hardware resources, making it appear as if it were installed on a separate computer.

Why Use a Virtual Machine?

A virtual machine is a guest operating system (OS) that runs on top of a host OS. It has its own virtual hardware, including a virtual CPU, memory, storage, and networking.

Virtual machines are useful for many purposes. They can be used to:

  • Try out new operating systems without installing them on your physical computer
  • Isolate an operating system or application from your physical computer
  • Run multiple operating systems or applications on the same physical computer
  • Easily backup and restore an operating system or application

How to Create a Virtual Machine in Ubuntu Server

Using virtual machines can be a great way to improve your productivity and workflows.

By creating a virtual machine, you can have a separate environment for running different operating systems or applications.

This can be useful for testing purposes, or for working with software that is not compatible with your primary operating system.

In this tutorial, we will show you how to create a virtual machine in Ubuntu Server using the command line.

We will be using the open source software called QEMU to create our virtual machine.

Before we begin, there are a few things that you should know about QEMU. QEMU is a emulator that can run operating systems and programs for one machine on another.

In other words, it can be used to simulate different hardware environments on your computer.

QEMU can be used in conjunction with KVM (Kernel-based Virtual Machine) to create virtual machines that have near-native performance.

KVM is a kernel module that allows QEMU to use your computer’s hardware resources to run virtual machines.

To use QEMU with KVM, you will need a CPU that supports hardware virtualization extensions, such as Intel VT-x or AMD-V. Most modern CPUs support these extensions.

You will also need to enable KVM in your kernel’s configuration file. Consult your distribution’s documentation for more information on how to do this.

With that out of the way, let’s get started!

Creating a Virtual Machine in Ubuntu Server

Whether you’re a system administrator or a developer, sometimes you need to run multiple operating systems on the same computer.

This can be for testing purposes, or because you need to use software that only runs on one type of OS.

In either case, you can create what’s called a virtual machine (VM), which essentially is an emulated computer running inside your main computer.

There are many software options available for creating and running VMs, but in this guide, we’ll focus on creating VMs using the built-in tool in Ubuntu Server 18.04, called KVM (Kernel-based Virtual Machine).

Creating a VM with KVM is a two-step process: first, you create the VM itself, then you install an operating system of your choice on the VM.

We’ll go over both steps so that you can have your own VM up and running in no time.

Configuring a Virtual Machine in Ubuntu Server

This guide covers the basic steps necessary to configure a virtual machine in Ubuntu Server. Before you begin, you will need to make sure you have the following:

  • A compatible CPU
  • Enough memory for the guest operating system
  • Free disk space for the virtual machine’s disk image

In this guide we will be using KVM as our hypervisor. This guide also assumes you are using a 64-bit host operating system. If you are using a 32-bit host operating system, some of the commands and options may be different.

1) install kvm and related packages
sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virt-manager
2) add your user to the libvirt group
sudo adduser libvirt
sudo adduser kvm
3) create a new directory for your virtual machine images
mkdir -p ~/vms/

4) use virt-install to create a new vm

--name=<vmname>: The name of the VM. This is what will be used to identify the VM in virt-manager and other tools.

--os-type=<ostype>: The type of operating system you are installing. This option is only required if you are installing an OS that virt-install does not recognize. For most popular OSes, such as Linux and Windows, virt-install will automatically detect the OS type.

--os-variant=<variant>: The specific variant of the OS type you are installing. This option is only required if you are installing an OS that virt-install does not recognize or if you want to use a specific settings profile for your VM (for example, Fedora 25Server).

--ram=<size>: The amount of memory, in MB, to allocate to the VM. Be sure to leave enough memory for your host operating system!

--vcpus=<count>: The number of virtual CPUs to allocate to the VM. You can leave this at the default (1) unless your CPU supports multiple threads per core (most Intel CPUs do) or unless you know you will need more than one CPU for your application(s).

--disk path=<path>,size=<size>,format=qcow2: The path where you want to store the disk image for your VM (we created a directory for this earlier), followed by the size of the disk image in GB, and finally followed by the format of the disk image file (qcow2 is recommended). If you have additional disks or more than one disk controller, you can specify those here as well. See "man virt-install" for more options.

--graphics vnc: This tells virt-install that we want to use VNC for our VM's display output instead of SDL (which would display output on our host's screen). We could also use SPICE here which would provide better performance and features but it requires additional software on both our host and guest systems so we'll stick with VNC for now.

--network bridge: By default, VMs created with virt-install will be given NATed network access through libvirt's builtin DHCP server but we can change this by using one of several --network options. For our purposes we'll use --network bridge which assigns our VM its own IP address on our local network just like a physical computer would have been assigned.

If we had plugged it into one of our network switch ports directly instead of creating it virtually inside our server first.

Be sure that whichever network interface on your server that is bridged with your LAN has an appropriate IP address already assigned before starting this command!

If it doesn’t, dhclient may attempt to acquire an IP address from DHCP which will cause this command to fail since ISC dhcpd is not running inside guest instances by default like it would be on physical servers.

After starting up successfully, your new VM should have its own IP address which can be obtained by running “virsh domifaddr <vmname>” on your KVM host or by looking at DHCP leases on your router or DHCP server if it is configured correctly.

You should now be able to ssh into your new virtual machine as root just like any other server!

Finally, start up your new vm virsh start <vmname>

Managing a Virtual Machine in Ubuntu Server

A virtual machine is a software computer that, like a physical computer, runs an operating system and applications.

The major difference between a physical computer and a virtual machine is that the virtual machine doesn’t have its own dedicated hardware but instead install on and shares the hardware resources of its host physical machine.

Creating and Managing Virtual Machines in Ubuntu Server with KVM

Kernel-based Virtual Machine (KVM) is a full virtualization solution for Linux on IBM z Systems™ processors.

This section provides information about how to download, install, and configure KVM in Ubuntu Server to create and manage virtual machines (VMs). It also provides information about how to configure networking and storage for your VMs.

Before you begin, review the following prerequisites:

  • You must have root user access or sudo privileges to complete these tasks. To learn how to gain root user access, see How to gain root user access on an IBM z Systems™ server running LinuxONE™ or How to use sudo privileges on an IBM z Systems server running LinuxONE or Obtaining administrative privileges on an IBM LinuxONE server.
  • The system must have enough computing power, memory, storage, and I/O capacity to support both the host OS and all of the guest VMs that you plan to create. The resources required for any given VM are highly dependent on the workloads that you plan to run inside of it and can vary considerably from one VM to another.
  • The system must have hypervisor software installed. For more information about KVM requirements, see .
  • Installing KVM in Ubuntu Server 16.04 LTS or later
    KVM is included in the mainline kernel package in Ubuntu 16.04 LTS or later releases so no additional installation is required; you can confirm this by checking that the kvm module is loaded:


In this article, we have shown you how to create a virtual machine in Ubuntu server using the virt-manager tool.

We have also covered some basic troubleshooting tips to help you get started.

Related Posts