QEMU Tutorial with Examples – POFTUT

QEMU Tutorial with Examples

Qemu is a very old virtualization technology used to virtualize system components and run operating systems on it. Before KVM and XEN QEMU was used heavily but it can not race with VMWARE or VIRTUAL PC. But with the KVM Qemu get superfast speed for computing by using hardware-based virtualization. QEMU acts as a hardware supplier and KVM is the CPU. KVM resides in Linux kernel and there is a little configuration for it. Virtualization configuration is made on the QEMU.

qemu-kvm or qemu or qemu-system-x86_64

Qemu is a very old and big project which has different user bases and intersecting with different projects. Qemu is used in the Linux Kernel Virtualization project named KVM. So this roject also provide Qemu with different command names but with the more features. qemu-system-x86_64 is the binary or command for Qemu which is used to create 64-bit x86 VMs.

Install Qemu

We can install Qemu with the qemu package name for different distributions.

Install Qemu For Ubuntu, Debian, Mint, Kali

We will use the following command.

Install Qemu For Ubuntu, Debian, Mint, Kali

Install Qemu For Ubuntu, Debian, Mint, Kali

Install Qemu For Fedora, CentOS, Red Hat

We will use both dnf and yum package managers according to distribution for rpm based install.

OR

Help

We can list short help information about the qemu like below by using -h option.

Help

Help

Syntax

Qemu syntax is the same as most of the Linux commands.

  • OPTIONS are provided for VM options like Ram size, features, CPU, Graphics, etc.
  • IMAGE is the file name of the disk for the VM.
LEARN MORE  How To Configure Linux Wireless From Command Line with wpa_supplicant

Download Cloud Images

Popular Linux distributions like Fedora, CentOS, Debian, Ubuntu, RedHat provides virtual machine images in various formats like raw, qcow2, vmdk, etc. We will download the Fedora 25 cloud image from the following link which is provided by the Fedora Project. Download with wget like below.

Download Cloud Images

Download Cloud Images

Set CPU and Core Count

CPU is one of the most important parts of a system. We can set the CPU core count for the VM in Qemu. We will provide the -smp option which will enable multiple CPU cores with the core=2 value which will set the core count 2 in the given VM.

Boot From Network

There are different ways to boot the VM system. Generally, images are used to boot but we can also boot from a network with the -boot order=nc option.

Set RAM or Memory Size

RAM is another important component of the VM. By default 128 MB RAM is set for the started VM. But we can also set the RAM size explicitly with the -m option which is the short form of the memory. We will also provide the size as MB where we will set 256 MB Ram in this example.

Set RAM or Memory Size

Set RAM or Memory Size

Set VM Name

We have also the option to set a name for the VM. We can use the -name option and provide the VM name. The VM name will be displayed in the Window header of the Qemu. In this example, we will set the VM name as poftut.com.

Specify Disk File

We can specify the disk/image file with the -drive option. This will provides us some ability to specify extra drivers related options. file is used to specify the file size. Also if is used to provide the driver or interface type for the disk.

Disable GUI

By default, the VM console will be provided as a GUI window. But we can also disable the console and only provide the terminal of the system with the -nographic option.

LEARN MORE  Linux Netstat Command With Examples

Connect To Virtual Switch Like virbr0

By default started guest will be connected no network and the only single interface will be attached. This is not practical and useful feature for most of the situations. We can add a network interface and connect this interface into a bridge device which is running in a host operating system. In this example, we will connect our guest with a virtuo type network interface into a virtual switch/bridge called virbr0 .

Use Remote Disk Images

Generally, the best way to use VM disk images are locally but qemu also supports the remote disk images via network share with different protocols like SSH, etc. In this example, we will use a disk image named disk.img on the remote system via SSh by using file option.

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)