-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqemu.txt
160 lines (111 loc) · 5.35 KB
/
qemu.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
QEMU
====
Steven K. Baum
v0.1, 2016-08-05
:doctype: book
:toc:
:icons:
:numbered!:
[preface]
Overview
--------
https://en.wikipedia.org/wiki/QEMU[`https://en.wikipedia.org/wiki/QEMU`]
*****
QEMU (short for Quick EMUlator is a free and open-source emulator and virtualizer that can perform hardware virtualization.
QEMU is a hosted virtual machine monitor: it emulates the machine's processor through dynamic binary translation and provides a set of different hardware and device models for the machine, enabling it to run a variety of guest operating systems. It also can be used with Kernel-based Virtual Machine (KVM) to run virtual machines at near-native speed (by taking advantage of hardware extensions such as Intel VT-x). QEMU can also do emulation for user-level processes, allowing applications compiled for one architecture to run on another.
QEMU has multiple operating modes:
* *User-mode emulation* - In this mode QEMU runs single Linux or Darwin/macOS programs that were compiled for a different instruction set. System calls are thunked for endianness and for 32/64 bit mismatches. Fast cross-compilation and cross-debugging are the main targets for user-mode emulation.
* *System emulation* - In this mode QEMU emulates a full computer system, including peripherals. It can be used to provide virtual hosting of several virtual computers on a single computer. QEMU can boot many guest operating systems, including Linux, Solaris, Microsoft Windows, DOS, and BSD; it supports emulating several instruction sets, including x86, MIPS, 32-bit ARMv7, ARMv8, PowerPC, SPARC, ETRAX CRIS and MicroBlaze.
* *KVM Hosting* - Here QEMU deals with the setting up and migration of KVM images. It is still involved in the emulation of hardware, but the execution of the guest is done by KVM as requested by QEMU.
*****
Official Documentation
----------------------
https://www.qemu.org/documentation/[`https://www.qemu.org/documentation/`]
Tutorial
--------
*Getting Started With QEMU*
https://drewdevault.com/2018/09/10/Getting-started-with-qemu.html[`https://drewdevault.com/2018/09/10/Getting-started-with-qemu.html`]
*****
qemu is the swiss army knife of virtualisation, much like ffmpeg is the swiss army knife of multimedia. Why is it better than all of the other options? Well, in short: qemu is fast, portable, better supported by guests, and has more features than Hollywood. There’s nothing other hypervisors can do that qemu can’t, and there’s plenty qemu can that they cannot.
*****
Quick Example
~~~~~~~~~~~~~
Download an ISO image:
-----
curl -O https://nl.alpinelinux.org/alpine/v3.8/releases/x86_64/alpine-standard-3.8.0-x86_64.iso
-----
Create a virtual hard drive:
-----
qemu-img create -f qcow2 alpine.qcow2 16G
-----
Boot up a VM using the ISO image and virtual hard disk:
-----
qemu-system-x86_64 \
-enable-kvm \
-m 2048 \
-nic user,model=virtio \
-drive file=alpine.qcow2,media=disk,if=virtio \
-cdrom alpine-standard-3.8.0-x86_64.iso \
-sdl
-----
The arguments are:
* *-enable-kvm* - enables use of the KVM (kernel virtual machine) to use hardware
accelerated virtualization on Linux
* *-m 20148* - specifies 2G of RAM for the guest
* *-nic user,model=virtio* - adds a virtual *n*etwork *i*nterface *c*ontroller using
a virtual LNA emulated by QEMU to enable internet access, with +mode=virtio+ enabling a
specific NIC model to provide faster networking
* *-drive file=alpine.qcow2,media=disk,if=virtio* - attaches the virtual disk to the guest that
will show up as +/dev/vda+, with +if=virtio+ supplying the fastest interface for Linux
* *-drom alpine-standard-3.8.0-x86_64.iso* - connects a virtual CD drive to the guest and
loads the install media into it
* *-sdl* - specifies the graphical configuration, in this case the SDL backend which is the
simplest usable one
Running this command causes an SDL window to appear and Alpine to boot.
Examples
--------
Emulating a Raspberry Pi
~~~~~~~~~~~~~~~~~~~~~~~~
https://blog.agchapman.com/using-qemu-to-emulate-a-raspberry-pi/[`https://blog.agchapman.com/using-qemu-to-emulate-a-raspberry-pi/`]
https://github.com/dhruvvyas90/qemu-rpi-kernel[`https://github.com/dhruvvyas90/qemu-rpi-kernel`]
Get an Raspbian image from:
https://www.raspberrypi.org/software/operating-systems/[`https://www.raspberrypi.org/software/operating-systems/`]
The Lite image will take less time for testing purposes. The latest as of this
writing is:
-----
2020-12-02-raspios-buster-armhf-lite.zip
-----
Get the kernel file:
-----
wget https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/kernel-qemu-5.4.51-buster
-----
Get the DTB file:
-----
wget https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/versatile-pb-buster-5.4.51.dtb
-----
Unzip the Raspbian image:
-----
unzip 2020-12-02-raspios-buster-armhf-lite.zip
-----
Convert the +.img+ file to +qcow+ format:
-----
qemu-img convert -f raw -O qcow2 2020-12-02-raspios-buster-armhf-lite.img 2020-12-02-raspios-buster-armhf-lite.qcow
-----
Resize the +qcow+ image:
-----
qemu-img resize 2020-12-02-raspios-buster-armhf-lite.qcow +6G
-----
Run the thing:
-----
qemu-system-arm \
-kernel ./kernel-qemu-4.4.34-jessie \
-dtb versatile-pb-buster-5.4.51.dtb \
-append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" \
-hda raspbian-stretch-lite.qcow \
-cpu arm1176 -m 256 \
-M versatilepb \
-no-reboot \
-serial stdio \
-net nic -net user \
-net tap,ifname=vnet0,script=no,downscript=no
-----