aboutsummaryrefslogtreecommitdiff
path: root/en_US.ISO8859-1/books/handbook/virtualization/chapter.xml
blob: 1ed9bd4bd74921a92dbdcc081f13497b22f2407a (plain) (blame)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
<?xml version="1.0" encoding="iso-8859-1"?>
<!--
     The FreeBSD Documentation Project

     $FreeBSD$
-->
<chapter xmlns="http://docbook.org/ns/docbook"
  xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0"
  xml:id="virtualization">

  <info>
    <title>Virtualization</title>

    <authorgroup>
      <author>
	<personname>
	  <firstname>Murray</firstname>
	  <surname>Stokely</surname>
	</personname>
	<contrib>Contributed by </contrib>
      </author>
    </authorgroup>

    <authorgroup>
      <author>
	<personname>
	  <firstname>Allan</firstname>
	  <surname>Jude</surname>
	</personname>
	<contrib>bhyve section by </contrib>
      </author>
    </authorgroup>

    <authorgroup>
      <author>
	<personname>
	  <firstname>Benedict</firstname>
	  <surname>Reuschling</surname>
	</personname>
	<contrib>Xen section by </contrib>
      </author>
    </authorgroup>
  </info>

  <sect1 xml:id="virtualization-synopsis">
    <title>Synopsis</title>

    <para>Virtualization software allows multiple operating systems to
      run simultaneously on the same computer.  Such software systems
      for <acronym>PC</acronym>s often involve a host operating system
      which runs the virtualization software and supports any number
      of guest operating systems.</para>

    <para>After reading this chapter, you will know:</para>

    <itemizedlist>
      <listitem>
	<para>The difference between a host operating system and a
	  guest operating system.</para>
      </listitem>

      <listitem>
	<para>How to install &os; on an &intel;-based &apple;
	  &mac; computer.</para>
      </listitem>

      <listitem>
	<para>How to install &os; on &microsoft.windows; with
	  <application>Virtual PC</application>.</para>
      </listitem>

      <listitem>
	<para>How to install &os; as a guest in
	  <application>bhyve</application>.</para>
      </listitem>

      <listitem>
	<para>How to tune a &os; system for best performance under
	  virtualization.</para>
      </listitem>

    </itemizedlist>

    <para>Before reading this chapter, you should:</para>

    <itemizedlist>
      <listitem>
	<para>Understand the <link linkend="basics">basics of &unix;
	    and &os;</link>.</para>
      </listitem>

      <listitem>
	<para>Know how to <link linkend="bsdinstall">install
	    &os;</link>.</para>
      </listitem>

      <listitem>
	<para>Know how to <link linkend="advanced-networking">set up a
	    network connection</link>.</para>
      </listitem>

      <listitem>
	<para>Know how to <link linkend="ports">install additional
	    third-party software</link>.</para>
      </listitem>
    </itemizedlist>
  </sect1>

  <sect1 xml:id="virtualization-guest-parallels">
    <title>&os; as a Guest on <application>Parallels</application> for
      &macos; X</title>

    <para><application>Parallels Desktop</application> for &mac; is
      a commercial software product available for &intel; based
      &apple; &mac; computers running &macos; 10.4.6 or higher.  &os;
      is a fully supported guest operating system.  Once
      <application>Parallels</application> has been installed on
      &macos; X, the user must configure a virtual machine and then
      install the desired guest operating system.</para>

    <sect2 xml:id="virtualization-guest-parallels-install">
      <title>Installing &os; on Parallels/&macos; X</title>

      <para>The first step in installing &os; on
	<application>Parallels</application> is to create a new
	virtual machine for installing &os;.  Select
	<guimenuitem>&os;</guimenuitem> as the
	<guimenu>Guest OS Type</guimenu> when prompted:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/parallels-freebsd1"/>
	</imageobject>
      </mediaobject>

      <para>Choose a reasonable amount of disk and memory
	depending on the plans for this virtual &os; instance.
	4GB of disk space and 512MB of RAM work well for most uses
	of &os; under <application>Parallels</application>:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/parallels-freebsd2"/>
	</imageobject>
      </mediaobject>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/parallels-freebsd3"/>
	</imageobject>
      </mediaobject>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/parallels-freebsd4"/>
	</imageobject>
      </mediaobject>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/parallels-freebsd5"/>
	</imageobject>
      </mediaobject>

      <para>Select the type of networking and a network
	interface:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/parallels-freebsd6"/>
	</imageobject>
      </mediaobject>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/parallels-freebsd7"/>
	</imageobject>
      </mediaobject>

      <para>Save and finish the configuration:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/parallels-freebsd8"/>
	</imageobject>
      </mediaobject>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/parallels-freebsd9"/>
	</imageobject>
      </mediaobject>

      <para>After the &os; virtual machine has been created, &os;
	can be installed on it.  This is best done with an official
	&os; <acronym>CD</acronym>/<acronym>DVD</acronym> or with an
	<acronym>ISO</acronym> image downloaded from an official
	<acronym>FTP</acronym> site.  Copy the appropriate
	<acronym>ISO</acronym> image to the local &mac; filesystem or
	insert a <acronym>CD</acronym>/<acronym>DVD</acronym> in the
	&mac;'s <acronym>CD-ROM</acronym> drive.  Click on the disc
	icon in the bottom right corner of the &os;
	<application>Parallels</application> window.  This will bring
	up a window that can be used to associate the
	<acronym>CD-ROM</acronym> drive in the virtual machine with
	the <acronym>ISO</acronym> file on disk or with the real
	<acronym>CD-ROM</acronym> drive.</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/parallels-freebsd11"/>
	</imageobject>
      </mediaobject>

      <para>Once this association with the <acronym>CD-ROM</acronym>
	source has been made, reboot the &os; virtual machine by
	clicking the reboot icon.
	<application>Parallels</application> will reboot with a
	special <acronym>BIOS</acronym> that first checks if there is
	a <acronym>CD-ROM</acronym>.</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/parallels-freebsd10"/>
	</imageobject>
      </mediaobject>

      <para>In this case it will find the &os; installation media and
	begin a normal &os; installation.  Perform the installation,
	but do not attempt to configure
	<application>&xorg;</application> at this time.</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/parallels-freebsd12"/>
	</imageobject>
      </mediaobject>

      <para>When the installation is finished, reboot into the newly
	installed &os; virtual machine.</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/parallels-freebsd13"/>
	</imageobject>
      </mediaobject>
    </sect2>

    <sect2 xml:id="virtualization-guest-parallels-configure">
      <title>Configuring &os; on
	<application>Parallels</application></title>

      <para>After &os; has been successfully installed on &macos; X
	with <application>Parallels</application>, there are a number
	of configuration steps that can be taken to optimize the
	system for virtualized operation.</para>

      <procedure>
	<step>
	  <title>Set Boot Loader Variables</title>

	  <para>The most important step is to reduce the
	    <option>kern.hz</option> tunable to reduce the CPU
	    utilization of &os; under the
	    <application>Parallels</application> environment.  This is
	    accomplished by adding the following line to
	    <filename>/boot/loader.conf</filename>:</para>

	  <programlisting>kern.hz=100</programlisting>

	  <para>Without this setting, an idle &os;
	    <application>Parallels</application> guest will use
	    roughly 15% of the CPU of a single processor &imac;.
	    After this change the usage will be closer to 5%.</para>
	</step>

	<step>
	  <title>Create a New Kernel Configuration File</title>

	  <para>All of the SCSI, FireWire, and USB device drivers
	    can be removed from a custom kernel configuration file.
	    <application>Parallels</application> provides a virtual
	    network adapter used by the &man.ed.4; driver, so all
	    network devices except for &man.ed.4; and &man.miibus.4;
	    can be removed from the kernel.</para>
	</step>

	<step>
	  <title>Configure Networking</title>

	  <para>The most basic networking setup uses DHCP to connect
	    the virtual machine to the same local area network as the
	    host &mac;.  This can be accomplished by adding
	    <literal>ifconfig_ed0="DHCP"</literal> to
	    <filename>/etc/rc.conf</filename>.  More advanced
	    networking setups are described in
	    <xref linkend="advanced-networking"/>.</para>
	</step>
      </procedure>
    </sect2>
  </sect1>

  <sect1 xml:id="virtualization-guest-virtualpc">
    <title>&os; as a Guest on <application>Virtual PC</application>
      for &windows;</title>

    <para><application>Virtual PC</application> for &windows; is a
      &microsoft; software product available for free download.  See
      this website for the <link
	xlink:href="http://www.microsoft.com/windows/downloads/virtualpc/sysreq.mspx">system
	requirements</link>.  Once
      <application>Virtual PC</application> has been installed on
      &microsoft.windows;, the user can configure a virtual machine
      and then install the desired guest operating system.</para>

    <sect2 xml:id="virtualization-guest-virtualpc-install">
      <title>Installing &os; on
	<application>Virtual PC</application></title>

      <para>The first step in installing &os; on
	<application>Virtual PC</application> is to create a new
	virtual machine for installing &os;.  Select
	<guimenuitem>Create a virtual machine</guimenuitem> when
	prompted:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/virtualpc-freebsd1"/>
	</imageobject>
      </mediaobject>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/virtualpc-freebsd2"/>
	</imageobject>
      </mediaobject>

      <para>Select <guimenuitem>Other</guimenuitem> as the
	<guimenuitem>Operating system</guimenuitem> when
	prompted:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/virtualpc-freebsd3"/>
	</imageobject>
      </mediaobject>

      <para>Then, choose a reasonable amount of disk and memory
	depending on the plans for this virtual &os; instance.
	4GB of disk space and 512MB of RAM work well for most uses
	of &os; under <application>Virtual PC</application>:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/virtualpc-freebsd4"/>
	</imageobject>
      </mediaobject>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/virtualpc-freebsd5"/>
	</imageobject>
      </mediaobject>

      <para>Save and finish the configuration:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/virtualpc-freebsd6"/>
	</imageobject>
      </mediaobject>

      <para>Select the &os; virtual machine and click
	<guimenu>Settings</guimenu>, then set the type of networking
	and a network interface:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/virtualpc-freebsd7"/>
	</imageobject>
      </mediaobject>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/virtualpc-freebsd8"/>
	</imageobject>
      </mediaobject>

      <para>After the &os; virtual machine has been created, &os; can
	be installed on it.  This is best done with an official &os;
	<acronym>CD</acronym>/<acronym>DVD</acronym> or with an
	<acronym>ISO</acronym> image downloaded from an official
	<acronym>FTP</acronym> site.  Copy the appropriate
	<acronym>ISO</acronym> image to the local &windows; filesystem
	or insert a <acronym>CD</acronym>/<acronym>DVD</acronym> in
	the <acronym>CD</acronym> drive, then double click on the &os;
	virtual machine to boot.  Then, click <guimenu>CD</guimenu>
	and choose <guimenu>Capture ISO Image...</guimenu> on the
	<application>Virtual PC</application> window.  This will bring
	up a window where the <acronym>CD-ROM</acronym> drive in the
	virtual machine can be associated with an
	<acronym>ISO</acronym> file on disk or with the real
	<acronym>CD-ROM</acronym> drive.</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/virtualpc-freebsd9"/>
	</imageobject>
      </mediaobject>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/virtualpc-freebsd10"/>
	</imageobject>
      </mediaobject>

      <para>Once this association with the <acronym>CD-ROM</acronym>
	source has been made, reboot the &os; virtual machine by
	clicking <guimenu>Action</guimenu> and
	<guimenu>Reset</guimenu>.
	<application>Virtual PC</application> will reboot with a
	special <acronym>BIOS</acronym> that first checks for a
	<acronym>CD-ROM</acronym>.</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/virtualpc-freebsd11"/>
	</imageobject>
      </mediaobject>

      <para>In this case it will find the &os; installation media
	and begin a normal &os; installation.  Continue with the
	installation, but do not attempt to configure
	<application>&xorg;</application> at this time.</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/virtualpc-freebsd12"/>
	</imageobject>
      </mediaobject>

      <para>When the installation is finished, remember to eject the
	<acronym>CD</acronym>/<acronym>DVD</acronym> or release the
	<acronym>ISO</acronym> image.  Finally, reboot into the newly
	installed &os; virtual machine.</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/virtualpc-freebsd13"/>
	</imageobject>
      </mediaobject>
    </sect2>

    <sect2 xml:id="virtualization-guest-virtualpc-configure">
      <title>Configuring &os; on <application>Virtual
	  PC</application></title>

      <para>After &os; has been successfully installed on
	&microsoft.windows; with
	<application>Virtual PC</application>, there are a number of
	configuration steps that can be taken to optimize the system
	for virtualized operation.</para>

      <procedure>
	<step>
	  <title>Set Boot Loader Variables</title>

	  <para>The most important step is to reduce the
	    <option>kern.hz</option> tunable to reduce the CPU
	    utilization of &os; under the
	    <application>Virtual PC</application> environment.  This
	    is accomplished by adding the following line to
	    <filename>/boot/loader.conf</filename>:</para>

	  <programlisting>kern.hz=100</programlisting>

	  <para>Without this setting, an idle &os;
	    <application>Virtual PC</application> guest OS will
	    use roughly 40% of the CPU of a single processor
	    computer.  After this change, the usage will be
	    closer to 3%.</para>
	</step>

	<step>
	  <title>Create a New Kernel Configuration File</title>

	  <para>All of the SCSI, FireWire, and USB device drivers can
	    be removed from a custom kernel configuration file.
	    <application>Virtual PC</application> provides a virtual
	    network adapter used by the &man.de.4; driver, so all
	    network devices except for &man.de.4; and &man.miibus.4;
	    can be removed from the kernel.</para>
	</step>

	<step>
	  <title>Configure Networking</title>

	  <para>The most basic networking setup uses DHCP to connect
	    the virtual machine to the same local area network as the
	    &microsoft.windows; host.  This can be accomplished by
	    adding <literal>ifconfig_de0="DHCP"</literal> to
	    <filename>/etc/rc.conf</filename>.  More advanced
	    networking setups are described in
	    <xref linkend="advanced-networking"/>.</para>
	</step>
      </procedure>
    </sect2>
  </sect1>

  <sect1 xml:id="virtualization-guest-vmware">
    <title>&os; as a Guest on <application>VMware Fusion</application>
      for &macos;</title>

    <para><application>VMware Fusion</application> for &mac; is a
      commercial software product available for &intel; based &apple;
      &mac; computers running &macos; 10.4.9 or higher.  &os; is a
      fully supported guest operating system.  Once
      <application>VMware Fusion</application> has been installed on
      &macos; X, the user can configure a virtual machine and then
      install the desired guest operating system.</para>

    <sect2 xml:id="virtualization-guest-vmware-install">
      <title>Installing &os; on
	<application>VMware Fusion</application></title>

      <para>The first step is to start
	<application>VMware Fusion</application> which will load the
	Virtual Machine Library.  Click <guimenuitem>New</guimenuitem>
	to create the virtual machine:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/vmware-freebsd01"/>
	</imageobject>
      </mediaobject>

      <para>This will load the New Virtual Machine Assistant.  Click
	<guimenuitem>Continue</guimenuitem> to proceed:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/vmware-freebsd02"/>
	</imageobject>
      </mediaobject>

      <para>Select <guimenuitem>Other</guimenuitem> as the
	<guimenuitem>Operating System</guimenuitem> and either
	<guimenuitem>&os;</guimenuitem> or
	<guimenuitem>&os; 64-bit</guimenuitem>, as the
	<guimenu>Version</guimenu> when prompted:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/vmware-freebsd03"/>
	</imageobject>
      </mediaobject>

      <para>Choose the name of the virtual machine and the directory
	where it should be saved:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/vmware-freebsd04"/>
	</imageobject>
      </mediaobject>

      <para>Choose the size of the Virtual Hard Disk for the virtual
	machine:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/vmware-freebsd05"/>
	</imageobject>
      </mediaobject>

      <para>Choose the method to install the virtual machine, either
	from an <acronym>ISO</acronym> image or from a
	<acronym>CD</acronym>/<acronym>DVD</acronym>:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/vmware-freebsd06"/>
	</imageobject>
      </mediaobject>

      <para>Click <guimenuitem>Finish</guimenuitem> and the virtual
	machine will boot:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/vmware-freebsd07"/>
	</imageobject>
      </mediaobject>

      <para>Install &os; as usual:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/vmware-freebsd08"/>
	</imageobject>
      </mediaobject>

      <para>Once the install is complete, the settings of the virtual
	machine can be modified, such as memory usage:</para>

      <note>
	<para>The System Hardware settings of the virtual machine
	  cannot be modified while the virtual machine is
	  running.</para>
      </note>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/vmware-freebsd09"/>
	</imageobject>
      </mediaobject>

      <para>The number of CPUs the virtual machine will have access
	to:</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/vmware-freebsd10"/>
	</imageobject>
      </mediaobject>

      <para>The status of the <acronym>CD-ROM</acronym> device.
	Normally the
	<acronym>CD</acronym>/<acronym>DVD</acronym>/<acronym>ISO</acronym>
	is disconnected from the virtual machine when it is no longer
	needed.</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/vmware-freebsd11"/>
	</imageobject>
      </mediaobject>

      <para>The last thing to change is how the virtual machine will
	connect to the network.  To allow connections to the virtual
	machine from other machines besides the host, choose
	<guimenuitem>Connect directly to the physical network
	  (Bridged)</guimenuitem>.  Otherwise,
	<guimenuitem>Share the host's internet connection
	  (NAT)</guimenuitem> is preferred so that the virtual machine
	can have access to the Internet, but the network cannot access
	the virtual machine.</para>

      <mediaobject>
	<imageobject>
	  <imagedata fileref="virtualization/vmware-freebsd12"/>
	</imageobject>
      </mediaobject>

      <para>After modifying the settings, boot the newly installed
	&os; virtual machine.</para>
    </sect2>

    <sect2 xml:id="virtualization-guest-vmware-configure">
      <title>Configuring &os; on <application>VMware
	  Fusion</application></title>

      <para>After &os; has been successfully installed on &macos; X
	with <application>VMware Fusion</application>, there are a
	number of configuration steps that can be taken to optimize
	the system for virtualized operation.</para>

      <procedure>
	<step>
	  <title>Set Boot Loader Variables</title>

	  <para>The most important step is to reduce the
	    <option>kern.hz</option> tunable to reduce the CPU
	    utilization of &os; under the
	    <application>VMware Fusion</application> environment.
	    This is accomplished by adding the following line to
	    <filename>/boot/loader.conf</filename>:</para>

	  <programlisting>kern.hz=100</programlisting>

	  <para>Without this setting, an idle &os;
	    <application>VMware Fusion</application> guest will use
	    roughly 15% of the CPU of a single processor &imac;.
	    After this change, the usage will be closer to 5%.</para>
	</step>

	<step>
	  <title>Create a New Kernel Configuration File</title>

	  <para>All of the FireWire, and USB device drivers can be
	    removed from a custom kernel configuration file.
	    <application>VMware Fusion</application> provides a
	    virtual network adapter used by the &man.em.4; driver, so
	    all network devices except for &man.em.4; can be removed
	    from the kernel.</para>
	</step>

	<step>
	  <title>Configure Networking</title>

	  <para>The most basic networking setup uses DHCP to connect
	    the virtual machine to the same local area network as the
	    host &mac;.  This can be accomplished by adding
	    <literal>ifconfig_em0="DHCP"</literal> to
	    <filename>/etc/rc.conf</filename>.  More advanced
	    networking setups are described in
	    <xref linkend="advanced-networking"/>.</para>
	</step>
      </procedure>
    </sect2>
  </sect1>

  <sect1 xml:id="virtualization-guest-virtualbox">
    <title>&os; as a Guest on &virtualbox;</title>

    <para>&os; works well as a guest in
      <application>&virtualbox;</application>.  The virtualization
      software is available for most common operating systems,
      including &os; itself.</para>

    <para>The <application>&virtualbox;</application> guest additions
      provide support for:</para>

    <itemizedlist>
      <listitem>
	<para>Clipboard sharing.</para>
      </listitem>

      <listitem>
	<para>Mouse pointer integration.</para>
      </listitem>

      <listitem>
	<para>Host time synchronization.</para>
      </listitem>

      <listitem>
	<para>Window scaling.</para>
      </listitem>

      <listitem>
	<para>Seamless mode.</para>
      </listitem>
    </itemizedlist>

    <note>
      <para>These commands are run in the &os; guest.</para>
    </note>

    <para>First, install the
      <package>emulators/virtualbox-ose-additions</package> package
      or port in the &os; guest.  This will install the port:</para>

    <screen>&prompt.root; <userinput>cd /usr/ports/emulators/virtualbox-ose-additions &amp;&amp; make install clean</userinput></screen>

    <para>Add these lines to <filename>/etc/rc.conf</filename>:</para>

    <programlisting>vboxguest_enable="YES"
