1 | <?xml version="1.0" encoding="UTF-8"?>
|
---|
2 | <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"[
|
---|
4 | <!ENTITY % all.entities SYSTEM "all-entities.ent">
|
---|
5 | %all.entities;
|
---|
6 | ]>
|
---|
7 | <chapter id="TechnicalBackground">
|
---|
8 |
|
---|
9 | <title>Technical Background</title>
|
---|
10 |
|
---|
11 | <para>
|
---|
12 | The contents of this chapter are not required to use VirtualBox
|
---|
13 | successfully. The following is provided as additional information
|
---|
14 | for readers who are more familiar with computer architecture and
|
---|
15 | technology and wish to find out more about how VirtualBox works
|
---|
16 | "under the hood".
|
---|
17 | </para>
|
---|
18 |
|
---|
19 | <sect1 id="vboxconfigdata">
|
---|
20 |
|
---|
21 | <title>Where VirtualBox Stores its Files</title>
|
---|
22 |
|
---|
23 | <para>
|
---|
24 | In VirtualBox, a virtual machine and its settings are described in
|
---|
25 | a virtual machine settings file in XML format. In addition, most
|
---|
26 | virtual machine have one or more virtual hard disks, which are
|
---|
27 | typically represented by disk images, such as those in VDI format.
|
---|
28 | Where all these files are stored depends on which version of
|
---|
29 | VirtualBox created the machine.
|
---|
30 | </para>
|
---|
31 |
|
---|
32 | <sect2 id="vboxconfigdata-pre-version-four">
|
---|
33 |
|
---|
34 | <title>Machines Created by VirtualBox Version 4.0 or Later</title>
|
---|
35 |
|
---|
36 | <para>
|
---|
37 | Starting with version 4.0, by default, each virtual machine has
|
---|
38 | one directory on your host computer where all the files of that
|
---|
39 | machine are stored: the XML settings file, with a
|
---|
40 | <computeroutput>.vbox</computeroutput> file extension, and its
|
---|
41 | disk images.
|
---|
42 | </para>
|
---|
43 |
|
---|
44 | <para>
|
---|
45 | By default, this <replaceable>machine folder</replaceable> is
|
---|
46 | placed in a common folder called <computeroutput>VirtualBox
|
---|
47 | VMs</computeroutput>, which VirtualBox creates in the current
|
---|
48 | system user's home directory. The location of this home
|
---|
49 | directory depends on the conventions of the host operating
|
---|
50 | system:
|
---|
51 | </para>
|
---|
52 |
|
---|
53 | <itemizedlist>
|
---|
54 |
|
---|
55 | <listitem>
|
---|
56 | <para>
|
---|
57 | On Windows, this is the location returned by the
|
---|
58 | <computeroutput>SHGetFolderPath</computeroutput> function of
|
---|
59 | the Windows system library Shell32.dll, asking for the user
|
---|
60 | profile. On very old Windows versions which do not have this
|
---|
61 | function or where it unexpectedly returns an error, there is
|
---|
62 | a fallback based on environment variables. First,
|
---|
63 | <computeroutput>%USERPROFILE%</computeroutput> is checked.
|
---|
64 | If it does not exist then an attempt with
|
---|
65 | <computeroutput>%HOMEDRIVE%%HOMEPATH%</computeroutput> is
|
---|
66 | made. A typical location is
|
---|
67 | <computeroutput>C:\Users\username</computeroutput>.
|
---|
68 | </para>
|
---|
69 | </listitem>
|
---|
70 |
|
---|
71 | <listitem>
|
---|
72 | <para>
|
---|
73 | On Linux, Mac OS X and Solaris, this is generally taken from
|
---|
74 | the environment variable
|
---|
75 | <computeroutput>$HOME</computeroutput>, except for the user
|
---|
76 | <computeroutput>root</computeroutput> where it is taken from
|
---|
77 | the account database. This is a workaround for the frequent
|
---|
78 | trouble caused by users using VirtualBox in combination with
|
---|
79 | the tool <computeroutput>sudo</computeroutput> which by
|
---|
80 | default does not reset the environment variable
|
---|
81 | <computeroutput>$HOME</computeroutput>. A typical location
|
---|
82 | on Linux and Solaris is
|
---|
83 | <computeroutput>/home/username</computeroutput> and on Mac
|
---|
84 | OS X <computeroutput>/Users/username</computeroutput>.
|
---|
85 | </para>
|
---|
86 | </listitem>
|
---|
87 |
|
---|
88 | </itemizedlist>
|
---|
89 |
|
---|
90 | <para>
|
---|
91 | For simplicity, we will abbreviate the location of the home
|
---|
92 | directory as <computeroutput>$HOME</computeroutput>. Using that
|
---|
93 | convention, the common folder for all virtual machines is
|
---|
94 | <computeroutput>$HOME/VirtualBox VMs</computeroutput>.
|
---|
95 | </para>
|
---|
96 |
|
---|
97 | <para>
|
---|
98 | As an example, when you create a virtual machine called "Example
|
---|
99 | VM", you will find that VirtualBox creates the following:
|
---|
100 | </para>
|
---|
101 |
|
---|
102 | <itemizedlist>
|
---|
103 |
|
---|
104 | <listitem>
|
---|
105 | <para>
|
---|
106 | A machine folder <computeroutput>$HOME/VirtualBox
|
---|
107 | VMs/Example VM/</computeroutput>
|
---|
108 | </para>
|
---|
109 | </listitem>
|
---|
110 |
|
---|
111 | <listitem>
|
---|
112 | <para>
|
---|
113 | In the machine folder, a settings file:
|
---|
114 | <computeroutput>Example VM.vbox</computeroutput>
|
---|
115 | </para>
|
---|
116 | </listitem>
|
---|
117 |
|
---|
118 | <listitem>
|
---|
119 | <para>
|
---|
120 | In the machine folder, a virtual disk image:
|
---|
121 | <computeroutput>Example VM.vdi</computeroutput>.
|
---|
122 | </para>
|
---|
123 | </listitem>
|
---|
124 |
|
---|
125 | </itemizedlist>
|
---|
126 |
|
---|
127 | <para>
|
---|
128 | This is the default layout if you use the Create New Virtual
|
---|
129 | Machine wizard described in <xref linkend="gui-createvm" />.
|
---|
130 | Once you start working with the VM, additional files are added.
|
---|
131 | Log files are in a subfolder called
|
---|
132 | <computeroutput>Logs</computeroutput>, and if you have taken
|
---|
133 | snapshots, they are in a
|
---|
134 | <computeroutput>Snapshots</computeroutput> subfolder. For each
|
---|
135 | VM, you can change the location of its snapshots folder in the
|
---|
136 | VM settings.
|
---|
137 | </para>
|
---|
138 |
|
---|
139 | <para>
|
---|
140 | You can change the default machine folder by selecting
|
---|
141 | <emphasis role="bold">Preferences</emphasis> from the File menu
|
---|
142 | in the VirtualBox main window. Then, in the displayed window,
|
---|
143 | click on the <emphasis role="bold">General</emphasis> tab.
|
---|
144 | Alternatively, use <computeroutput>VBoxManage setproperty
|
---|
145 | machinefolder</computeroutput>. See
|
---|
146 | <xref
|
---|
147 | linkend="vboxmanage-setproperty" />.
|
---|
148 | </para>
|
---|
149 |
|
---|
150 | </sect2>
|
---|
151 |
|
---|
152 | <sect2 id="vboxconfigdata-post-version-four">
|
---|
153 |
|
---|
154 | <title>Machines Created by VirtualBox Versions Before 4.0</title>
|
---|
155 |
|
---|
156 | <para>
|
---|
157 | If you have upgraded to VirtualBox 4.0 from an earlier version
|
---|
158 | of VirtualBox, you probably have settings files and disks in the
|
---|
159 | earlier file system layout.
|
---|
160 | </para>
|
---|
161 |
|
---|
162 | <para>
|
---|
163 | Before version 4.0, VirtualBox separated the machine settings
|
---|
164 | files from virtual disk images. The machine settings files had
|
---|
165 | an <computeroutput>.xml</computeroutput> file extension and
|
---|
166 | resided in a folder called "Machines" under the global
|
---|
167 | VirtualBox configuration directory. See
|
---|
168 | <xref linkend="vboxconfigdata-global"/>. On Linux, for example,
|
---|
169 | this was the hidden
|
---|
170 | <computeroutput>$HOME/.VirtualBox/Machines</computeroutput>
|
---|
171 | directory. The default hard disks folder was called "HardDisks"
|
---|
172 | and resided in the <computeroutput>.VirtualBox</computeroutput>
|
---|
173 | folder as well. Both locations could be changed by the user in
|
---|
174 | the global preferences. The concept of a default hard disk
|
---|
175 | folder has been abandoned with VirtualBox 4.0, since disk images
|
---|
176 | now reside in each machine's folder by default.
|
---|
177 | </para>
|
---|
178 |
|
---|
179 | <para>
|
---|
180 | The old layout had the following severe disadvantages:
|
---|
181 | </para>
|
---|
182 |
|
---|
183 | <itemizedlist>
|
---|
184 |
|
---|
185 | <listitem>
|
---|
186 | <para>
|
---|
187 | It was very difficult to move a virtual machine from one
|
---|
188 | host to another because the files involved did not reside in
|
---|
189 | the same folder. In addition, the virtual media of all
|
---|
190 | machines were registered with a global registry in the
|
---|
191 | central VirtualBox settings file,
|
---|
192 | <computeroutput>$HOME/.VirtualBox/VirtualBox.xml</computeroutput>.
|
---|
193 | </para>
|
---|
194 |
|
---|
195 | <para>
|
---|
196 | To move a machine to another host, it was therefore not
|
---|
197 | enough to move the XML settings file and the disk images,
|
---|
198 | which were in different locations, but the hard disk entries
|
---|
199 | from the global media registry XML had to be meticulously
|
---|
200 | copied as well. This was close to impossible if the machine
|
---|
201 | had snapshots and therefore differencing images.
|
---|
202 | </para>
|
---|
203 | </listitem>
|
---|
204 |
|
---|
205 | <listitem>
|
---|
206 | <para>
|
---|
207 | Storing virtual disk images, which can grow very large,
|
---|
208 | under the hidden
|
---|
209 | <computeroutput>.VirtualBox</computeroutput> directory, at
|
---|
210 | least on Linux and Solaris hosts, made many users wonder
|
---|
211 | where their disk space had gone.
|
---|
212 | </para>
|
---|
213 | </listitem>
|
---|
214 |
|
---|
215 | </itemizedlist>
|
---|
216 |
|
---|
217 | <para>
|
---|
218 | Whereas new VMs created with VirtualBox 4.0 or later will
|
---|
219 | conform to the new layout, for maximum compatibility, old VMs
|
---|
220 | are <emphasis>not</emphasis> converted to the new layout.
|
---|
221 | Otherwise machine settings would be irrevocably broken if a user
|
---|
222 | downgraded from 4.0 back to an older version of VirtualBox.
|
---|
223 | </para>
|
---|
224 |
|
---|
225 | </sect2>
|
---|
226 |
|
---|
227 | <sect2 id="vboxconfigdata-global">
|
---|
228 |
|
---|
229 | <title>Global Configuration Data</title>
|
---|
230 |
|
---|
231 | <para>
|
---|
232 | In addition to the files of the virtual machines, VirtualBox
|
---|
233 | maintains global configuration data. On Linux and Solaris as of
|
---|
234 | VirtualBox 4.3, this is in the hidden directory
|
---|
235 | <computeroutput>$HOME/.config/VirtualBox</computeroutput>,
|
---|
236 | although <computeroutput>$HOME/.VirtualBox</computeroutput> will
|
---|
237 | be used if it exists for compatibility with earlier versions. On
|
---|
238 | Windows, and on Linux and Solaris with VirtualBox 4.2 and
|
---|
239 | earlier, this is in
|
---|
240 | <computeroutput>$HOME/.VirtualBox</computeroutput>. On Mac OS X,
|
---|
241 | it resides in
|
---|
242 | <computeroutput>$HOME/Library/VirtualBox</computeroutput>.
|
---|
243 | </para>
|
---|
244 |
|
---|
245 | <para>
|
---|
246 | VirtualBox creates this configuration directory automatically if
|
---|
247 | necessary. Optionally, you can supply an alternate configuration
|
---|
248 | directory by setting the
|
---|
249 | <computeroutput><literal>VBOX_USER_HOME</literal></computeroutput>
|
---|
250 | environment variable, or additionally on Linux or Solaris by
|
---|
251 | using the standard
|
---|
252 | <computeroutput><literal>XDG_CONFIG_HOME</literal></computeroutput>
|
---|
253 | variable. Since the global
|
---|
254 | <computeroutput>VirtualBox.xml</computeroutput> settings file
|
---|
255 | points to all other configuration files, this allows for
|
---|
256 | switching between several VirtualBox configurations entirely.
|
---|
257 | </para>
|
---|
258 |
|
---|
259 | <para>
|
---|
260 | Most importantly, in this directory, VirtualBox stores its
|
---|
261 | global settings file, another XML file called
|
---|
262 | <computeroutput>VirtualBox.xml</computeroutput>. This includes
|
---|
263 | global configuration options and the list of registered virtual
|
---|
264 | machines with pointers to their XML settings files. Neither the
|
---|
265 | location of this file nor its directory has changed with
|
---|
266 | VirtualBox 4.0.
|
---|
267 | </para>
|
---|
268 |
|
---|
269 | <para>
|
---|
270 | Before VirtualBox 4.0, all virtual media (disk image files) were
|
---|
271 | also contained in a global registry in this settings file. For
|
---|
272 | compatibility, this media registry still exists if you upgrade
|
---|
273 | VirtualBox and there are media from machines which were created
|
---|
274 | with a version before 4.0. If you have no such machines, then
|
---|
275 | there will be no global media registry. With VirtualBox 4.0,
|
---|
276 | each machine XML file has its own media registry.
|
---|
277 | </para>
|
---|
278 |
|
---|
279 | <para>
|
---|
280 | Also before VirtualBox 4.0, the default "Machines" folder and
|
---|
281 | the default "HardDisks" folder resided under the VirtualBox
|
---|
282 | configuration directory, such as
|
---|
283 | <computeroutput>$HOME/.VirtualBox/Machines</computeroutput> on
|
---|
284 | Linux. If you are upgrading from a VirtualBox version before
|
---|
285 | 4.0, files in these directories are not automatically moved in
|
---|
286 | order not to break backwards compatibility.
|
---|
287 | </para>
|
---|
288 |
|
---|
289 | </sect2>
|
---|
290 |
|
---|
291 | <sect2 id="vboxconfigdata-summary-version-four">
|
---|
292 |
|
---|
293 | <title>Summary of 4.0 Configuration Changes</title>
|
---|
294 |
|
---|
295 | <para>
|
---|
296 | <xref linkend="table-version4-config-changes"/> gives a brief
|
---|
297 | overview of the configuration changes between legacy versions
|
---|
298 | and version 4.0 or later.
|
---|
299 | </para>
|
---|
300 |
|
---|
301 | <table id="table-version4-config-changes">
|
---|
302 | <title>Configuration Changes in Version 4.0 or Above</title>
|
---|
303 | <tgroup cols="3">
|
---|
304 | <thead>
|
---|
305 | <row>
|
---|
306 | <entry><emphasis role="bold">Setting</emphasis></entry>
|
---|
307 | <entry><emphasis role="bold">Before 4.0</emphasis></entry>
|
---|
308 | <entry><emphasis role="bold">4.0 or above</emphasis></entry>
|
---|
309 | </row>
|
---|
310 | </thead>
|
---|
311 | <tbody>
|
---|
312 | <row>
|
---|
313 | <entry>Default machines folder</entry>
|
---|
314 | <entry><computeroutput>$HOME/.VirtualBox/Machines</computeroutput></entry>
|
---|
315 | <entry><computeroutput>$HOME/VirtualBox VMs</computeroutput></entry>
|
---|
316 | </row>
|
---|
317 | <row>
|
---|
318 | <entry>Default disk image location</entry>
|
---|
319 | <entry><computeroutput>$HOME/.VirtualBox/HardDisks</computeroutput></entry>
|
---|
320 | <entry>In each machine's folder</entry>
|
---|
321 | </row>
|
---|
322 | <row>
|
---|
323 | <entry>Machine settings file extension</entry>
|
---|
324 | <entry><computeroutput>.xml</computeroutput></entry>
|
---|
325 | <entry><computeroutput>.vbox</computeroutput></entry>
|
---|
326 | </row>
|
---|
327 | <row>
|
---|
328 | <entry>Media registry</entry>
|
---|
329 | <entry>Global <computeroutput>VirtualBox.xml</computeroutput> file</entry>
|
---|
330 | <entry>Each machine settings file</entry>
|
---|
331 | </row>
|
---|
332 | <row>
|
---|
333 | <entry>Media registration</entry>
|
---|
334 | <entry>Explicit open/close required</entry>
|
---|
335 | <entry>Automatic on attach</entry>
|
---|
336 | </row>
|
---|
337 | </tbody>
|
---|
338 | </tgroup>
|
---|
339 | </table>
|
---|
340 |
|
---|
341 | </sect2>
|
---|
342 |
|
---|
343 | <sect2 id="vboxconfigdata-XML-files">
|
---|
344 |
|
---|
345 | <title>VirtualBox XML Files</title>
|
---|
346 |
|
---|
347 | <para>
|
---|
348 | VirtualBox uses XML for both the machine settings files and the
|
---|
349 | global configuration file,
|
---|
350 | <computeroutput>VirtualBox.xml</computeroutput>.
|
---|
351 | </para>
|
---|
352 |
|
---|
353 | <para>
|
---|
354 | All VirtualBox XML files are versioned. When a new settings file
|
---|
355 | is created, for example because a new virtual machine is
|
---|
356 | created, VirtualBox automatically uses the settings format of
|
---|
357 | the current VirtualBox version. These files may not be readable
|
---|
358 | if you downgrade to an earlier version of VirtualBox. However,
|
---|
359 | when VirtualBox encounters a settings file from an earlier
|
---|
360 | version, such as after upgrading VirtualBox, it attempts to
|
---|
361 | preserve the settings format as much as possible. It will only
|
---|
362 | silently upgrade the settings format if the current settings
|
---|
363 | cannot be expressed in the old format, for example because you
|
---|
364 | enabled a feature that was not present in an earlier version of
|
---|
365 | VirtualBox.
|
---|
366 |
|
---|
367 | <footnote>
|
---|
368 |
|
---|
369 | <para>
|
---|
370 | As an example, before VirtualBox 3.1, it was only possible
|
---|
371 | to enable or disable a single DVD drive in a virtual
|
---|
372 | machine. If it was enabled, then it would always be visible
|
---|
373 | as the secondary master of the IDE controller. With
|
---|
374 | VirtualBox 3.1, DVD drives can be attached to arbitrary
|
---|
375 | slots of arbitrary controllers, so they could be the
|
---|
376 | secondary slave of an IDE controller or in a SATA slot. If
|
---|
377 | you have a machine settings file from an earlier version and
|
---|
378 | upgrade VirtualBox to 3.1 and then move the DVD drive from
|
---|
379 | its default position, this cannot be expressed in the old
|
---|
380 | settings format; the XML machine file would get written in
|
---|
381 | the new format, and a backup file of the old format would be
|
---|
382 | kept.
|
---|
383 | </para>
|
---|
384 |
|
---|
385 | </footnote>
|
---|
386 |
|
---|
387 | In such cases, VirtualBox backs up the old settings file in the
|
---|
388 | virtual machine's configuration directory. If you need to go
|
---|
389 | back to the earlier version of VirtualBox, then you will need to
|
---|
390 | manually copy these backup files back.
|
---|
391 | </para>
|
---|
392 |
|
---|
393 | <para>
|
---|
394 | We intentionally do not document the specifications of the
|
---|
395 | VirtualBox XML files, as we must reserve the right to modify
|
---|
396 | them in the future. We therefore strongly suggest that you do
|
---|
397 | not edit these files manually. VirtualBox provides complete
|
---|
398 | access to its configuration data through its the
|
---|
399 | <computeroutput>VBoxManage</computeroutput> command line tool,
|
---|
400 | see <xref linkend="vboxmanage" /> and its API, see
|
---|
401 | <xref
|
---|
402 | linkend="VirtualBoxAPI" />.
|
---|
403 | </para>
|
---|
404 |
|
---|
405 | </sect2>
|
---|
406 |
|
---|
407 | </sect1>
|
---|
408 |
|
---|
409 | <sect1 id="technical-components">
|
---|
410 |
|
---|
411 | <title>VirtualBox Executables and Components</title>
|
---|
412 |
|
---|
413 | <para>
|
---|
414 | VirtualBox was designed to be modular and flexible. When the
|
---|
415 | VirtualBox graphical user interface (GUI) is opened and a VM is
|
---|
416 | started, at least the following three processes are running:
|
---|
417 | </para>
|
---|
418 |
|
---|
419 | <itemizedlist>
|
---|
420 |
|
---|
421 | <listitem>
|
---|
422 | <para>
|
---|
423 | <computeroutput>VBoxSVC</computeroutput>, the VirtualBox
|
---|
424 | service process which always runs in the background. This
|
---|
425 | process is started automatically by the first VirtualBox
|
---|
426 | client process and exits a short time after the last client
|
---|
427 | exits. The first VirtualBox service can be the GUI,
|
---|
428 | <computeroutput>VBoxManage</computeroutput>,
|
---|
429 | <computeroutput>VBoxHeadless</computeroutput>, the web service
|
---|
430 | amongst others. The service is responsible for bookkeeping,
|
---|
431 | maintaining the state of all VMs, and for providing
|
---|
432 | communication between VirtualBox components. This
|
---|
433 | communication is implemented via COM/XPCOM.
|
---|
434 | </para>
|
---|
435 |
|
---|
436 | <note>
|
---|
437 | <para>
|
---|
438 | When we refer to "clients" here, we mean the local clients
|
---|
439 | of a particular <computeroutput>VBoxSVC</computeroutput>
|
---|
440 | server process, not clients in a network. VirtualBox employs
|
---|
441 | its own client/server design to allow its processes to
|
---|
442 | cooperate, but all these processes run under the same user
|
---|
443 | account on the host operating system, and this is totally
|
---|
444 | transparent to the user.
|
---|
445 | </para>
|
---|
446 | </note>
|
---|
447 | </listitem>
|
---|
448 |
|
---|
449 | <listitem>
|
---|
450 | <para>
|
---|
451 | The GUI process, <computeroutput>VirtualBox</computeroutput>,
|
---|
452 | a client application based on the cross-platform Qt library.
|
---|
453 | When started without the
|
---|
454 | <computeroutput>--startvm</computeroutput> option, this
|
---|
455 | application acts as the VirtualBox manager, displaying the VMs
|
---|
456 | and their settings. It then communicates settings and state
|
---|
457 | changes to <computeroutput>VBoxSVC</computeroutput> and also
|
---|
458 | reflects changes effected through other means, such as
|
---|
459 | <computeroutput>VBoxManage</computeroutput>.
|
---|
460 | </para>
|
---|
461 | </listitem>
|
---|
462 |
|
---|
463 | <listitem>
|
---|
464 | <para>
|
---|
465 | If the <computeroutput>VirtualBox</computeroutput> client
|
---|
466 | application is started with the
|
---|
467 | <computeroutput>--startvm</computeroutput> argument, it loads
|
---|
468 | the VMM library which includes the actual hypervisor and then
|
---|
469 | runs a virtual machine and provides the input and output for
|
---|
470 | the guest.
|
---|
471 | </para>
|
---|
472 | </listitem>
|
---|
473 |
|
---|
474 | </itemizedlist>
|
---|
475 |
|
---|
476 | <para>
|
---|
477 | Any VirtualBox front-end, or client, will communicate with the
|
---|
478 | service process and can both control and reflect the current
|
---|
479 | state. For example, either the VM selector or the VM window or
|
---|
480 | VBoxManage can be used to pause the running VM, and other
|
---|
481 | components will always reflect the changed state.
|
---|
482 | </para>
|
---|
483 |
|
---|
484 | <para>
|
---|
485 | The VirtualBox GUI application is only one of several available
|
---|
486 | front ends, or clients. The complete list shipped with VirtualBox
|
---|
487 | is as follows:
|
---|
488 | </para>
|
---|
489 |
|
---|
490 | <itemizedlist>
|
---|
491 |
|
---|
492 | <listitem>
|
---|
493 | <para>
|
---|
494 | <computeroutput>VirtualBox</computeroutput>: The Qt front end
|
---|
495 | implementing the manager and running VMs.
|
---|
496 | </para>
|
---|
497 | </listitem>
|
---|
498 |
|
---|
499 | <listitem>
|
---|
500 | <para>
|
---|
501 | <computeroutput>VBoxManage</computeroutput>: A less
|
---|
502 | user-friendly but more powerful alternative. See
|
---|
503 | <xref
|
---|
504 | linkend="vboxmanage" />.
|
---|
505 | </para>
|
---|
506 | </listitem>
|
---|
507 |
|
---|
508 | <listitem>
|
---|
509 | <para>
|
---|
510 | <computeroutput>VBoxSDL</computeroutput>: A simple graphical
|
---|
511 | front end based on the SDL library. See
|
---|
512 | <xref
|
---|
513 | linkend="vboxsdl" />.
|
---|
514 | </para>
|
---|
515 | </listitem>
|
---|
516 |
|
---|
517 | <listitem>
|
---|
518 | <para>
|
---|
519 | <computeroutput>VBoxHeadless</computeroutput>: A VM front end
|
---|
520 | which does not directly provide any video output and
|
---|
521 | keyboard/mouse input, but allows redirection via VirtualBox
|
---|
522 | Remote Desktop Extension. See <xref linkend="vboxheadless" />.
|
---|
523 | </para>
|
---|
524 | </listitem>
|
---|
525 |
|
---|
526 | <listitem>
|
---|
527 | <para>
|
---|
528 | <computeroutput>vboxwebsrv</computeroutput>: The VirtualBox
|
---|
529 | web service process which allows for controlling a VirtualBox
|
---|
530 | host remotely. This is described in detail in the VirtualBox
|
---|
531 | Software Development Kit (SDK) reference. See
|
---|
532 | <xref
|
---|
533 | linkend="VirtualBoxAPI" />.
|
---|
534 | </para>
|
---|
535 | </listitem>
|
---|
536 |
|
---|
537 | <listitem>
|
---|
538 | <para>
|
---|
539 | The VirtualBox Python shell: A Python alternative to
|
---|
540 | VBoxManage. This is also described in the SDK reference.
|
---|
541 | </para>
|
---|
542 | </listitem>
|
---|
543 |
|
---|
544 | </itemizedlist>
|
---|
545 |
|
---|
546 | <para>
|
---|
547 | Internally, VirtualBox consists of many more or less separate
|
---|
548 | components. You may encounter these when analyzing VirtualBox
|
---|
549 | internal error messages or log files. These include the following:
|
---|
550 | </para>
|
---|
551 |
|
---|
552 | <itemizedlist>
|
---|
553 |
|
---|
554 | <listitem>
|
---|
555 | <para>
|
---|
556 | IPRT: A portable runtime library which abstracts file access,
|
---|
557 | threading, and string manipulation. Whenever VirtualBox
|
---|
558 | accesses host operating features, it does so through this
|
---|
559 | library for cross-platform portability.
|
---|
560 | </para>
|
---|
561 | </listitem>
|
---|
562 |
|
---|
563 | <listitem>
|
---|
564 | <para>
|
---|
565 | VMM (Virtual Machine Monitor): The heart of the hypervisor.
|
---|
566 | </para>
|
---|
567 | </listitem>
|
---|
568 |
|
---|
569 | <listitem>
|
---|
570 | <para>
|
---|
571 | EM (Execution Manager): Controls execution of guest code.
|
---|
572 | </para>
|
---|
573 | </listitem>
|
---|
574 |
|
---|
575 | <listitem>
|
---|
576 | <para>
|
---|
577 | REM (Recompiled Execution Monitor): Provides software
|
---|
578 | emulation of CPU instructions.
|
---|
579 | </para>
|
---|
580 | </listitem>
|
---|
581 |
|
---|
582 | <listitem>
|
---|
583 | <para>
|
---|
584 | TRPM (Trap Manager): Intercepts and processes guest traps and
|
---|
585 | exceptions.
|
---|
586 | </para>
|
---|
587 | </listitem>
|
---|
588 |
|
---|
589 | <listitem>
|
---|
590 | <para>
|
---|
591 | HM (Hardware Acceleration Manager): Provides support for VT-x
|
---|
592 | and AMD-V.
|
---|
593 | </para>
|
---|
594 | </listitem>
|
---|
595 |
|
---|
596 | <listitem>
|
---|
597 | <para>
|
---|
598 | GIM (Guest Interface Manager): Provides support for various
|
---|
599 | paravirtualization interfaces to the guest.
|
---|
600 | </para>
|
---|
601 | </listitem>
|
---|
602 |
|
---|
603 | <listitem>
|
---|
604 | <para>
|
---|
605 | PDM (Pluggable Device Manager): An abstract interface between
|
---|
606 | the VMM and emulated devices which separates device
|
---|
607 | implementations from VMM internals and makes it easy to add
|
---|
608 | new emulated devices. Through PDM, third-party developers can
|
---|
609 | add new virtual devices to VirtualBox without having to change
|
---|
610 | VirtualBox itself.
|
---|
611 | </para>
|
---|
612 | </listitem>
|
---|
613 |
|
---|
614 | <listitem>
|
---|
615 | <para>
|
---|
616 | PGM (Page Manager): A component that controls guest paging.
|
---|
617 | </para>
|
---|
618 | </listitem>
|
---|
619 |
|
---|
620 | <listitem>
|
---|
621 | <para>
|
---|
622 | PATM (Patch Manager): Patches guest code to improve and speed
|
---|
623 | up software virtualization.
|
---|
624 | </para>
|
---|
625 | </listitem>
|
---|
626 |
|
---|
627 | <listitem>
|
---|
628 | <para>
|
---|
629 | TM (Time Manager): Handles timers and all aspects of time
|
---|
630 | inside guests.
|
---|
631 | </para>
|
---|
632 | </listitem>
|
---|
633 |
|
---|
634 | <listitem>
|
---|
635 | <para>
|
---|
636 | CFGM (Configuration Manager): Provides a tree structure which
|
---|
637 | holds configuration settings for the VM and all emulated
|
---|
638 | devices.
|
---|
639 | </para>
|
---|
640 | </listitem>
|
---|
641 |
|
---|
642 | <listitem>
|
---|
643 | <para>
|
---|
644 | SSM (Saved State Manager): Saves and loads VM state.
|
---|
645 | </para>
|
---|
646 | </listitem>
|
---|
647 |
|
---|
648 | <listitem>
|
---|
649 | <para>
|
---|
650 | VUSB (Virtual USB): A USB layer which separates emulated USB
|
---|
651 | controllers from the controllers on the host and from USB
|
---|
652 | devices. This component also enables remote USB.
|
---|
653 | </para>
|
---|
654 | </listitem>
|
---|
655 |
|
---|
656 | <listitem>
|
---|
657 | <para>
|
---|
658 | DBGF (Debug Facility): A built-in VM debugger.
|
---|
659 | </para>
|
---|
660 | </listitem>
|
---|
661 |
|
---|
662 | <listitem>
|
---|
663 | <para>
|
---|
664 | VirtualBox emulates a number of devices to provide the
|
---|
665 | hardware environment that various guests need. Most of these
|
---|
666 | are standard devices found in many PC compatible machines and
|
---|
667 | widely supported by guest operating systems. For network and
|
---|
668 | storage devices in particular, there are several options for
|
---|
669 | the emulated devices to access the underlying hardware. These
|
---|
670 | devices are managed by PDM.
|
---|
671 | </para>
|
---|
672 | </listitem>
|
---|
673 |
|
---|
674 | <listitem>
|
---|
675 | <para>
|
---|
676 | Guest Additions for various guest operating systems. This is
|
---|
677 | code that is installed from within a virtual machine. See
|
---|
678 | <xref
|
---|
679 | linkend="guestadditions" />.
|
---|
680 | </para>
|
---|
681 | </listitem>
|
---|
682 |
|
---|
683 | <listitem>
|
---|
684 | <para>
|
---|
685 | The "Main" component is special. It ties all the above bits
|
---|
686 | together and is the only public API that VirtualBox provides.
|
---|
687 | All the client processes listed above use only this API and
|
---|
688 | never access the hypervisor components directly. As a result,
|
---|
689 | third-party applications that use the VirtualBox Main API can
|
---|
690 | rely on the fact that it is always well-tested and that all
|
---|
691 | capabilities of VirtualBox are fully exposed. It is this API
|
---|
692 | that is described in the VirtualBox SDK. See
|
---|
693 | <xref linkend="VirtualBoxAPI" />.
|
---|
694 | </para>
|
---|
695 | </listitem>
|
---|
696 |
|
---|
697 | </itemizedlist>
|
---|
698 |
|
---|
699 | </sect1>
|
---|
700 |
|
---|
701 | <sect1 id="hwvirt">
|
---|
702 |
|
---|
703 | <title>Hardware vs. Software Virtualization</title>
|
---|
704 |
|
---|
705 | <para>
|
---|
706 | VirtualBox allows software in the virtual machine to run directly
|
---|
707 | on the processor of the host, but an array of complex techniques
|
---|
708 | is employed to intercept operations that would interfere with your
|
---|
709 | host. Whenever the guest attempts to do something that could be
|
---|
710 | harmful to your computer and its data, VirtualBox steps in and
|
---|
711 | takes action. In particular, for lots of hardware that the guest
|
---|
712 | believes to be accessing, VirtualBox simulates a certain "virtual"
|
---|
713 | environment according to how you have configured a virtual
|
---|
714 | machine. For example, when the guest attempts to access a hard
|
---|
715 | disk, VirtualBox redirects these requests to whatever you have
|
---|
716 | configured to be the virtual machine's virtual hard disk. This is
|
---|
717 | normally an image file on your host.
|
---|
718 | </para>
|
---|
719 |
|
---|
720 | <para>
|
---|
721 | Unfortunately, the x86 platform was never designed to be
|
---|
722 | virtualized. Detecting situations in which VirtualBox needs to
|
---|
723 | take control over the guest code that is executing, as described
|
---|
724 | above, is difficult. There are two ways in which to achieve this:
|
---|
725 | </para>
|
---|
726 |
|
---|
727 | <itemizedlist>
|
---|
728 |
|
---|
729 | <listitem>
|
---|
730 | <para>
|
---|
731 | Since 2006, Intel and AMD processors have had support for
|
---|
732 | so-called <emphasis>hardware virtualization</emphasis>. This
|
---|
733 | means that these processors can help VirtualBox to intercept
|
---|
734 | potentially dangerous operations that a guest operating system
|
---|
735 | may be attempting and also makes it easier to present virtual
|
---|
736 | hardware to a virtual machine.
|
---|
737 | </para>
|
---|
738 |
|
---|
739 | <para>
|
---|
740 | These hardware features differ between Intel and AMD
|
---|
741 | processors. Intel named its technology >VT-x. AMD calls theirs
|
---|
742 | AMD-V. The Intel and AMD support for virtualization is very
|
---|
743 | different in detail, but not very different in principle.
|
---|
744 | </para>
|
---|
745 |
|
---|
746 | <note>
|
---|
747 | <para>
|
---|
748 | On many systems, the hardware virtualization features first
|
---|
749 | need to be enabled in the BIOS before VirtualBox can use
|
---|
750 | them.
|
---|
751 | </para>
|
---|
752 | </note>
|
---|
753 | </listitem>
|
---|
754 |
|
---|
755 | <listitem>
|
---|
756 | <para>
|
---|
757 | As opposed to other virtualization software, for many usage
|
---|
758 | scenarios, VirtualBox does not <emphasis>require</emphasis>
|
---|
759 | hardware virtualization features to be present. Through
|
---|
760 | sophisticated techniques, VirtualBox virtualizes many guest
|
---|
761 | operating systems entirely in <emphasis>software</emphasis>.
|
---|
762 | This means that you can run virtual machines even on older
|
---|
763 | processors which do not support hardware virtualization.
|
---|
764 | </para>
|
---|
765 | </listitem>
|
---|
766 |
|
---|
767 | </itemizedlist>
|
---|
768 |
|
---|
769 | <para>
|
---|
770 | Even though VirtualBox does not always require hardware
|
---|
771 | virtualization, enabling it is <emphasis>required</emphasis> in
|
---|
772 | the following scenarios:
|
---|
773 | </para>
|
---|
774 |
|
---|
775 | <itemizedlist>
|
---|
776 |
|
---|
777 | <listitem>
|
---|
778 | <para>
|
---|
779 | Certain rare guest operating systems like OS/2 make use of
|
---|
780 | very esoteric processor instructions that are not supported
|
---|
781 | with our software virtualization. For virtual machines that
|
---|
782 | are configured to contain such an operating system, hardware
|
---|
783 | virtualization is enabled automatically.
|
---|
784 | </para>
|
---|
785 | </listitem>
|
---|
786 |
|
---|
787 | <listitem>
|
---|
788 | <para>
|
---|
789 | VirtualBox's 64-bit guest support (added with version 2.0) and
|
---|
790 | multiprocessing (SMP, added with version 3.0) both require
|
---|
791 | hardware virtualization to be enabled. This is not much of a
|
---|
792 | limitation since the vast majority of today's 64-bit and
|
---|
793 | multicore CPUs ship with hardware virtualization anyway. The
|
---|
794 | exceptions to this rule are older Intel Celeron and AMD
|
---|
795 | Opteron CPUs, for example.
|
---|
796 | </para>
|
---|
797 | </listitem>
|
---|
798 |
|
---|
799 | </itemizedlist>
|
---|
800 |
|
---|
801 | <warning>
|
---|
802 | <para>
|
---|
803 | Do not run other hypervisors, either open source or commercial
|
---|
804 | virtualization products, together with VirtualBox. While several
|
---|
805 | hypervisors can normally be <emphasis>installed</emphasis> in
|
---|
806 | parallel, do not attempt to <emphasis>run</emphasis> several
|
---|
807 | virtual machines from competing hypervisors at the same time.
|
---|
808 | VirtualBox cannot track what another hypervisor is currently
|
---|
809 | attempting to do on the same host, and especially if several
|
---|
810 | products attempt to use hardware virtualization features such as
|
---|
811 | VT-x, this can crash the entire host. Also, within VirtualBox,
|
---|
812 | you can mix software and hardware virtualization when running
|
---|
813 | multiple VMs. In certain cases a small performance penalty will
|
---|
814 | be unavoidable when mixing VT-x and software virtualization VMs.
|
---|
815 | We recommend not mixing virtualization modes if maximum
|
---|
816 | performance and low overhead are essential. This does
|
---|
817 | <emphasis>not</emphasis> apply to AMD-V.
|
---|
818 | </para>
|
---|
819 | </warning>
|
---|
820 |
|
---|
821 | </sect1>
|
---|
822 |
|
---|
823 | <sect1 id="gimproviders">
|
---|
824 |
|
---|
825 | <title>Paravirtualization Providers</title>
|
---|
826 |
|
---|
827 | <para>
|
---|
828 | VirtualBox allows exposing a paravirtualization interface to
|
---|
829 | facilitate accurate and efficient execution of software within a
|
---|
830 | virtual machine. These interfaces require the guest operating
|
---|
831 | system to recognize their presence and make use of them in order
|
---|
832 | to leverage the benefits of communicating with the VirtualBox
|
---|
833 | hypervisor.
|
---|
834 | </para>
|
---|
835 |
|
---|
836 | <para>
|
---|
837 | Most modern mainstream guest operating systems, including Windows
|
---|
838 | and Linux, ship with support for one or more paravirtualization
|
---|
839 | interfaces. Hence, there is typically no need to install
|
---|
840 | additional software in the guest to take advantage of this
|
---|
841 | feature.
|
---|
842 | </para>
|
---|
843 |
|
---|
844 | <para>
|
---|
845 | Exposing a paravirtualization provider to the guest operating
|
---|
846 | system does not rely on the choice of host platforms. For example,
|
---|
847 | the <emphasis>Hyper-V</emphasis> paravirtualization provider can
|
---|
848 | be used for VMs to run on any host platform supported by
|
---|
849 | VirtualBox and not just Windows.
|
---|
850 | </para>
|
---|
851 |
|
---|
852 | <para>
|
---|
853 | VirtualBox provides the following interfaces:
|
---|
854 | </para>
|
---|
855 |
|
---|
856 | <itemizedlist>
|
---|
857 |
|
---|
858 | <listitem>
|
---|
859 | <para>
|
---|
860 | <emphasis role="bold">Minimal</emphasis>: Announces the
|
---|
861 | presence of a virtualized environment. Additionally, reports
|
---|
862 | the TSC and APIC frequency to the guest operating system. This
|
---|
863 | provider is mandatory for running any Mac OS X guests.
|
---|
864 | </para>
|
---|
865 | </listitem>
|
---|
866 |
|
---|
867 | <listitem>
|
---|
868 | <para>
|
---|
869 | <emphasis role="bold">KVM</emphasis>: Presents a Linux KVM
|
---|
870 | hypervisor interface which is recognized by Linux kernels
|
---|
871 | starting with version 2.6.25. VirtualBox's implementation
|
---|
872 | currently supports paravirtualized clocks and SMP spinlocks.
|
---|
873 | This provider is recommended for Linux guests.
|
---|
874 | </para>
|
---|
875 | </listitem>
|
---|
876 |
|
---|
877 | <listitem>
|
---|
878 | <para>
|
---|
879 | <emphasis role="bold">Hyper-V</emphasis>: Presents a Microsoft
|
---|
880 | Hyper-V hypervisor interface which is recognized by Windows 7
|
---|
881 | and newer operating systems. VirtualBox's implementation
|
---|
882 | currently supports paravirtualized clocks, APIC frequency
|
---|
883 | reporting, guest debugging, guest crash reporting and relaxed
|
---|
884 | timer checks. This provider is recommended for Windows guests.
|
---|
885 | </para>
|
---|
886 | </listitem>
|
---|
887 |
|
---|
888 | </itemizedlist>
|
---|
889 |
|
---|
890 | </sect1>
|
---|
891 |
|
---|
892 | <sect1 id="swvirt-details">
|
---|
893 |
|
---|
894 | <title>Details About Software Virtualization</title>
|
---|
895 |
|
---|
896 | <para>
|
---|
897 | Implementing virtualization on x86 CPUs with no hardware
|
---|
898 | virtualization support is an extraordinarily complex task because
|
---|
899 | the CPU architecture was not designed to be virtualized. The
|
---|
900 | problems can usually be solved, but at the cost of reduced
|
---|
901 | performance. Thus, there is a constant clash between
|
---|
902 | virtualization performance and accuracy.
|
---|
903 | </para>
|
---|
904 |
|
---|
905 | <para>
|
---|
906 | The x86 instruction set was originally designed in the 1970s and
|
---|
907 | underwent significant changes with the addition of protected mode
|
---|
908 | in the 1980s with the 286 CPU architecture and then again with the
|
---|
909 | Intel 386 and its 32-bit architecture. Whereas the 386 did have
|
---|
910 | limited virtualization support for real mode operation (V86 mode,
|
---|
911 | as used by the "DOS Box" of Windows 3.x and OS/2 2.x), no support
|
---|
912 | was provided for virtualizing the entire architecture.
|
---|
913 | </para>
|
---|
914 |
|
---|
915 | <para>
|
---|
916 | In theory, software virtualization is not overly complex. There
|
---|
917 | are four privilege levels, called <emphasis>rings</emphasis>,
|
---|
918 | provided by the hardware. Typically only two rings are used: ring
|
---|
919 | 0 for kernel mode and ring 3 for user mode. Additionally, one
|
---|
920 | needs to differentiate between <emphasis>host context</emphasis>
|
---|
921 | and <emphasis>guest context</emphasis>.
|
---|
922 | </para>
|
---|
923 |
|
---|
924 | <para>
|
---|
925 | In host context, everything is as if no hypervisor was active.
|
---|
926 | This might be the active mode if another application on your host
|
---|
927 | has been scheduled CPU time. In that case, there is a host ring 3
|
---|
928 | mode and a host ring 0 mode. The hypervisor is not involved.
|
---|
929 | </para>
|
---|
930 |
|
---|
931 | <para>
|
---|
932 | In guest context, however, a virtual machine is active. So long as
|
---|
933 | the guest code is running in ring 3, this is not much of a problem
|
---|
934 | since a hypervisor can set up the page tables properly and run
|
---|
935 | that code natively on the processor. The problems mostly lie in
|
---|
936 | how to intercept what the guest's kernel does.
|
---|
937 | </para>
|
---|
938 |
|
---|
939 | <para>
|
---|
940 | There are several possible solutions to these problems. One
|
---|
941 | approach is full software emulation, usually involving
|
---|
942 | recompilation. That is, all code to be run by the guest is
|
---|
943 | analyzed, transformed into a form which will not allow the guest
|
---|
944 | to either modify or see the true state of the CPU, and only then
|
---|
945 | executed. This process is obviously highly complex and costly in
|
---|
946 | terms of performance. VirtualBox contains a recompiler based on
|
---|
947 | QEMU which can be used for pure software emulation, but the
|
---|
948 | recompiler is only activated in special situations, described
|
---|
949 | below.
|
---|
950 | </para>
|
---|
951 |
|
---|
952 | <para>
|
---|
953 | Another possible solution is paravirtualization, in which only
|
---|
954 | specially modified guest OSes are allowed to run. This way, most
|
---|
955 | of the hardware access is abstracted and any functions which would
|
---|
956 | normally access the hardware or privileged CPU state are passed on
|
---|
957 | to the hypervisor instead. Paravirtualization can achieve good
|
---|
958 | functionality and performance on standard x86 CPUs, but it can
|
---|
959 | only work if the guest OS can actually be modified, which is
|
---|
960 | obviously not always the case.
|
---|
961 | </para>
|
---|
962 |
|
---|
963 | <para>
|
---|
964 | VirtualBox chooses a different approach. When starting a virtual
|
---|
965 | machine, through its ring-0 support kernel driver, VirtualBox has
|
---|
966 | set up the host system so that it can run most of the guest code
|
---|
967 | natively, but it has inserted itself at the "bottom" of the
|
---|
968 | picture. It can then assume control when needed. If a privileged
|
---|
969 | instruction is executed, the guest traps, in particular because an
|
---|
970 | I/O register was accessed and a device needs to be virtualized, or
|
---|
971 | external interrupts occur. VirtualBox may then handle this and
|
---|
972 | either route a request to a virtual device or possibly delegate
|
---|
973 | handling such things to the guest or host OS. In guest context,
|
---|
974 | VirtualBox can therefore be in one of three states:
|
---|
975 | </para>
|
---|
976 |
|
---|
977 | <itemizedlist>
|
---|
978 |
|
---|
979 | <listitem>
|
---|
980 | <para>
|
---|
981 | Guest ring 3 code is run unmodified, at full speed, as much as
|
---|
982 | possible. The number of faults will generally be low, unless
|
---|
983 | the guest allows port I/O from ring 3. This is something we
|
---|
984 | cannot do as we do not want the guest to be able to access
|
---|
985 | real ports. This is also referred to as <emphasis>raw
|
---|
986 | mode</emphasis>, as the guest ring-3 code runs unmodified.
|
---|
987 | </para>
|
---|
988 | </listitem>
|
---|
989 |
|
---|
990 | <listitem>
|
---|
991 | <para>
|
---|
992 | For guest code in ring 0, VirtualBox employs a clever trick.
|
---|
993 | It actually reconfigures the guest so that its ring-0 code is
|
---|
994 | run in ring 1 instead, which is normally not used in x86
|
---|
995 | operating systems). As a result, when guest ring-0 code,
|
---|
996 | actually running n ring 1, such as a guest device driver
|
---|
997 | attempts to write to an I/O register or execute a privileged
|
---|
998 | instruction, the VirtualBox hypervisor in the "real" ring 0
|
---|
999 | can take over.
|
---|
1000 | </para>
|
---|
1001 | </listitem>
|
---|
1002 |
|
---|
1003 | <listitem>
|
---|
1004 | <para>
|
---|
1005 | The hypervisor (VMM) can be active. Every time a fault occurs,
|
---|
1006 | VirtualBox looks at the offending instruction and can relegate
|
---|
1007 | it to a virtual device or the host OS or the guest OS or run
|
---|
1008 | it in the recompiler.
|
---|
1009 | </para>
|
---|
1010 |
|
---|
1011 | <para>
|
---|
1012 | In particular, the recompiler is used when guest code disables
|
---|
1013 | interrupts and VirtualBox cannot figure out when they will be
|
---|
1014 | switched back on. In these situations, VirtualBox actually
|
---|
1015 | analyzes the guest code using its own disassembler. Also,
|
---|
1016 | certain privileged instructions such as LIDT need to be
|
---|
1017 | handled specially. Finally, any real-mode or protected-mode
|
---|
1018 | code, such as BIOS code, a DOS guest, or any operating system
|
---|
1019 | startup, is run in the recompiler entirely.
|
---|
1020 | </para>
|
---|
1021 | </listitem>
|
---|
1022 |
|
---|
1023 | </itemizedlist>
|
---|
1024 |
|
---|
1025 | <para>
|
---|
1026 | Unfortunately this only works to a degree. Among others, the
|
---|
1027 | following situations require special handling:
|
---|
1028 | </para>
|
---|
1029 |
|
---|
1030 | <itemizedlist>
|
---|
1031 |
|
---|
1032 | <listitem>
|
---|
1033 | <para>
|
---|
1034 | Running ring 0 code in ring 1 causes a lot of additional
|
---|
1035 | instruction faults, as ring 1 is not allowed to execute any
|
---|
1036 | privileged instructions, of which guest's ring-0 contains
|
---|
1037 | plenty. With each of these faults, the VMM must step in and
|
---|
1038 | emulate the code to achieve the desired behavior. While this
|
---|
1039 | works, emulating thousands of these faults is very expensive
|
---|
1040 | and severely hurts the performance of the virtualized guest.
|
---|
1041 | </para>
|
---|
1042 | </listitem>
|
---|
1043 |
|
---|
1044 | <listitem>
|
---|
1045 | <para>
|
---|
1046 | There are certain flaws in the implementation of ring 1 in the
|
---|
1047 | x86 architecture that were never fixed. Certain instructions
|
---|
1048 | that <emphasis>should</emphasis> trap in ring 1 do not. This
|
---|
1049 | affects, for example, the LGDT/SGDT, LIDT/SIDT, or POPF/PUSHF
|
---|
1050 | instruction pairs. Whereas the "load" operation is privileged
|
---|
1051 | and can therefore be trapped, the "store" instruction always
|
---|
1052 | succeed. If the guest is allowed to execute these, it will see
|
---|
1053 | the true state of the CPU, not the virtualized state. The
|
---|
1054 | CPUID instruction also has the same problem.
|
---|
1055 | </para>
|
---|
1056 | </listitem>
|
---|
1057 |
|
---|
1058 | <listitem>
|
---|
1059 | <para>
|
---|
1060 | A hypervisor typically needs to reserve some portion of the
|
---|
1061 | guest's address space, both linear address space and
|
---|
1062 | selectors, for its own use. This is not entirely transparent
|
---|
1063 | to the guest OS and may cause clashes.
|
---|
1064 | </para>
|
---|
1065 | </listitem>
|
---|
1066 |
|
---|
1067 | <listitem>
|
---|
1068 | <para>
|
---|
1069 | The SYSENTER instruction, used for system calls, executed by
|
---|
1070 | an application running in a guest OS always transitions to
|
---|
1071 | ring 0. But that is where the hypervisor runs, not the guest
|
---|
1072 | OS. In this case, the hypervisor must trap and emulate the
|
---|
1073 | instruction even when it is not desirable.
|
---|
1074 | </para>
|
---|
1075 | </listitem>
|
---|
1076 |
|
---|
1077 | <listitem>
|
---|
1078 | <para>
|
---|
1079 | The CPU segment registers contain a "hidden" descriptor cache
|
---|
1080 | which is not software-accessible. The hypervisor cannot read,
|
---|
1081 | save, or restore this state, but the guest OS may use it.
|
---|
1082 | </para>
|
---|
1083 | </listitem>
|
---|
1084 |
|
---|
1085 | <listitem>
|
---|
1086 | <para>
|
---|
1087 | Some resources must, and can, be trapped by the hypervisor,
|
---|
1088 | but the access is so frequent that this creates a significant
|
---|
1089 | performance overhead. An example is the TPR (Task Priority)
|
---|
1090 | register in 32-bit mode. Accesses to this register must be
|
---|
1091 | trapped by the hypervisor. But certain guest operating
|
---|
1092 | systems, notably Windows and Solaris, write this register very
|
---|
1093 | often, which adversely affects virtualization performance.
|
---|
1094 | </para>
|
---|
1095 | </listitem>
|
---|
1096 |
|
---|
1097 | </itemizedlist>
|
---|
1098 |
|
---|
1099 | <para>
|
---|
1100 | To fix these performance and security issues, VirtualBox contains
|
---|
1101 | a Code Scanning and Analysis Manager (CSAM), which disassembles
|
---|
1102 | guest code, and the Patch Manager (PATM), which can replace it at
|
---|
1103 | runtime.
|
---|
1104 | </para>
|
---|
1105 |
|
---|
1106 | <para>
|
---|
1107 | Before executing ring 0 code, CSAM scans it recursively to
|
---|
1108 | discover problematic instructions. PATM then performs
|
---|
1109 | <emphasis>in-situ </emphasis>patching. It replaces the instruction
|
---|
1110 | with a jump to hypervisor memory where an integrated code
|
---|
1111 | generator has placed a more suitable implementation. In reality,
|
---|
1112 | this is a very complex task as there are lots of odd situations to
|
---|
1113 | be discovered and handled correctly. So, with its current
|
---|
1114 | complexity, one could argue that PATM is an advanced
|
---|
1115 | <emphasis>in-situ</emphasis> recompiler.
|
---|
1116 | </para>
|
---|
1117 |
|
---|
1118 | <para>
|
---|
1119 | In addition, every time a fault occurs, VirtualBox analyzes the
|
---|
1120 | offending code to determine if it is possible to patch it in order
|
---|
1121 | to prevent it from causing more faults in the future. This
|
---|
1122 | approach works well in practice and dramatically improves software
|
---|
1123 | virtualization performance.
|
---|
1124 | </para>
|
---|
1125 |
|
---|
1126 | </sect1>
|
---|
1127 |
|
---|
1128 | <sect1 id="hwvirt-details">
|
---|
1129 |
|
---|
1130 | <title>Details About Hardware Virtualization</title>
|
---|
1131 |
|
---|
1132 | <para>
|
---|
1133 | With Intel VT-x, there are two distinct modes of CPU operation:
|
---|
1134 | VMX root mode and non-root mode.
|
---|
1135 | </para>
|
---|
1136 |
|
---|
1137 | <itemizedlist>
|
---|
1138 |
|
---|
1139 | <listitem>
|
---|
1140 | <para>
|
---|
1141 | In root mode, the CPU operates much like older generations of
|
---|
1142 | processors without VT-x support. There are four privilege
|
---|
1143 | levels, called rings, and the same instruction set is
|
---|
1144 | supported, with the addition of several virtualization
|
---|
1145 | specific instruction. Root mode is what a host operating
|
---|
1146 | system without virtualization uses, and it is also used by a
|
---|
1147 | hypervisor when virtualization is active.
|
---|
1148 | </para>
|
---|
1149 | </listitem>
|
---|
1150 |
|
---|
1151 | <listitem>
|
---|
1152 | <para>
|
---|
1153 | In non-root mode, CPU operation is significantly different.
|
---|
1154 | There are still four privilege rings and the same instruction
|
---|
1155 | set, but a new structure called VMCS (Virtual Machine Control
|
---|
1156 | Structure) now controls the CPU operation and determines how
|
---|
1157 | certain instructions behave. Non-root mode is where guest
|
---|
1158 | systems run.
|
---|
1159 | </para>
|
---|
1160 | </listitem>
|
---|
1161 |
|
---|
1162 | </itemizedlist>
|
---|
1163 |
|
---|
1164 | <para>
|
---|
1165 | Switching from root mode to non-root mode is called "VM entry",
|
---|
1166 | the switch back is "VM exit". The VMCS includes a guest and host
|
---|
1167 | state area which is saved/restored at VM entry and exit. Most
|
---|
1168 | importantly, the VMCS controls which guest operations will cause
|
---|
1169 | VM exits.
|
---|
1170 | </para>
|
---|
1171 |
|
---|
1172 | <para>
|
---|
1173 | The VMCS provides fairly fine-grained control over what the guests
|
---|
1174 | can and cannot do. For example, a hypervisor can allow a guest to
|
---|
1175 | write certain bits in shadowed control registers, but not others.
|
---|
1176 | This enables efficient virtualization in cases where guests can be
|
---|
1177 | allowed to write control bits without disrupting the hypervisor,
|
---|
1178 | while preventing them from altering control bits over which the
|
---|
1179 | hypervisor needs to retain full control. The VMCS also provides
|
---|
1180 | control over interrupt delivery and exceptions.
|
---|
1181 | </para>
|
---|
1182 |
|
---|
1183 | <para>
|
---|
1184 | Whenever an instruction or event causes a VM exit, the VMCS
|
---|
1185 | contains information about the exit reason, often with
|
---|
1186 | accompanying detail. For example, if a write to the CR0 register
|
---|
1187 | causes an exit, the offending instruction is recorded, along with
|
---|
1188 | the fact that a write access to a control register caused the
|
---|
1189 | exit, and information about source and destination register. Thus
|
---|
1190 | the hypervisor can efficiently handle the condition without
|
---|
1191 | needing advanced techniques such as CSAM and PATM described above.
|
---|
1192 | </para>
|
---|
1193 |
|
---|
1194 | <para>
|
---|
1195 | VT-x inherently avoids several of the problems which software
|
---|
1196 | virtualization faces. The guest has its own completely separate
|
---|
1197 | address space not shared with the hypervisor, which eliminates
|
---|
1198 | potential clashes. Additionally, guest OS kernel code runs at
|
---|
1199 | privilege ring 0 in VMX non-root mode, obviating the problems by
|
---|
1200 | running ring 0 code at less privileged levels. For example the
|
---|
1201 | SYSENTER instruction can transition to ring 0 without causing
|
---|
1202 | problems. Naturally, even at ring 0 in VMX non-root mode, any I/O
|
---|
1203 | access by guest code still causes a VM exit, allowing for device
|
---|
1204 | emulation.
|
---|
1205 | </para>
|
---|
1206 |
|
---|
1207 | <para>
|
---|
1208 | The biggest difference between VT-x and AMD-V is that AMD-V
|
---|
1209 | provides a more complete virtualization environment. VT-x requires
|
---|
1210 | the VMX non-root code to run with paging enabled, which precludes
|
---|
1211 | hardware virtualization of real-mode code and non-paged
|
---|
1212 | protected-mode software. This typically only includes firmware and
|
---|
1213 | OS loaders, but nevertheless complicates VT-x hypervisor
|
---|
1214 | implementation. AMD-V does not have this restriction.
|
---|
1215 | </para>
|
---|
1216 |
|
---|
1217 | <para>
|
---|
1218 | Of course hardware virtualization is not perfect. Compared to
|
---|
1219 | software virtualization, the overhead of VM exits is relatively
|
---|
1220 | high. This causes problems for devices whose emulation requires
|
---|
1221 | high number of traps. One example is the VGA device in 16-color
|
---|
1222 | modes, where not only every I/O port access but also every access
|
---|
1223 | to the framebuffer memory must be trapped.
|
---|
1224 | </para>
|
---|
1225 |
|
---|
1226 | </sect1>
|
---|
1227 |
|
---|
1228 | <sect1 id="nestedpaging">
|
---|
1229 |
|
---|
1230 | <title>Nested Paging and VPIDs</title>
|
---|
1231 |
|
---|
1232 | <para>
|
---|
1233 | In addition to normal hardware virtualization, your processor may
|
---|
1234 | also support the following additional sophisticated techniques:
|
---|
1235 |
|
---|
1236 | <footnote>
|
---|
1237 |
|
---|
1238 | <para>
|
---|
1239 | VirtualBox 2.0 added support for AMD's nested paging; support
|
---|
1240 | for Intel's EPT and VPIDs was added with version 2.1.
|
---|
1241 | </para>
|
---|
1242 |
|
---|
1243 | </footnote>
|
---|
1244 | </para>
|
---|
1245 |
|
---|
1246 | <itemizedlist>
|
---|
1247 |
|
---|
1248 | <listitem>
|
---|
1249 | <para>
|
---|
1250 | A newer feature called <emphasis>nested paging</emphasis>
|
---|
1251 | implements some memory management in hardware, which can
|
---|
1252 | greatly accelerate hardware virtualization since these tasks
|
---|
1253 | no longer need to be performed by the virtualization software.
|
---|
1254 | </para>
|
---|
1255 |
|
---|
1256 | <para>
|
---|
1257 | With nested paging, the hardware provides another level of
|
---|
1258 | indirection when translating linear to physical addresses.
|
---|
1259 | Page tables function as before, but linear addresses are now
|
---|
1260 | translated to "guest physical" addresses first and not
|
---|
1261 | physical addresses directly. A new set of paging registers now
|
---|
1262 | exists under the traditional paging mechanism and translates
|
---|
1263 | from guest physical addresses to host physical addresses,
|
---|
1264 | which are used to access memory.
|
---|
1265 | </para>
|
---|
1266 |
|
---|
1267 | <para>
|
---|
1268 | Nested paging eliminates the overhead caused by VM exits and
|
---|
1269 | page table accesses. In essence, with nested page tables the
|
---|
1270 | guest can handle paging without intervention from the
|
---|
1271 | hypervisor. Nested paging thus significantly improves
|
---|
1272 | virtualization performance.
|
---|
1273 | </para>
|
---|
1274 |
|
---|
1275 | <para>
|
---|
1276 | On AMD processors, nested paging has been available starting
|
---|
1277 | with the Barcelona (K10) architecture. They now call it "rapid
|
---|
1278 | virtualization indexing" (RVI). Intel added support for nested
|
---|
1279 | paging, which they call extended page tables (EPT), with their
|
---|
1280 | Core i7 (Nehalem) processors.
|
---|
1281 | </para>
|
---|
1282 |
|
---|
1283 | <para>
|
---|
1284 | If nested paging is enabled, the VirtualBox hypervisor can
|
---|
1285 | also use <emphasis role="bold">large pages</emphasis> to
|
---|
1286 | reduce TLB usage and overhead. This can yield a performance
|
---|
1287 | improvement of up to 5%. To enable this feature for a VM, you
|
---|
1288 | need to use the <computeroutput>VBoxManage modifyvm
|
---|
1289 | </computeroutput><computeroutput>--largepages</computeroutput>
|
---|
1290 | command. See <xref linkend="vboxmanage-modifyvm" />.
|
---|
1291 | </para>
|
---|
1292 | </listitem>
|
---|
1293 |
|
---|
1294 | <listitem>
|
---|
1295 | <para>
|
---|
1296 | On Intel CPUs, another hardware feature called Virtual
|
---|
1297 | Processor Identifiers" (VPIDs) can greatly accelerate context
|
---|
1298 | switching by reducing the need for expensive flushing of the
|
---|
1299 | processor's Translation Lookaside Buffers (TLBs).
|
---|
1300 | </para>
|
---|
1301 |
|
---|
1302 | <para>
|
---|
1303 | To enable these features for a VM, you need to use the
|
---|
1304 | <computeroutput>VBoxManage modifyvm --vtxvpid</computeroutput>
|
---|
1305 | and <computeroutput>--largepages</computeroutput> commands.
|
---|
1306 | See <xref
|
---|
1307 | linkend="vboxmanage-modifyvm" />.
|
---|
1308 | </para>
|
---|
1309 | </listitem>
|
---|
1310 |
|
---|
1311 | </itemizedlist>
|
---|
1312 |
|
---|
1313 | </sect1>
|
---|
1314 |
|
---|
1315 | </chapter>
|
---|