2018-05-25 19:50:26 +00:00
= How to use QEMU
2023-08-19 08:33:41 +00:00
Richard Gregory
:revnumber: unspecified
:revdate: 2020-11-05
:category: Virtualisation
2023-08-28 20:44:35 +00:00
:tags: How-to, Qemu
2023-08-19 08:33:41 +00:00
// :page-aliases:
2017-10-26 21:20:01 +00:00
2023-08-19 08:33:41 +00:00
[abstract]
2018-04-11 14:46:02 +00:00
QEMU is a very flexible virtualization technology however it is quite slow and it is recommended that you understand and evaluate alternative solutions before picking this one.
2023-08-19 08:33:41 +00:00
Refer to xref:getting-started-with-virtualization.adoc[Getting started with virtualization]
2017-10-26 21:20:01 +00:00
[[qemu]]
2018-05-25 19:50:26 +00:00
== QEMU
2017-10-26 21:20:01 +00:00
2018-04-11 14:46:02 +00:00
QEMU is a generic and open source processor emulator which achieves a good emulation speed by using dynamic translation.
2017-10-26 21:20:01 +00:00
QEMU has two operating modes:
2018-04-11 14:46:02 +00:00
* Full system emulation.
2020-04-18 21:27:08 +00:00
In this mode, QEMU emulates a full system (for example a PC), including a processor and various peripherials.
It can be used to launch different Operating Systems without rebooting the PC or to debug system code.
2018-04-11 14:46:02 +00:00
* User mode emulation (Linux host only). In this mode, QEMU can launch Linux processes compiled for one CPU on another CPU.
2017-10-26 21:20:01 +00:00
[[download]]
2018-04-11 14:46:02 +00:00
== Download
2017-10-26 21:20:01 +00:00
2023-08-19 08:33:41 +00:00
QEMU is available on Fedora repository. It can be installed by using xref:dnf.adoc[DNF]:
2017-10-26 21:20:01 +00:00
....
$ su -c "dnf install qemu"
....
2023-08-19 08:33:41 +00:00
[[qemu-commands]]
== QEMU commands
2017-10-26 21:20:01 +00:00
To discover the qemu commands that are installed perform the following:
....
$ ls /usr/bin/qemu-*
....
2018-04-11 14:46:02 +00:00
In the following examples where "qemu" is, substitute your command for executing qemu. E.g.
2017-10-26 21:20:01 +00:00
....
qemu-system-i386
....
or
....
qemu-i386
....
Of course, this does not apply to "qemu-img".
[[qemu-virtual-machine-installation]]
2018-05-25 19:50:26 +00:00
== QEMU virtual machine installation
2017-10-26 21:20:01 +00:00
Create the virtual image for the system:
....
$ qemu-img create fedora.qcow 5G
....
Of course you are not obliged to take 5GB.
2018-04-11 14:46:02 +00:00
Note: Even if you take 10GB this does NOT mean that the image does really HAVE the size of 10GB. It just means that your new system is limited up to 10GB - if the new system takes only 1,2 GB also the image will only be at 1,2GB.
2017-10-26 21:20:01 +00:00
2018-04-11 14:46:02 +00:00
Now let's install the OS. Put in the install CD and type into your konsole (all in one line without break):
2017-10-26 21:20:01 +00:00
....
2020-11-05 11:47:51 +00:00
$ qemu -cdrom /dev/cdrom -hda fedora.qcow -boot d -net nic -net user -m 196 -rtc base=localtime
2017-10-26 21:20:01 +00:00
....
2018-04-11 14:46:02 +00:00
"-user -net" is important to have internet access within your new system.
"-m 196" is the Set virtual RAM size (megabytes), default is 128 MB, I chose 196.
2017-10-26 21:20:01 +00:00
2018-04-11 14:46:02 +00:00
The install may take some time. After the install, qemu will try to boot the new OS itself.
Maybe this may fail (was the case for me) - but don't worry.
If that happens: just close the qemu window and type the following command into your konsole to launch your new OS:
2017-10-26 21:20:01 +00:00
....
2020-11-05 11:47:51 +00:00
$qemu fedora.qcow -boot c -net nic -net user -m 196 -rtc base=localtime
2017-10-26 21:20:01 +00:00
....
[[testing-iso-images]]
2018-04-11 14:46:02 +00:00
== Testing ISO Images
2017-10-26 21:20:01 +00:00
Type, in the proper directory
....
$ qemu -m 512M -cdrom <isoname>.iso
....
[[debugging]]
2018-04-11 14:46:02 +00:00
== Debugging
2017-10-26 21:20:01 +00:00
2018-04-11 14:46:02 +00:00
To get kernel output dumped to a file outside the virtual system, add e.g. "-serial file:/tmp/qemu-output.log" to the qemu command line.
When booting the virtual system, add "console=ttyS0" to the kernel boot parameters.
2017-10-26 21:20:01 +00:00
2018-04-11 14:46:02 +00:00
This output is particularly helpful if you are having trouble booting the system, in which case you may also wish to remove "rhgb" and "quiet" from the kernel boot parameters.