vboxservice_enable="YES"</programlisting>

    <para>If &man.ntpd.8; or &man.ntpdate.8; is used, disable host
      time synchronization:</para>

    <programlisting>vboxservice_flags="--disable-timesync"</programlisting>

    <para><application>Xorg</application> will automatically recognize
      the <literal>vboxvideo</literal> driver.  It can also be
      manually entered in
      <filename>/etc/X11/xorg.conf</filename>:</para>

    <programlisting>Section "Device"
	Identifier "Card0"
	Driver "vboxvideo"
	VendorName "InnoTek Systemberatung GmbH"
	BoardName "VirtualBox Graphics Adapter"
EndSection</programlisting>

    <para>To use the <literal>vboxmouse</literal> driver, adjust the
      mouse section in <filename>/etc/X11/xorg.conf</filename>:</para>

    <programlisting>Section "InputDevice"
	Identifier "Mouse0"
	Driver "vboxmouse"
EndSection</programlisting>

    <para><acronym>HAL</acronym> users should create the following
      <filename>/usr/local/etc/hal/fdi/policy/90-vboxguest.fdi</filename>
      or copy it from
      <filename>/usr/local/share/hal/fdi/policy/10osvendor/90-vboxguest.fdi</filename>:</para>

    <programlisting>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!--
