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. A 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 project also provides Qemu with different command names but with 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
qemu Command Help
We can list short help information about the
qemu like below by using
$ qemu-system-x86_64 -h
qemu Command Syntax
Qemu syntax is the same as most of the Linux commands.
qemu-system-x86_64 OPTIONS IMAGE
OPTIONSare provided for VM options like Ram size, features, CPU, Graphics, etc.
IMAGEis 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 for Qemu VM
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 For Qemu VM
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 For Qemu
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 or Image For Qemu VM
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
Disable GUI for Qemu VM
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 guests will be connected with no network and the only single interface will be attached. This is not a practical and useful feature for most of the situations. We can add a network interface and connect this interface into a bridge device that is running in a host operating system. In this example, we will connect our guest with a
virtio 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 For Qemu VM
Generally, the best way to use VM disk images is 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://[email protected]/disk.img