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.
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.
$ sudo apt install qemu
Install Qemu For Fedora, CentOS, Red Hat
We will use both dnf and yum package managers according to distribution for rpm based install.
$ sudo dnf install qemu
$ sudo yum install qemu
We can list short help information about the
qemu like below by using
$ qemu-system-x86_64 -h
Qemu syntax is the same as most of the Linux commands.
qemu-system-x86_64 OPTIONS IMAGE
- `OPTIONS` are provided for VM options like Ram size, features, CPU, Graphics, etc.
- `IMAGE` is the file name of the disk for the VM.
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.
$ wget http://www.nic.funet.fi/pub/mirrors/fedora.redhat.com/pub/fedora/linux/releases/30/Cloud/x86_64/images/Fedora-Cloud-Base-30-1.2.x86_64.qcow2
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.
$ qemu-system-x86_64 -smp cores=2
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.
$ qemu-system-x86_64 -boot order=nc
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.
$ qemu-system-x86_64 -m 256
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
$ qemu-system-x86_64 -name 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.
$ qemu-system-x86_64 -drive file=fedoraraw.qcow2,if=virtio
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
$ qemu-system-x86_64 -nographic
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
$ qemu-system-x86_64 -drive file=fedoraraw.qcow2,if=virtio -display none -net bridge,br=virbr0 -net nic,model=virtio
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
$ qemu-system-x86_64 -drive file=ssh://firstname.lastname@example.org/disk.img