# Sun VirtualBox
# Hal driver description for the vboxmouse driver
# $Id: chapter.xml,v 1.33 2012-03-17 04:53:52 eadler Exp $

	Copyright (C) 2008-2009 Sun Microsystems, Inc.

	This file is part of VirtualBox Open Source Edition (OSE, as
	available from http://www.virtualbox.org. This file is free software;
	you can redistribute it and/or modify it under the terms of the GNU
	General Public License (GPL) as published by the Free Software
	Foundation, in version 2 as it comes in the "COPYING" file of the
	VirtualBox OSE distribution. VirtualBox OSE is distributed in the
	hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.

	Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
	Clara, CA 95054 USA or visit http://www.sun.com if you need
	additional information or have any questions.
--&gt;
&lt;deviceinfo version="0.2"&gt;
  &lt;device&gt;
    &lt;match key="info.subsystem" string="pci"&gt;
      &lt;match key="info.product" string="VirtualBox guest Service"&gt;
        &lt;append key="info.capabilities" type="strlist"&gt;input&lt;/append&gt;
	&lt;append key="info.capabilities" type="strlist"&gt;input.mouse&lt;/append&gt;
        &lt;merge key="input.x11_driver" type="string"&gt;vboxmouse&lt;/merge&gt;
	&lt;merge key="input.device" type="string"&gt;/dev/vboxguest&lt;/merge&gt;
      &lt;/match&gt;
    &lt;/match&gt;
  &lt;/device&gt;
&lt;/deviceinfo&gt;</programlisting>

    <para>Shared folders for file transfers between host and VM are
      accessible by mounting them using
      <literal>mount_vboxvfs</literal>.  A shared folder can be created
      on the host using the VirtualBox GUI or via
      <command>vboxmanage</command>.  For example, to create a shared
      folder called <replaceable>myshare</replaceable> under
      <filename><replaceable>/mnt/bsdboxshare</replaceable></filename>
      for the VM named <replaceable>BSDBox</replaceable>, run:</para>

    <screen>&prompt.root; <userinput>vboxmanage sharedfolder add '<replaceable>BSDBox</replaceable>' --name <replaceable>myshare</replaceable> --hostpath <replaceable>/mnt/bsdboxshare</replaceable></userinput></screen>

    <para>Note that the shared folder name must not contain spaces.
      Mount the shared folder from within the guest system like
      this:</para>

    <screen>&prompt.root; <userinput>mount_vboxvfs -w <replaceable>myshare</replaceable> <replaceable>/mnt</replaceable></userinput></screen>
  </sect1>

  <sect1 xml:id="virtualization-host-virtualbox">
    <title>&os; as a Host with &virtualbox;</title>

    <para><application>&virtualbox;</application> is an actively
      developed, complete virtualization package, that is available
      for most operating systems including &windows;, &macos;, &linux;
      and &os;.  It is equally capable of running &windows; or
      &unix;-like guests.  It is released as open source software, but
      with closed-source components available in a separate extension
      pack.  These components include support for USB 2.0 devices.
      More information may be found on the <link
	xlink:href="http://www.virtualbox.org/wiki/Downloads"><quote>Downloads</quote>
	page of the <application>&virtualbox;</application>
	wiki</link>.  Currently, these extensions are not available
      for &os;.</para>

    <sect2 xml:id="virtualization-virtualbox-install">
      <title>Installing &virtualbox;</title>

      <para><application>&virtualbox;</application> is available as a
	&os; package or port in
	<package>emulators/virtualbox-ose</package>.  The port can be
	installed using these commands:</para>

      <screen>&prompt.root; <userinput>cd /usr/ports/emulators/virtualbox-ose</userinput>
&prompt.root; <userinput>make install clean</userinput></screen>

      <para>One useful option in the port's configuration menu is the
	<literal>GuestAdditions</literal> suite of programs.  These
	provide a number of useful features in guest operating
	systems, like mouse pointer integration (allowing the mouse to
	be shared between host and guest without the need to press a
	special keyboard shortcut to switch) and faster video
	rendering, especially in &windows; guests.  The guest
	additions are available in the <guimenu>Devices</guimenu>
	menu, after the installation of the guest is finished.</para>

      <para>A few configuration changes are needed before
	<application>&virtualbox;</application> is started for the
	first time.  The port installs a kernel module in
	<filename>/boot/modules</filename> which
	must be loaded into the running kernel:</para>

      <screen>&prompt.root; <userinput>kldload vboxdrv</userinput></screen>

      <para>To ensure the module is always loaded after a reboot,
	add this line to
	<filename>/boot/loader.conf</filename>:</para>

      <programlisting>vboxdrv_load="YES"</programlisting>

      <para>To use the kernel modules that allow bridged or host-only
	networking, add this line to
	<filename>/etc/rc.conf</filename> and reboot the
	computer:</para>

      <programlisting>vboxnet_enable="YES"</programlisting>

      <para>The <systemitem class="groupname">vboxusers</systemitem>
	group is created during installation of
	<application>&virtualbox;</application>.  All users that need
	access to <application>&virtualbox;</application> will have to
	be added as members of this group.  <command>pw</command> can
	be used to add new members:</para>

      <screen>&prompt.root; <userinput>pw groupmod vboxusers -m <replaceable>yourusername</replaceable></userinput></screen>

      <para>The default permissions for
	<filename>/dev/vboxnetctl</filename> are restrictive and need
	to be changed for bridged networking:</para>

      <screen>&prompt.root; <userinput>chown root:vboxusers /dev/vboxnetctl</userinput>
&prompt.root; <userinput>chmod 0660 /dev/vboxnetctl</userinput></screen>

      <para>To make this permissions change permanent, add these
	lines to <filename>/etc/devfs.conf</filename>:</para>

      <programlisting>own     vboxnetctl root:vboxusers
perm    vboxnetctl 0660</programlisting>

      <para>To launch <application>&virtualbox;</application>,
	type from a <application>&xorg;</application> session:</para>

      <screen>&prompt.user; <userinput>VirtualBox</userinput></screen>

      <para>For more information on configuring and using
	<application>&virtualbox;</application>, refer to the
	<link xlink:href="http://www.virtualbox.org">official
	  website</link>.  For &os;-specific information and
	troubleshooting instructions, refer to the <link
	  xlink:href="http://wiki.FreeBSD.org/VirtualBox">relevant
	  page in the &os; wiki</link>.</para>
    </sect2>

    <sect2 xml:id="virtualization-virtualbox-usb-support">
      <title>&virtualbox; USB Support</title>

      <para><application>&virtualbox;</application> can be configured
	to pass <acronym>USB</acronym> devices through to the guest
	operating system.  The host controller of the OSE version is
	limited to emulating <acronym>USB</acronym> 1.1 devices until
	the extension pack supporting <acronym>USB</acronym> 2.0 and
	3.0 devices becomes available on &os;.</para>

      <para>For <application>&virtualbox;</application> to be aware of
	<acronym>USB</acronym> devices attached to the machine, the
	user needs to be a member of the <systemitem
	  class="groupname">operator</systemitem> group.</para>

      <screen>&prompt.root; <userinput>pw groupmod operator -m <replaceable>yourusername</replaceable></userinput></screen>

      <para>Then, add the following to
       <filename>/etc/devfs.rules</filename>, or create this file if
       it does not exist yet:</para>

      <programlisting>[system=10]
add path 'usb/*' mode 0660 group operator</programlisting>

      <para>To load these new rules, add the following to
       <filename>/etc/rc.conf</filename>:</para>

      <programlisting>devfs_system_ruleset="system"</programlisting>

      <para>Then, restart devfs:</para>

      <screen>&prompt.root; <userinput>service devfs restart</userinput></screen>

      <para>Restart the login session and
	<application>&virtualbox;</application> for these changes to
	take effect, and create <acronym>USB</acronym> filters as
	necessary.</para>
    </sect2>

    <sect2 xml:id="virtualization-virtualbox-host-dvd-cd-access">
      <title>&virtualbox; Host
	<acronym>DVD</acronym>/<acronym>CD</acronym> Access</title>

      <para>Access to the host
	<acronym>DVD</acronym>/<acronym>CD</acronym> drives from
	guests is achieved through the sharing of the physical drives.
	Within &virtualbox;, this is set up from the Storage window in
	the Settings of the virtual machine.  If needed, create an
	empty <acronym>IDE</acronym>
	<acronym>CD</acronym>/<acronym>DVD</acronym> device first.
	Then choose the Host Drive from the popup menu for the virtual
	<acronym>CD</acronym>/<acronym>DVD</acronym> drive selection.
	A checkbox labeled <literal>Passthrough</literal> will appear.
	This allows the virtual machine to use the hardware directly.
	For example, audio <acronym>CD</acronym>s or the burner will
	only function if this option is selected.</para>

      <para><acronym>HAL</acronym> needs to run for
	<application>&virtualbox;</application>
	<acronym>DVD</acronym>/<acronym>CD</acronym> functions to
	work, so enable it in <filename>/etc/rc.conf</filename> and
	start it if it is not already running:</para>

      <programlisting>hald_enable="YES"</programlisting>

      <screen>&prompt.root; <userinput>service hald start</userinput></screen>

      <para>In order for users to be able to use
	<application>&virtualbox;</application>
	<acronym>DVD</acronym>/<acronym>CD</acronym> functions, they
	need access to <filename>/dev/xpt0</filename>,
	<filename>/dev/cd<replaceable>N</replaceable></filename>, and
	<filename>/dev/pass<replaceable>N</replaceable></filename>.
	This is usually achieved by making the user a member of
	<systemitem class="groupname">operator</systemitem>.
	Permissions to these devices have to be corrected by adding
	these lines to <filename>/etc/devfs.conf</filename>:</para>

      <programlisting>perm cd* 0660
perm xpt0 0660
perm pass* 0660</programlisting>

      <screen>&prompt.root; <userinput>service devfs restart</userinput></screen>
    </sect2>
  </sect1>

  <sect1 xml:id="virtualization-host-bhyve">
    <title>&os; as a Host with
      <application>bhyve</application></title>

    <para>The <application>bhyve</application>
      <acronym>BSD</acronym>-licensed hypervisor became part of the
      base system with &os; 10.0-RELEASE.  This hypervisor supports a
      number of guests, including &os;, OpenBSD, and many &linux;
      distributions.  By default, <application>bhyve</application>
      provides access to serial console and does not emulate a
      graphical console.  Virtualization offload features of newer
      <acronym>CPU</acronym>s are used to avoid the legacy methods of
      translating instructions and manually managing memory
      mappings.</para>

    <para>The <application>bhyve</application> design requires a
      processor that supports &intel; Extended Page Tables
      (<acronym>EPT</acronym>) or &amd; Rapid Virtualization Indexing
      (<acronym>RVI</acronym>) or Nested Page Tables
      (<acronym>NPT</acronym>).  Hosting &linux; guests or &os; guests
      with more than one <acronym>vCPU</acronym> requires
      <acronym>VMX</acronym> unrestricted mode support
      (<acronym>UG</acronym>).  Most newer processors, specifically
      the &intel;&nbsp;&core; i3/i5/i7 and &intel;&nbsp;&xeon;
      E3/E5/E7, support these features.  <acronym>UG</acronym> support
      was introduced with Intel's Westmere micro-architecture.  For a
      complete list of &intel; processors that support
      <acronym>EPT</acronym>, refer to <link
	xlink:href="https://ark.intel.com/content/www/us/en/ark/search/featurefilter.html?productType=873&amp;0_ExtendedPageTables=True"/>.
      <acronym>RVI</acronym> is found on the third generation and
      later of the &amd.opteron; (Barcelona) processors.  The easiest
      way to tell if a processor supports
      <application>bhyve</application> is to run
      <command>dmesg</command> or look in
      <filename>/var/run/dmesg.boot</filename> for the
      <literal>POPCNT</literal> processor feature flag on the
      <literal>Features2</literal> line for &amd; processors or
      <literal>EPT</literal> and <literal>UG</literal> on the
      <literal>VT-x</literal> line for &intel; processors.</para>

    <sect2 xml:id="virtualization-bhyve-prep">
      <title>Preparing the Host</title>

      <para>The first step to creating a virtual machine in
	<application>bhyve</application> is configuring the host
	system.  First, load the <application>bhyve</application>
	kernel module:</para>

      <screen>&prompt.root; <userinput>kldload vmm</userinput></screen>

      <para>Then, create a <filename>tap</filename> interface for the
	network device in the virtual machine to attach to.  In order
	for the network device to participate in the network, also
	create a bridge interface containing the
	<filename>tap</filename> interface and the physical interface
	as members.  In this example, the physical interface is
	<replaceable>igb0</replaceable>:</para>

      <screen>&prompt.root; <userinput>ifconfig <replaceable>tap0</replaceable> create</userinput>
&prompt.root; <userinput>sysctl net.link.tap.up_on_open=1</userinput>
net.link.tap.up_on_open: 0 -> 1
&prompt.root; <userinput>ifconfig <replaceable>bridge0</replaceable> create</userinput>
&prompt.root; <userinput>ifconfig <replaceable>bridge0</replaceable> addm <replaceable>igb0</replaceable> addm <replaceable>tap0</replaceable></userinput>
&prompt.root; <userinput>ifconfig <replaceable>bridge0</replaceable> up</userinput></screen>
    </sect2>

    <sect2 xml:id="virtualization-bhyve-freebsd">
      <title>Creating a FreeBSD Guest</title>

      <para>Create a file to use as the virtual disk for the guest
	machine.  Specify the size and name of the virtual
	disk:</para>

      <screen>&prompt.root; <userinput>truncate -s <replaceable>16G</replaceable> <replaceable>guest.img</replaceable></userinput></screen>

      <para>Download an installation image of &os; to install:</para>

      <screen>&prompt.root; <userinput>fetch <replaceable>ftp://ftp.freebsd.org/pub/FreeBSD/releases/ISO-IMAGES/10.3/FreeBSD-10.3-RELEASE-amd64-bootonly.iso</replaceable></userinput>
FreeBSD-10.3-RELEASE-amd64-bootonly.iso       100% of  230 MB  570 kBps 06m17s</screen>

      <para>&os; comes with an example script for running a virtual
	machine in <application>bhyve</application>.  The script will
	start the virtual machine and run it in a loop, so it will
	automatically restart if it crashes.  The script takes a
	number of options to control the configuration of the machine:
	<option>-c</option> controls the number of virtual CPUs,
	<option>-m</option> limits the amount of memory available to
	the guest, <option>-t</option> defines which
	<filename>tap</filename> device to use, <option>-d</option>
	indicates which disk image to use, <option>-i</option> tells
	<application>bhyve</application> to boot from the
	<acronym>CD</acronym> image instead of the disk, and
	<option>-I</option> defines which <acronym>CD</acronym> image
	to use.  The last parameter is the name of the virtual
	machine, used to track the running machines.  This example
	starts the virtual machine in installation mode:</para>

      <screen>&prompt.root; <userinput>sh /usr/share/examples/bhyve/vmrun.sh -c <replaceable>1</replaceable> -m <replaceable>1024M</replaceable> -t <replaceable>tap0</replaceable> -d <replaceable>guest.img</replaceable> -i -I <replaceable>FreeBSD-10.3-RELEASE-amd64-bootonly.iso</replaceable> <replaceable>guestname</replaceable></userinput></screen>

      <para>The virtual machine will boot and start the installer.
	After installing a system in the virtual machine, when the
	system asks about dropping in to a shell at the end of the
	installation, choose <guibutton>Yes</guibutton>.</para>

      <para>Reboot the virtual machine.  While rebooting the virtual
	machine causes <application>bhyve</application> to exit, the
	<filename>vmrun.sh</filename> script runs
	<command>bhyve</command> in a loop and will automatically
	restart it.  When this happens, choose the reboot option from
	the boot loader menu in order to escape the loop.  Now the
	guest can be started from the virtual disk:</para>

      <screen>&prompt.root; <userinput>sh /usr/share/examples/bhyve/vmrun.sh -c <replaceable>4</replaceable> -m <replaceable>1024M</replaceable> -t <replaceable>tap0</replaceable> -d <replaceable>guest.img</replaceable> <replaceable>guestname</replaceable></userinput></screen>
    </sect2>

    <sect2 xml:id="virtualization-bhyve-linux">
      <title>Creating a &linux; Guest</title>

      <para>In order to boot operating systems other than &os;, the
	<package>sysutils/grub2-bhyve</package> port must be first
	installed.</para>

      <para>Next, create a file to use as the virtual disk for the
	guest machine:</para>

      <screen>&prompt.root; <userinput>truncate -s <replaceable>16G</replaceable> <replaceable>linux.img</replaceable></userinput></screen>

      <para>Starting a virtual machine with
	<application>bhyve</application> is a two step process.  First
	a kernel must be loaded, then the guest can be started.  The
	&linux; kernel is loaded with
	<package>sysutils/grub2-bhyve</package>.  Create a
	<filename>device.map</filename> that
	<application>grub</application> will use to map the virtual
	devices to the files on the host system:</para>

      <programlisting>(hd0) ./linux.img
(cd0) ./somelinux.iso</programlisting>

      <para>Use <package>sysutils/grub2-bhyve</package> to load the
	&linux; kernel from the <acronym>ISO</acronym> image:</para>

      <screen>&prompt.root; <userinput>grub-bhyve -m device.map -r cd0 -M <replaceable>1024M</replaceable> <replaceable>linuxguest</replaceable></userinput></screen>

      <para>This will start grub.  If the installation
	<acronym>CD</acronym> contains a
	<filename>grub.cfg</filename>, a menu will be displayed.
	If not, the <literal>vmlinuz</literal> and
	<literal>initrd</literal> files must be located and loaded
	manually:</para>

      <screen>grub> <userinput>ls</userinput>
(hd0) (cd0) (cd0,msdos1) (host)
grub> <userinput>ls (cd0)/isolinux</userinput>
boot.cat boot.msg grub.conf initrd.img isolinux.bin isolinux.cfg memtest
splash.jpg TRANS.TBL vesamenu.c32 vmlinuz
grub> <userinput>linux (cd0)/isolinux/vmlinuz</userinput>
grub> <userinput>initrd (cd0)/isolinux/initrd.img</userinput>
grub> <userinput>boot</userinput></screen>

      <para>Now that the &linux; kernel is loaded, the guest can be
	started:</para>

      <screen>&prompt.root; <userinput>bhyve -A -H -P -s 0:0,hostbridge -s 1:0,lpc -s 2:0,virtio-net,<replaceable>tap0</replaceable> -s 3:0,virtio-blk,<replaceable>./linux.img</replaceable> \
    -s 4:0,ahci-cd,<replaceable>./somelinux.iso</replaceable> -l com1,stdio -c <replaceable>4</replaceable> -m <replaceable>1024M</replaceable> <replaceable>linuxguest</replaceable></userinput></screen>

      <para>The system will boot and start the installer.  After
	installing a system in the virtual machine, reboot the virtual
	machine.  This will cause <application>bhyve</application> to
	exit.  The instance of the virtual machine needs to be
	destroyed before it can be started again:</para>

      <screen>&prompt.root; <userinput>bhyvectl --destroy --vm=<replaceable>linuxguest</replaceable></userinput></screen>

      <para>Now the guest can be started directly from the virtual
	disk.  Load the kernel:</para>

      <screen>&prompt.root; <userinput>grub-bhyve -m device.map -r hd0,msdos1 -M <replaceable>1024M</replaceable> <replaceable>linuxguest</replaceable></userinput>
grub> <userinput>ls</userinput>
(hd0) (hd0,msdos2) (hd0,msdos1) (cd0) (cd0,msdos1) (host)
(lvm/VolGroup-lv_swap) (lvm/VolGroup-lv_root)
grub> <userinput>ls (hd0,msdos1)/</userinput>
lost+found/ grub/ efi/ System.map-2.6.32-431.el6.x86_64 config-2.6.32-431.el6.x
86_64 symvers-2.6.32-431.el6.x86_64.gz vmlinuz-2.6.32-431.el6.x86_64
initramfs-2.6.32-431.el6.x86_64.img
grub> <userinput>linux (hd0,msdos1)/vmlinuz-2.6.32-431.el6.x86_64 root=/dev/mapper/VolGroup-lv_root</userinput>
grub> <userinput>initrd (hd0,msdos1)/initramfs-2.6.32-431.el6.x86_64.img</userinput>
grub> <userinput>boot</userinput></screen>

      <para>Boot the virtual machine:</para>

      <screen>&prompt.root; <userinput>bhyve -A -H -P -s 0:0,hostbridge -s 1:0,lpc -s 2:0,virtio-net,<replaceable>tap0</replaceable> \
    -s 3:0,virtio-blk,<replaceable>./linux.img</replaceable> -l com1,stdio -c <replaceable>4</replaceable> -m <replaceable>1024M</replaceable> <replaceable>linuxguest</replaceable></userinput></screen>

      <para>&linux; will now boot in the virtual machine and
	eventually present you with the login prompt.  Login and use
	the virtual machine.  When you are finished, reboot the
	virtual machine to exit <application>bhyve</application>.
	Destroy the virtual machine instance:</para>

      <screen>&prompt.root; <userinput>bhyvectl --destroy --vm=<replaceable>linuxguest</replaceable></userinput></screen>
    </sect2>

    <sect2 xml:id="virtualization-bhyve-uefi">
      <title>Booting <application>bhyve</application> Virtual Machines
	with <acronym>UEFI</acronym> Firmware</title>

      <para>In addition to <application>bhyveload</application> and
	<application>grub-bhyve</application>, the
	<application>bhyve</application> hypervisor can also boot
	virtual machines using the <acronym>UEFI</acronym> userspace
	firmware.  This option may support guest operating systems
	that are not supported by the other loaders.</para>

      <para>In order to make use of the <acronym>UEFI</acronym>
	support in <application>bhyve</application>, first obtain the
	<acronym>UEFI</acronym> firmware images.  This can be done by
	installing <package>sysutils/bhyve-firmware</package> port or
	package.</para>

      <para>With the firmware in place, add the flags <option>-l
	  bootrom,<replaceable>/path/to/firmware</replaceable></option>
	to your <application>bhyve</application> command line.  The
	actual <application>bhyve</application> command may look like
	this:</para>

      <screen>&prompt.root; <userinput>bhyve -AHP -s 0:0,hostbridge -s 1:0,lpc \
-s 2:0,virtio-net,<replaceable>tap1</replaceable> -s 3:0,virtio-blk,<replaceable>./disk.img</replaceable> \
-s 4:0,ahci-cd,<replaceable>./install.iso</replaceable> -c <replaceable>4</replaceable> -m <replaceable>1024M</replaceable> \
-l bootrom,<replaceable>/usr/local/share/uefi-firmware/BHYVE_UEFI.fd</replaceable> \
<replaceable>guest</replaceable></userinput></screen>

      <para><package>sysutils/bhyve-firmware</package> also contains a
	<acronym>CSM</acronym>-enabled firmware, to boot guests with
	no <acronym>UEFI</acronym> support in legacy
	<acronym>BIOS</acronym> mode:</para>

      <screen>&prompt.root; <userinput>bhyve -AHP -s 0:0,hostbridge -s 1:0,lpc \
-s 2:0,virtio-net,<replaceable>tap1</replaceable> -s 3:0,virtio-blk,<replaceable>./disk.img</replaceable> \
-s 4:0,ahci-cd,<replaceable>./install.iso</replaceable> -c <replaceable>4</replaceable> -m <replaceable>1024M</replaceable> \
-l bootrom,<replaceable>/usr/local/share/uefi-firmware/BHYVE_UEFI_CSM.fd</replaceable> \
<replaceable>guest</replaceable></userinput></screen>
    </sect2>

    <sect2 xml:id="virtualization-bhyve-framebuffer">
      <title>Graphical <acronym>UEFI</acronym> Framebuffer for
	<application>bhyve</application> Guests</title>

      <para>The <acronym>UEFI</acronym> firmware support is
	particularly useful with predominantly graphical guest
	operating systems such as Microsoft &windows;.</para>

      <para>Support for the UEFI-GOP framebuffer may also be enabled
	with the <option>-s
	  29,fbuf,tcp=<replaceable>0.0.0.0:5900</replaceable></option>
	flags.  The framebuffer resolution may be configured with
	<option>w=<replaceable>800</replaceable></option> and
	<option>h=<replaceable>600</replaceable></option>, and
	<application>bhyve</application> can be instructed to wait for
	a <acronym>VNC</acronym> connection before booting the guest
	by adding <option>wait</option>.  The framebuffer may be
	accessed from the host or over the network via the
	<acronym>VNC</acronym> protocol.</para>

      <para>The resulting <application>bhyve</application> command
	would look like this:</para>

      <screen>&prompt.root; <userinput>bhyve -AHP -s 0:0,hostbridge -s 31:0,lpc \
-s 2:0,virtio-net,<replaceable>tap1</replaceable> -s 3:0,virtio-blk,<replaceable>./disk.img</replaceable> \
-s 4:0,ahci-cd,<replaceable>./install.iso</replaceable> -c <replaceable>4</replaceable> -m <replaceable>1024M</replaceable> \
-s 29,fbuf,tcp=<replaceable>0.0.0.0:5900</replaceable>,w=<replaceable>800</replaceable>,h=<replaceable>600</replaceable>,wait \
-l bootrom,<replaceable>/usr/local/share/uefi-firmware/BHYVE_UEFI.fd</replaceable> \
<replaceable>guest</replaceable></userinput></screen>

      <para>Note, in BIOS emulation mode, the framebuffer will cease
	receiving updates once control is passed from firmware to
	guest operating system.</para>
    </sect2>

    <sect2 xml:id="virtualization-bhyve-zfs">
      <title>Using <acronym>ZFS</acronym> with
	<application>bhyve</application> Guests</title>

      <para>If <acronym>ZFS</acronym> is available on the host
	machine, using <acronym>ZFS</acronym> volumes
	instead of disk image files can provide significant
	performance benefits for the guest <acronym>VMs</acronym>.  A
	<acronym>ZFS</acronym> volume can be created by:</para>

      <screen>&prompt.root; <userinput>zfs create -V<replaceable>16G</replaceable> -o volmode=dev <replaceable>zroot/linuxdisk0</replaceable></userinput></screen>

      <para>When starting the <acronym>VM</acronym>, specify the
	<acronym>ZFS</acronym> volume as the disk drive:</para>

      <screen>&prompt.root; <userinput>bhyve -A -H -P -s 0:0,hostbridge -s 1:0,lpc -s 2:0,virtio-net,<replaceable>tap0</replaceable> -s3:0,virtio-blk,<replaceable>/dev/zvol/zroot/linuxdisk0</replaceable> \
    -l com1,<replaceable>stdio</replaceable> -c <replaceable>4</replaceable> -m <replaceable>1024M</replaceable> <replaceable>linuxguest</replaceable></userinput></screen>
    </sect2>

    <sect2 xml:id="virtualization-bhyve-nmdm">
      <title>Virtual Machine Consoles</title>

      <para>It is advantageous to wrap the
	<application>bhyve</application> console in a session
	management tool such as <package>sysutils/tmux</package> or
	<package>sysutils/screen</package> in order to detach and
	reattach to the console.  It is also possible to have the
	console of <application>bhyve</application> be a null modem
	device that can be accessed with <command>cu</command>.  To do
	this, load the <filename>nmdm</filename> kernel module and
	replace <option>-l com1,stdio</option> with
	<option>-l com1,/dev/nmdm0A</option>.  The
	<filename>/dev/nmdm</filename> devices are created
	automatically as needed, where each is a pair, corresponding
	to the two ends of the null modem cable
	(<filename>/dev/nmdm0A</filename> and
	<filename>/dev/nmdm0B</filename>).  See &man.nmdm.4; for more
	information.</para>

      <screen>&prompt.root; <userinput>kldload nmdm</userinput>
&prompt.root; <userinput>bhyve -A -H -P -s 0:0,hostbridge -s 1:0,lpc -s 2:0,virtio-net,<replaceable>tap0</replaceable> -s 3:0,virtio-blk,<replaceable>./linux.img</replaceable> \
    -l com1,<replaceable>/dev/nmdm0A</replaceable> -c <replaceable>4</replaceable> -m <replaceable>1024M</replaceable> <replaceable>linuxguest</replaceable></userinput>
&prompt.root; <userinput>cu -l <replaceable>/dev/nmdm0B</replaceable></userinput>
Connected

Ubuntu 13.10 handbook ttyS0

handbook login:</screen>
    </sect2>

    <sect2 xml:id="virtualization-bhyve-managing">
      <title>Managing Virtual Machines</title>

      <para>A device node is created in <filename
	  role="directory">/dev/vmm</filename> for each virtual
	machine.  This allows the administrator to easily see a list
	of the running virtual machines:</para>

      <screen>&prompt.root; <userinput>ls -al /dev/vmm</userinput>
total 1
dr-xr-xr-x   2 root  wheel    512 Mar 17 12:19 ./
dr-xr-xr-x  14 root  wheel    512 Mar 17 06:38 ../
crw-------   1 root  wheel  0x1a2 Mar 17 12:20 guestname
crw-------   1 root  wheel  0x19f Mar 17 12:19 linuxguest
crw-------   1 root  wheel  0x1a1 Mar 17 12:19 otherguest</screen>

      <para>A specified virtual machine can be destroyed using
	<command>bhyvectl</command>:</para>

      <screen>&prompt.root; <userinput>bhyvectl --destroy --vm=<replaceable>guestname</replaceable></userinput></screen>
    </sect2>

    <sect2 xml:id="virtualization-bhyve-onboot">
      <title>Persistent Configuration</title>

      <para>In order to configure the system to start
	<application>bhyve</application> guests at boot time, the
	following configurations must be made in the specified
	files:</para>

      <procedure>
	<step>
	  <title><filename>/etc/sysctl.conf</filename></title>

	  <programlisting>net.link.tap.up_on_open=1</programlisting>
	</step>

	<step>
	  <title><filename>/etc/rc.conf</filename></title>

	  <programlisting>cloned_interfaces="<replaceable>bridge0</replaceable> <replaceable>tap0</replaceable>"
ifconfig_bridge0="addm <replaceable>igb0</replaceable> addm <replaceable>tap0</replaceable>"
kld_list="nmdm vmm"</programlisting>
	</step>
      </procedure>
    </sect2>
  </sect1>

  <sect1 xml:id="virtualization-host-xen">
    <title>&os; as a &xen;-Host</title>

    <para><application>Xen</application> is a GPLv2-licensed <link
	xlink:href="https://en.wikipedia.org/wiki/Hypervisor#Classification">type
	1 hypervisor</link> for &intel; and &arm; architectures.  &os;
      has included &i386; and &amd;&nbsp;64-Bit <link
	xlink:href="https://wiki.xenproject.org/wiki/DomU">DomU</link>
      and <link
	xlink:href="https://en.wikipedia.org/wiki/Amazon_Elastic_Compute_Cloud">Amazon
	EC2</link> unprivileged domain (virtual machine) support since
      &os;&nbsp;8.0 and includes Dom0 control domain (host) support in
      &os;&nbsp;11.0.  Support for para-virtualized (PV) domains has
      been removed from &os;&nbsp;11 in favor of hardware virtualized
      (HVM) domains, which provides better performance.</para>

    <para>&xen; is a bare-metal hypervisor, which means that it is the
      first program loaded after the BIOS. A special privileged guest
      called the Domain-0 (<literal>Dom0</literal> for short) is then
      started.  The Dom0 uses its special privileges to directly
      access the underlying physical hardware, making it a
      high-performance solution.  It is able to access the disk
      controllers and network adapters directly.  The &xen; management
      tools to manage and control the &xen; hypervisor are also used
      by the Dom0 to create, list, and destroy VMs.  Dom0 provides
      virtual disks and networking for unprivileged domains, often
      called <literal>DomU</literal>.  &xen; Dom0 can be compared to
      the service console of other hypervisor solutions, while the
      DomU is where individual guest VMs are run.</para>

<!-- Hidden until the mode in which FreeBSD uses Xen is supported.
    <para>Features of &xen; include GPU passthrough from the host
      running the Dom0 into a DomU guest machine.  This requires a
      CPU, chipset, and BIOS with VT-D support and might require extra
      patches or not work with all graphics cards.  A list of adapters
      can be found in the <link
	xlink:href="https://wiki.xenproject.org/wiki/Xen_VGA_Passthrough_Tested_Adapters">Xen
	Wiki</link>.  Note that not all GPUs listed there are
      supported on &os;.  The  &xen; hypervisor also supports PCI
      passthrough to give a DomU guest full, direct access to a PCI
      device like NIC, disk controller, or soundcard.</para>
-->
    <para>&xen; can migrate VMs between different &xen; servers.  When
      the two xen hosts share the same underlying storage, the
      migration can be done without having to shut the VM down first.
      Instead, the migration is performed live while the DomU is
      running and there is no need to restart it or plan a downtime.
      This is useful in maintenance scenarios or upgrade windows to
      ensure that the services provided by the DomU are still
      provided.  Many more features of &xen; are listed on the <link
	xlink:href="https://wiki.xenproject.org/wiki/Category:Overview">Xen
	Wiki Overview page</link>.  Note that not all features are
      supported on &os; yet.</para>

    <sect2 xml:id="virtualization-host-xen-requirements">
      <title>Hardware Requirements for &xen; Dom0</title>

      <para>To run the &xen; hypervisor on a host, certain hardware
	functionality is required.  Hardware virtualized domains
	require Extended Page Table (<link
	  xlink:href="http://en.wikipedia.org/wiki/Extended_Page_Table">EPT</link>)
	and Input/Output Memory Management Unit (<link
	  xlink:href="http://en.wikipedia.org/wiki/List_of_IOMMU-supporting_hardware">IOMMU</link>)
	support in the host processor.</para>

      <note>
	<para>In order to run a FreeBSD &xen; Dom0 the box must be
	  booted using legacy boot (BIOS).</para>
      </note>

    </sect2>

    <sect2 xml:id="virtualization-host-xen-dom0-setup">
      <title>&xen; Dom0 Control Domain Setup</title>

      <para>Users of &os;&nbsp;11 should install the
	<package>emulators/xen-kernel47</package> and
	<package>sysutils/xen-tools47</package> packages that are
	based on Xen version 4.7.  Systems running on &os;-12.0 or
	newer can use Xen 4.11 provided by
	<package>emulators/xen-kernel411</package> and
	<package>sysutils/xen-tools411</package>, respectively.</para>

      <para>Configuration files must be edited to prepare the host
	for the Dom0 integration after the Xen packages are installed.
	An entry to <filename>/etc/sysctl.conf</filename> disables the
	limit on how many pages of memory are allowed to be wired.
	Otherwise, DomU VMs with higher memory requirements will not
	run.</para>

      <screen>&prompt.root; <userinput>echo 'vm.max_wired=-1' >> /etc/sysctl.conf</userinput></screen>

      <para>Another memory-related setting involves changing
	<filename>/etc/login.conf</filename>, setting the
	<literal>memorylocked</literal> option to
	<literal>unlimited</literal>.  Otherwise, creating DomU
	domains may fail with <errorname>Cannot allocate
	  memory</errorname> errors.  After making the change to
	<filename>/etc/login.conf</filename>, run
	<command>cap_mkdb</command> to update the capability database.
	See <xref linkend="security-resourcelimits"/> for
	details.</para>

      <screen>&prompt.root; <userinput>sed -i '' -e 's/memorylocked=64K/memorylocked=unlimited/' /etc/login.conf</userinput>
&prompt.root; <userinput>cap_mkdb /etc/login.conf</userinput></screen>

      <para>Add an entry for the &xen; console to
	<filename>/etc/ttys</filename>:</para>

      <screen>&prompt.root; <userinput>echo 'xc0     "/usr/libexec/getty Pc"         xterm   onifconsole  secure' >> /etc/ttys</userinput></screen>

      <para>Selecting a &xen; kernel in
	<filename>/boot/loader.conf</filename> activates the Dom0.
	&xen; also requires resources like CPU and memory from the
	host machine for itself and other DomU domains.  How much CPU
	and memory depends on the individual requirements and hardware
	capabilities.  In this example, 8&nbsp;GB of memory and 4
	virtual CPUs are made available for the Dom0. The serial
	console is also activated and logging options are
	defined.</para>

      <para>The following command is used for Xen 4.7 packages:</para>

      <screen>&prompt.root; <userinput>sysrc -f /boot/loader.conf hw.pci.mcfg=0</userinput>
&prompt.root; <userinput>sysrc -f /boot/loader.conf if_tap_load="YES"</userinput>
&prompt.root; <userinput>sysrc -f /boot/loader.conf xen_kernel="/boot/xen"</userinput>
&prompt.root; <userinput>sysrc -f /boot/loader.conf xen_cmdline="dom0_mem=<replaceable>8192M</replaceable> dom0_max_vcpus=<replaceable>4</replaceable> dom0pvh=1 console=com1,vga com1=115200,8n1 guest_loglvl=all loglvl=all"</userinput></screen>

      <para>For Xen versions 4.11 and higher, the following command
	should be used instead:</para>

      <screen>&prompt.root; <userinput>sysrc -f /boot/loader.conf if_tap_load="YES"</userinput>
&prompt.root; <userinput>sysrc -f /boot/loader.conf xen_kernel="/boot/xen"</userinput>
&prompt.root; <userinput>sysrc -f /boot/loader.conf xen_cmdline="dom0_mem=<replaceable>8192M</replaceable> dom0_max_vcpus=<replaceable>4</replaceable> dom0=pvh console=com1,vga com1=115200,8n1 guest_loglvl=all loglvl=all"</userinput></screen>

	<tip>
	  <para>Log files that &xen; creates for the DomU VMs
	    are stored in <filename>/var/log/xen</filename>.  Please
	    be sure to check the contents of that directory if
	    experiencing issues.</para>
	</tip>

	<para>Activate the xencommons service during system
	  startup:</para>

	<screen>&prompt.root; <userinput>sysrc xencommons_enable=yes</userinput></screen>

	<para>These settings are enough to start a Dom0-enabled
	  system.  However, it lacks network functionality for the
	  DomU machines.  To fix that, define a bridged interface with
	  the main NIC of the system which the DomU VMs can use to
	  connect to the network.  Replace
	  <replaceable>em0</replaceable> with the host network
	  interface name.</para>

	<screen>&prompt.root; <userinput>sysrc cloned_interfaces="bridge0"</userinput>
&prompt.root; <userinput>sysrc ifconfig_bridge0="addm <replaceable>em0</replaceable> SYNCDHCP"</userinput>
&prompt.root; <userinput>sysrc ifconfig_<replaceable>em0</replaceable>="up"</userinput></screen>

	<para>Restart the host to load the &xen; kernel and start the
	  Dom0.</para>

	<screen>&prompt.root; <userinput>reboot</userinput></screen>

	<para>After successfully booting the &xen; kernel and logging
	  into the system again, the &xen; management tool
	  <command>xl</command> is used to show information about the
	  domains.</para>

	<screen>&prompt.root; <userinput>xl list</userinput>
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  8192     4     r-----     962.0</screen>

	<para>The output confirms that the Dom0 (called
	  <literal>Domain-0</literal>) has the ID <literal>0</literal>
	  and is running.  It also has the memory and virtual CPUs
	  that were defined in <filename>/boot/loader.conf</filename>
	  earlier.  More information can be found in the <link
	    xlink:href="https://www.xenproject.org/help/documentation.html">&xen;
	    Documentation</link>.  DomU guest VMs can now be
	  created.</para>
      </sect2>

      <sect2 xml:id="virtualization-host-xen-domu-setup">
	<title>&xen; DomU Guest VM Configuration</title>

	<para>Unprivileged domains consist of a configuration file and
	  virtual or physical hard disks.  Virtual disk storage for
	  the DomU can be files created by &man.truncate.1; or ZFS
	  volumes as described in <xref linkend="zfs-zfs-volume"/>.
	  In this example, a 20&nbsp;GB volume is used.  A VM is
	  created with the ZFS volume, a &os; ISO image, 1&nbsp;GB of
	  RAM and two virtual CPUs.  The ISO installation file is
	  retrieved with &man.fetch.1; and saved locally in a file
	  called <filename>freebsd.iso</filename>.</para>

	<screen>&prompt.root; <userinput>fetch <replaceable>ftp://ftp.freebsd.org/pub/FreeBSD/releases/ISO-IMAGES/<replaceable>12.0</replaceable>/FreeBSD-<replaceable>12.0</replaceable>-RELEASE-amd64-bootonly.iso</replaceable> -o <replaceable>freebsd.iso</replaceable></userinput></screen>

      <para>A ZFS volume of 20&nbsp;GB called
	<filename>xendisk0</filename> is created to serve as the disk
	space for the VM.</para>

      <screen>&prompt.root; <userinput>zfs create -V20G -o volmode=dev zroot/xendisk0</userinput></screen>

      <para>The new DomU guest VM is defined in a file.  Some specific
	definitions like name, keymap, and VNC connection details are
	also defined.  The following <filename>freebsd.cfg</filename>
	contains a minimum DomU configuration for this example:</para>

      <screen>&prompt.root; <userinput>cat freebsd.cfg</userinput>
builder = "hvm" <co xml:id="co-xen-builder"/>
name = "freebsd" <co xml:id="co-xen-name"/>
memory = 1024 <co xml:id="co-xen-memory"/>
vcpus = 2 <co xml:id="co-xen-vcpus"/>
vif = [ 'mac=00:16:3E:74:34:32,bridge=bridge0' ] <co xml:id="co-xen-vif"/>
disk = [
'/dev/zvol/tank/xendisk0,raw,hda,rw', <co xml:id="co-xen-disk"/>
'/root/freebsd.iso,raw,hdc:cdrom,r' <co xml:id="co-xen-cdrom"/>
  ]
vnc = 1 <co xml:id="co-xen-vnc"/>
vnclisten = "0.0.0.0"
serial = "pty"
usbdevice = "tablet"</screen>

      <para>These lines are explained in more detail:</para>

      <calloutlist>
	<callout arearefs="co-xen-builder">
	  <para>This defines what kind of virtualization to use.
	    <literal>hvm</literal> refers to hardware-assisted
	    virtualization or hardware virtual machine.  Guest
	    operating systems can run unmodified on CPUs with
	    virtualization extensions, providing nearly the same
	    performance as running on physical hardware.
	    <literal>generic</literal> is the default value and
	    creates a PV domain.</para>
	</callout>

	<callout arearefs="co-xen-name">
	  <para>Name of this virtual machine to distinguish it from
	    others running on the same Dom0.  Required.</para>
	</callout>

	<callout arearefs="co-xen-memory">
	  <para>Quantity of RAM in megabytes to make available to the
	    VM.  This amount is subtracted from the hypervisor's total
	    available memory, not the memory of the Dom0.</para>
	</callout>

	<callout arearefs="co-xen-vcpus">
	  <para>Number of virtual CPUs available to the guest VM.  For
	    best performance, do not create guests with more virtual
	    CPUs than the number of physical CPUs on the host.</para>
	</callout>

	<callout arearefs="co-xen-vif">
	  <para>Virtual network adapter.  This is the bridge connected
	    to the network interface of the host.  The
	    <literal>mac</literal> parameter is the MAC address set on
	    the virtual network interface.  This parameter is
	    optional, if no MAC is provided &xen; will generate a
	    random one.</para>
	</callout>

	<callout arearefs="co-xen-disk">
	  <para>Full path to the disk, file, or ZFS volume of the disk
	    storage for this VM.  Options and multiple disk
	    definitions are separated by commas.</para>
	</callout>

	<callout arearefs="co-xen-cdrom">
	  <para>Defines the Boot medium from which the initial
	    operating system is installed.  In this example, it is the
	    ISO imaged downloaded earlier.  Consult the &xen;
	    documentation for other kinds of devices and options to
	    set.</para>
	</callout>

	<callout arearefs="co-xen-vnc">
	  <para>Options controlling VNC connectivity to the serial
	    console of the DomU.  In order, these are: active VNC
	    support, define IP address on which to listen, device node
	    for the serial console, and the input method for precise
	    positioning of the mouse and other input methods.
	    <literal>keymap</literal> defines which keymap to use, and
	    is <literal>english</literal> by default.</para>
	</callout>
      </calloutlist>

      <para>After the file has been created with all the necessary
	options, the DomU is created by passing it to <command>xl
	  create</command> as a parameter.</para>

      <screen>&prompt.root; <userinput>xl create freebsd.cfg</userinput></screen>

      <note>
	<para>Each time the Dom0 is restarted, the configuration file
	  must be passed to <command>xl create</command> again to
	  re-create the DomU.  By default, only the Dom0 is created
	  after a reboot, not the individual VMs.  The VMs can
	  continue where they left off as they stored the operating
	  system on the virtual disk.  The virtual machine
	  configuration can change over time (for example, when adding
	  more memory).  The virtual machine configuration files must
	  be properly backed up and kept available to be able to
	  re-create the guest VM when needed.</para>
      </note>

      <para>The output of <command>xl list</command> confirms that the
	DomU has been created.</para>

      <screen>&prompt.root; <userinput>xl list</userinput>
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  8192     4     r-----  1653.4
freebsd                                      1  1024     1     -b----   663.9</screen>

      <para>To begin the installation of the base operating system,
	start the VNC client, directing it to the main network address
	of the host or to the IP address defined on the
	<literal>vnclisten</literal> line of
	<filename>freebsd.cfg</filename>.  After the operating system
	has been installed, shut down the DomU and disconnect the VNC
	viewer.  Edit <filename>freebsd.cfg</filename>, removing the
	line with the <literal>cdrom</literal> definition or
	commenting it out by inserting a <literal>#</literal>
	character at the beginning of the line.  To load this new
	configuration, it is necessary to remove the old DomU with
	<command>xl destroy</command>, passing either the name or the
	id as the parameter.  Afterwards, recreate it using the
	modified <filename>freebsd.cfg</filename>.</para>

      <screen>&prompt.root; <userinput>xl destroy freebsd</userinput>
&prompt.root; <userinput>xl create freebsd.cfg</userinput></screen>

      <para>The machine can then be accessed again using the VNC
	viewer.  This time, it will boot from the virtual disk where
	the operating system has been installed and can be used as a
	virtual machine.</para>
    </sect2>

    <sect2 xml:id="virtualization-host-xen-troubleshooting">
      <title>Troubleshooting</title>

      <para>This section contains basic information in order to help
	troubleshoot issues found when using &os; as a &xen; host or
	guest.</para>

      <sect3 xml:id="virtualization-host-xen-troubleshooting-host">
	<title>Host Boot Troubleshooting</title>

	<para>Please note that the following troubleshooting tips
	  are intended for &xen; 4.11 or newer.  If you are still
	  using &xen; 4.7 and having issues consider migrating to
	  a newer version of &xen;.</para>

	<para>In order to troubleshoot host boot issues you will
	  likely need a serial cable, or a debug USB cable.  Verbose
	  &xen; boot output can be obtained by adding options to the
	  <literal>xen_cmdline</literal> option found in
	  <filename>loader.conf</filename>.  A couple of relevant
	  debug options are:</para>

	<itemizedlist>
	  <listitem>
	    <para><literal>iommu=debug</literal>: can be used to print
	      additional diagnostic information about the
	      iommu.</para>
	  </listitem>
	  <listitem>
	    <para><literal>dom0=verbose</literal>: can be used to
	      print additional diagnostic information about the
	      dom0 build process.</para>
	  </listitem>
	  <listitem>
	    <para><literal>sync_console</literal>: flag to force
	      synchronous console output.  Useful for debugging to
	      avoid losing messages due to rate limiting.
	      Never use this option in production environments since
	      it can allow malicious guests to perform DoS attacks
	      against &xen; using the console.</para>
	  </listitem>
	</itemizedlist>

	<para>&os; should also be booted in verbose mode in order
	  to identify any issues.  To activate verbose booting, run
	  this command:</para>

	<screen>&prompt.root; <userinput>sysrc -f /boot/loader.conf boot_verbose="YES"</userinput></screen>

	<para>If none of these options help solving the problem,
	  please send the serial boot log to
	  <email>freebsd-xen@FreeBSD.org</email> and
	  <email>xen-devel@lists.xenproject.org</email>
	  for further analysis.</para>
      </sect3>

      <sect3 xml:id="virtualization-host-xen-troubleshooting-guest">
	<title>Guest Creation Troubleshooting</title>

	<para>Issues can also arise when creating guests, the
	  following attempts to provide some help for those trying
	  to diagnose guest creation issues.</para>

	<para>The most common cause of guest creation failures is the
	  <literal>xl</literal> command spitting some error and
	  exiting with a return code different than 0.  If the error
	  provided is not enough to help identify the issue, more
	  verbose output can also be obtained from
	  <literal>xl</literal> by using the <literal>v</literal>
	  option repeatedly.</para>

	<screen>&prompt.root; <userinput>xl -vvv create freebsd.cfg</userinput>
Parsing config from freebsd.cfg
libxl: debug: libxl_create.c:1693:do_domain_create: Domain 0:ao 0x800d750a0: create: how=0x0 callback=0x0 poller=0x800d6f0f0
libxl: debug: libxl_device.c:397:libxl__device_disk_set_backend: Disk vdev=xvda spec.backend=unknown
libxl: debug: libxl_device.c:432:libxl__device_disk_set_backend: Disk vdev=xvda, using backend phy
libxl: debug: libxl_create.c:1018:initiate_domain_create: Domain 1:running bootloader
libxl: debug: libxl_bootloader.c:328:libxl__bootloader_run: Domain 1:not a PV/PVH domain, skipping bootloader
libxl: debug: libxl_event.c:689:libxl__ev_xswatch_deregister: watch w=0x800d96b98: deregister unregistered
domainbuilder: detail: xc_dom_allocate: cmdline="", features=""
domainbuilder: detail: xc_dom_kernel_file: filename="/usr/local/lib/xen/boot/hvmloader"
domainbuilder: detail: xc_dom_malloc_filemap    : 326 kB
libxl: debug: libxl_dom.c:988:libxl__load_hvm_firmware_module: Loading BIOS: /usr/local/share/seabios/bios.bin
...</screen>

	<para>If the verbose output does not help diagnose the issue
	  there are also QEMU and &xen; toolstack logs in
	  <filename>/var/log/xen</filename>.  Note that the name of
	  the domain is appended to the log name, so if the domain
	  is named <literal>freebsd</literal> you should find a
	  <filename>/var/log/xen/xl-freebsd.log</filename> and likely
	  a <filename>/var/log/xen/qemu-dm-freebsd.log</filename>.
	  Both log files can contain useful information for debugging.
	  If none of this helps solve the issue, please send the
	  description of the issue you are facing and as much
	  information as possible to
	  <email>freebsd-xen@FreeBSD.org</email> and
	  <email>xen-devel@lists.xenproject.org</email> in order to
	  get help.</para>
      </sect3>
    </sect2>
  </sect1>
</chapter>