|
Lines 20-25
Link Here
|
| 20 |
<contrib>Contributed by </contrib> |
20 |
<contrib>Contributed by </contrib> |
| 21 |
</author> |
21 |
</author> |
| 22 |
</authorgroup> |
22 |
</authorgroup> |
|
|
23 |
|
| 24 |
<authorgroup> |
| 25 |
<author> |
| 26 |
<personname> |
| 27 |
<firstname>Allan</firstname> |
| 28 |
<surname>Jude</surname> |
| 29 |
</personname> |
| 30 |
<contrib>bhyve section by </contrib> |
| 31 |
</author> |
| 32 |
</authorgroup> |
| 23 |
</info> |
33 |
</info> |
| 24 |
|
34 |
|
| 25 |
<sect1 xml:id="virtualization-synopsis"> |
35 |
<sect1 xml:id="virtualization-synopsis"> |
|
Lines 1110-1117
Link Here
|
| 1110 |
</sect2> |
1120 |
</sect2> |
| 1111 |
</sect1> |
1121 |
</sect1> |
| 1112 |
|
1122 |
|
| 1113 |
<sect1 xml:id="virtualization-host"> |
1123 |
<sect1 xml:id="virtualization-host-virtualbox"> |
| 1114 |
<title>&os; as a Host</title> |
1124 |
<title>&os; as a Host with <application>VirtualBox</application></title> |
| 1115 |
|
1125 |
|
| 1116 |
<para><application>&virtualbox;</application> is an actively |
1126 |
<para><application>&virtualbox;</application> is an actively |
| 1117 |
developed, complete virtualization package, that is available |
1127 |
developed, complete virtualization package, that is available |
|
Lines 1273-1279
Link Here
|
| 1273 |
|
1283 |
|
| 1274 |
<screen>&prompt.root; <userinput>service devfs restart</userinput></screen> |
1284 |
<screen>&prompt.root; <userinput>service devfs restart</userinput></screen> |
| 1275 |
</sect2> |
1285 |
</sect2> |
|
|
1286 |
</sect1> |
| 1276 |
|
1287 |
|
|
|
1288 |
<sect1 xml:id="virtualization-host-bhyve"> |
| 1289 |
<title>&os; as a Host with |
| 1290 |
<application>bhyve</application></title> |
| 1291 |
|
| 1292 |
<para>Starting with &os; 10.0-RELEASE the BSD licensed hypervisor |
| 1293 |
<application>bhyve</application> is part of the base system. |
| 1294 |
<application>bhyve</application> supports a number of guests |
| 1295 |
including &os;, OpenBSD, and many flavors of &linux;. |
| 1296 |
<application>bhyve</application> currently only supports a |
| 1297 |
serial console and does not emulate a graphical console. |
| 1298 |
<application>bhyve</application> is a legacy-free hypervisor, |
| 1299 |
meaning that instead of translating instructions, and manually |
| 1300 |
managing memory mappings, it relies on the virtualization |
| 1301 |
offload features of newer <acronym>CPU</acronym>s. |
| 1302 |
<application>bhyve</application> also avoids emulating |
| 1303 |
compatible hardware for the guest, and instead relies on the |
| 1304 |
paravirtualization drivers, called |
| 1305 |
<literal>VirtIO</literal>.</para> |
| 1306 |
|
| 1307 |
<para>Due to the design of <application>bhyve</application>, it is |
| 1308 |
only possible to use <application>bhyve</application> on |
| 1309 |
computers with newer processors that support &intel; |
| 1310 |
<acronym>EPT</acronym> (Extended Page Tables) or &amd; |
| 1311 |
<acronym>RVI</acronym> (Rapid Virtualization Indexing, also know |
| 1312 |
as <acronym>NPT</acronym> or Nested Page Tables). Most newer |
| 1313 |
processors, specifically the &intel; &core; i3/i5/i7 and |
| 1314 |
&intel; &xeon; E3/E5/E7 support this feature, for a |
| 1315 |
complete list of &intel; processors that support |
| 1316 |
<acronym>EPT</acronym> see the <link |
| 1317 |
xlink:href="http://ark.intel.com/search/advanced?s=t&ExtendedPageTables=true">&intel; |
| 1318 |
ARK</link>. <acronym>RVI</acronym> is found on the 3rd |
| 1319 |
generation and later of the &amd.opteron; (Barcelona) |
| 1320 |
processors. The easiest way to check for support of |
| 1321 |
<acronym>EPT</acronym> or <acronym>RVI</acronym> on a system is |
| 1322 |
to look for the <literal>POPCNT</literal> processor feature flag |
| 1323 |
on the <literal>Features2</literal> line in |
| 1324 |
<command>dmesg</command> or |
| 1325 |
<filename>/var/run/dmesg.boot</filename>.</para> |
| 1326 |
|
| 1327 |
<sect2 xml:id="virtualization-bhyve-prep"> |
| 1328 |
<title>Preparing the Host</title> |
| 1329 |
|
| 1330 |
<para>The first step to creating a virtual machine in |
| 1331 |
<application>bhyve</application> is configuring the host |
| 1332 |
system. Load the <application>bhyve</application> kernel |
| 1333 |
module called vmm. Create a <filename>tap</filename> |
| 1334 |
interface for the network device in the virtual machine to |
| 1335 |
attach to. Optionally create a bridge interface and add the |
| 1336 |
<filename>tap</filename> interface as well as the physical |
| 1337 |
interface as members to allow the virtual machine to have |
| 1338 |
access to the network.</para> |
| 1339 |
|
| 1340 |
<screen>&prompt.root; <userinput>kldload vmm</userinput> |
| 1341 |
&prompt.root; <userinput>kldload nmdm</userinput> |
| 1342 |
&prompt.root; <userinput>ifconfig <replaceable>tap0</replaceable> create</userinput> |
| 1343 |
&prompt.root; <userinput>sysctl net.link.tap.up_on_open=1</userinput> |
| 1344 |
net.link.tap.up_on_open: 0 -> 1 |
| 1345 |
&prompt.root; <userinput>ifconfig <replaceable>bridge0</replaceable> create</userinput> |
| 1346 |
&prompt.root; <userinput>ifconfig <replaceable>bridge0</replaceable> addm <replaceable>igb0</replaceable> addm <replaceable>tap0</replaceable></userinput> |
| 1347 |
&prompt.root; <userinput>ifconfig <replaceable>bridge0</replaceable> up</userinput></screen> |
| 1348 |
|
| 1349 |
</sect2> |
| 1350 |
|
| 1351 |
<sect2 xml:id="virtualization-bhyve-freebsd"> |
| 1352 |
<title>Creating a FreeBSD Guest</title> |
| 1353 |
|
| 1354 |
<para>Create a file to use as the virtual disk for the guest |
| 1355 |
machine.</para> |
| 1356 |
|
| 1357 |
<screen>&prompt.root; <userinput>truncate -s <replaceable>16G</replaceable> <filename>guest.img</filename></userinput></screen> |
| 1358 |
|
| 1359 |
<para>Download an installation image of &os; to install:</para> |
| 1360 |
|
| 1361 |
<screen>&prompt.root; <userinput>fetch <replaceable>ftp://ftp.freebsd.org/pub/FreeBSD/ISO-IMAGES-amd64/10.0/FreeBSD-10.0-RELEASE-amd64-bootonly.iso</replaceable></userinput> |
| 1362 |
FreeBSD-10.0-RELEASE-amd64-bootonly.iso 100% of 209 MB 570 kBps 06m17s</screen> |
| 1363 |
|
| 1364 |
<para>&os; comes with an example script for running a virtual |
| 1365 |
machine in <application>bhyve</application>. The script will |
| 1366 |
start the virtual machine and run it in a loop, so it will |
| 1367 |
automatically restart if it crashes. The script takes a |
| 1368 |
number of options to control the configuration of the machine. |
| 1369 |
<option>-c</option> controls the number of virtual CPUs. |
| 1370 |
<option>-m</option> limits the amount of memory available to |
| 1371 |
the guest. <option>-t</option> defines which |
| 1372 |
<filename>tap</filename> device to use. <option>-d</option> |
| 1373 |
indicates which disk image to use. <option>-i</option> tells |
| 1374 |
<application>bhyve</application> to boot from the CD image |
| 1375 |
instead of the disk, and <option>-I</option> defines which CD |
| 1376 |
image to use. Finally the last parameter is the name of the |
| 1377 |
virtual machine, used to track the running machines. Start |
| 1378 |
the virtual machine in installation mode:</para> |
| 1379 |
|
| 1380 |
<screen>&prompt.root; <userinput>sh <filename>/usr/share/examples/bhyve/vmrun.sh</filename> -c <replaceable>4</replaceable> -m <replaceable>1024M</replaceable> -t tap0 -d <filename>guest.img</filename> -i -I <filename>FreeBSD-10.0-RELEASE-amd64-bootonly.iso</filename> <replaceable>guestname</replaceable></userinput></screen> |
| 1381 |
|
| 1382 |
<para>The system will boot and start the installer. After |
| 1383 |
installing a system in the virtual machine, when the system |
| 1384 |
asks about dropping in to a shell at the end of the |
| 1385 |
installation, choose <guibutton>Yes</guibutton>. A small |
| 1386 |
change needs to be made to make the system start with a serial |
| 1387 |
console. Edit <filename>/etc/ttys</filename> and replace the |
| 1388 |
existing <literal>console</literal> line with:</para> |
| 1389 |
|
| 1390 |
<programlisting>console "/usr/libexec/getty std.9600" xterm on secure</programlisting> |
| 1391 |
|
| 1392 |
<para>Reboot the virtual machine. Rebooting the virtual machine |
| 1393 |
causes <application>bhyve</application> to exit. However the |
| 1394 |
<filename>vmrun.sh</filename> script runs |
| 1395 |
<command>bhyve</command> in a loop and will automatically |
| 1396 |
restart it. When this happens, choose the reboot option from |
| 1397 |
the boot loader menu, and this will escape the loop. Now the |
| 1398 |
guest can be started from the virtual disk:</para> |
| 1399 |
|
| 1400 |
<screen>&prompt.root; <userinput>sh <filename>/usr/share/examples/bhyve/vmrun.sh</filename> -c <replaceable>4</replaceable> -m <replaceable>1024M</replaceable> -t tap0 -d <filename>guest.img</filename> <replaceable>guestname</replaceable></userinput></screen> |
| 1401 |
</sect2> |
| 1402 |
|
| 1403 |
<sect2 xml:id="virtualization-bhyve-linux"> |
| 1404 |
<title>Creating a &linux; Guest</title> |
| 1405 |
|
| 1406 |
<note><para><application>bhyve</application> requires |
| 1407 |
<package>sysutils/grub2-bhyve</package> in order to boot |
| 1408 |
operating systems other than &os;.</para></note> |
| 1409 |
|
| 1410 |
<para>Create a file to use as the virtual disk for the guest |
| 1411 |
machine.</para> |
| 1412 |
|
| 1413 |
<screen>&prompt.root; <userinput>truncate -s <replaceable>16G</replaceable> <filename>linux.img</filename></userinput></screen> |
| 1414 |
|
| 1415 |
<para>Starting a virtual machine with |
| 1416 |
<application>bhyve</application> is a two step process. First |
| 1417 |
a kernel must be loaded, then the guest can be started. |
| 1418 |
<package>sysutils/grub2-bhyve</package> is used to load the |
| 1419 |
&linux; kernel. Create a <filename>device.map</filename> that |
| 1420 |
<application>grub</application> will use to map the virtual |
| 1421 |
devices to the files on the host system:</para> |
| 1422 |
|
| 1423 |
<programlisting>(hd0) ./linux.img |
| 1424 |
(cd0) ./somelinux.iso</programlisting> |
| 1425 |
|
| 1426 |
<para>Use <package>sysutils/grub2-bhyve</package> to load the |
| 1427 |
&linux; kernel from the <acronym>ISO</acronym> image:</para> |
| 1428 |
|
| 1429 |
<screen>&prompt.root; <userinput>grub-bhyve -m <filename>device.map</filename> -r cd0 -M <replaceable>1024M</replaceable> <replaceable>linuxguest</replaceable></userinput></screen> |
| 1430 |
|
| 1431 |
<para>This will start grub. If the installation CD contains a |
| 1432 |
<filename>grub.cfg</filename> then a menu will be displayed. |
| 1433 |
If not, the <literal>vmlinuz</literal> and |
| 1434 |
<literal>initrd</literal> files must be located and loaded |
| 1435 |
manually:</para> |
| 1436 |
|
| 1437 |
<screen>grub> <userinput>ls</userinput> |
| 1438 |
(hd0) (cd0) (cd0,msdos1) (host) |
| 1439 |
grub> <userinput>ls (cd0)/isolinux</userinput> |
| 1440 |
boot.cat boot.msg grub.conf initrd.img isolinux.bin isolinux.cfg memtest |
| 1441 |
splash.jpg TRANS.TBL vesamenu.c32 vmlinuz |
| 1442 |
grub> <userinput>linux (cd0)/isolinux/vmlinuz</userinput> |
| 1443 |
grub> <userinput>initrd (cd0)/isolinux/initrd.img</userinput> |
| 1444 |
grub> <userinput>boot</userinput></screen> |
| 1445 |
|
| 1446 |
<para>Now that the &linux; kernel is loaded, the guest can be |
| 1447 |
started:</para> |
| 1448 |
|
| 1449 |
<screen>&prompt.root; <userinput>bhyve -AI -H -P \ |
| 1450 |
-s 0:0,hostbridge \ |
| 1451 |
-s 1:0,lpc \ |
| 1452 |
-s 2:0,virtio-net,tap1 \ |
| 1453 |
-s 3:0,virtio-blk,./linux.img \ |
| 1454 |
-s 4:0,ahci-cd,./somelinux.iso \ |
| 1455 |
-l com1,stdio \ |
| 1456 |
-c <replaceable>4</replaceable> -m <replaceable>1024M</replaceable> <replaceable>linuxguest</replaceable></userinput></screen> |
| 1457 |
|
| 1458 |
<para>The system will boot and start the installer. After |
| 1459 |
installing a system in the virtual machine, reboot the virtual |
| 1460 |
machine. This will cause <application>bhyve</application> to |
| 1461 |
exit. The instance of the virtual machine needs to be |
| 1462 |
destroyed before it can be started again:</para> |
| 1463 |
|
| 1464 |
<screen>&prompt.root; <userinput>bhyvectl --destroy --vm=<replaceable>linuxguest</replaceable></userinput></screen> |
| 1465 |
|
| 1466 |
<para>Now the guest can be started directly from the virtual |
| 1467 |
disk. Load the kernel:</para> |
| 1468 |
|
| 1469 |
<screen>&prompt.root; <userinput>grub-bhyve -m <filename>device.map</filename> -r hd0,msdos1 -M <replaceable>1024M</replaceable> <replaceable>linuxguest</replaceable></userinput> |
| 1470 |
grub> <userinput>ls</userinput> |
| 1471 |
(hd0) (hd0,msdos2) (hd0,msdos1) (cd0) (cd0,msdos1) (host) |
| 1472 |
(lvm/VolGroup-lv_swap) (lvm/VolGroup-lv_root) |
| 1473 |
grub> <userinput>ls (hd0,msdos1)/</userinput> |
| 1474 |
lost+found/ grub/ efi/ System.map-2.6.32-431.el6.x86_64 config-2.6.32-431.el6.x |
| 1475 |
86_64 symvers-2.6.32-431.el6.x86_64.gz vmlinuz-2.6.32-431.el6.x86_64 |
| 1476 |
initramfs-2.6.32-431.el6.x86_64.img |
| 1477 |
grub> <userinput>linux (hd0,msdos1)/vmlinuz-2.6.32-431.el6.x86_64 root=/dev/mapper/VolGroup-lv_root</userinput> |
| 1478 |
grub> <userinput>initrd (hd0,msdos1)/initramfs-2.6.32-431.el6.x86_64.img</userinput> |
| 1479 |
grub> <userinput>boot</userinput></screen> |
| 1480 |
|
| 1481 |
<para>Boot the virtual machine:</para> |
| 1482 |
|
| 1483 |
<screen>&prompt.root; <userinput>bhyve -AI -H -P \ |
| 1484 |
-s 0:0,hostbridge \ |
| 1485 |
-s 1:0,lpc \ |
| 1486 |
-s 2:0,virtio-net,tap1 \ |
| 1487 |
-s 3:0,virtio-blk,./linux.img \ |
| 1488 |
-l com1,stdio \ |
| 1489 |
-c <replaceable>4</replaceable> -m <replaceable>1024M</replaceable> <replaceable>linuxguest</replaceable></userinput></screen> |
| 1490 |
|
| 1491 |
<para>&linux; will now boot in the virtual machine and |
| 1492 |
eventually present you with the login prompt. Login and use |
| 1493 |
the virtual machine. When you are finished, reboot the |
| 1494 |
virtual machine to exit <application>bhyve</application>. |
| 1495 |
Destroy the virtual machine instance:</para> |
| 1496 |
|
| 1497 |
<screen>&prompt.root; <userinput>bhyvectl --destroy --vm=<replaceable>linuxguest</replaceable></userinput></screen> |
| 1498 |
</sect2> |
| 1499 |
|
| 1500 |
<sect2 xml:id="virtualization-bhyve-nmdm"> |
| 1501 |
<title>Virtual Machines Consoles</title> |
| 1502 |
|
| 1503 |
<para>It is advantageous to wrap the |
| 1504 |
<application>bhyve</application> console in a session |
| 1505 |
management tool such as <package>sysutils/tmux</package> or |
| 1506 |
<package>sysutils/screen</package> in order to detach and |
| 1507 |
reattach to the console. It is also possible to have the |
| 1508 |
console of <application>bhyve</application> be a null modem |
| 1509 |
device that can be accessed with <command>cu</command>. Load |
| 1510 |
the <filename>nmdm</filename> kernel module, and replace |
| 1511 |
<option>-l com1,stdio</option> with |
| 1512 |
<option>-l com1,/dev/nmdm0A</option>. The |
| 1513 |
<filename>/dev/nmdm</filename> devices are created |
| 1514 |
automatically as needed, each is a pair, |
| 1515 |
<filename>/dev/nmdm1A</filename> and |
| 1516 |
<filename>/dev/nmdm1B</filename> corresponding to the two ends |
| 1517 |
of the null modem cable. See &man.nmdm.4; for more |
| 1518 |
information.</para> |
| 1519 |
|
| 1520 |
<screen>&prompt.root; <userinput>bhyve -AI -H -P \ |
| 1521 |
-s 0:0,hostbridge \ |
| 1522 |
-s 1:0,lpc \ |
| 1523 |
-s 2:0,virtio-net,tap1 \ |
| 1524 |
-s 3:0,virtio-blk,./linux.img \ |
| 1525 |
-l com1,<replaceable>/dev/nmdm0A</replaceable> \ |
| 1526 |
-c <replaceable>4</replaceable> -m <replaceable>1024M</replaceable> <replaceable>linuxguest</replaceable></userinput> |
| 1527 |
&prompt.root; <userinput>cu -l /dev/nmdm0B -s 9600</userinput> |
| 1528 |
Connected |
| 1529 |
|
| 1530 |
Ubuntu 13.10 handbook ttyS0 |
| 1531 |
|
| 1532 |
handbook login:</screen> |
| 1533 |
|
| 1534 |
</sect2> |
| 1535 |
|
| 1536 |
<sect2 xml:id="virtualization-bhyve-managing"> |
| 1537 |
<title>Managing Virtual Machines</title> |
| 1538 |
|
| 1539 |
<para>A device node is created in <filename |
| 1540 |
role="directory">/dev/vmm</filename> for each virtual |
| 1541 |
machine. This allows the administrator to easily see a list |
| 1542 |
of the running virtual machines:</para> |
| 1543 |
|
| 1544 |
<screen>&prompt.root; <userinput>ls -al /dev/vmm</userinput> |
| 1545 |
total 1 |
| 1546 |
dr-xr-xr-x 2 root wheel 512 Mar 17 12:19 ./ |
| 1547 |
dr-xr-xr-x 14 root wheel 512 Mar 17 06:38 ../ |
| 1548 |
crw------- 1 root wheel 0x1a2 Mar 17 12:20 guestname |
| 1549 |
crw------- 1 root wheel 0x19f Mar 17 12:19 linuxguest |
| 1550 |
crw------- 1 root wheel 0x1a1 Mar 17 12:19 otherguest</screen> |
| 1551 |
|
| 1552 |
<para>Virtual machines can be destroyed using |
| 1553 |
<command>bhyvectl</command>:</para> |
| 1554 |
|
| 1555 |
<screen>&prompt.root; bhyvectl --destroy --vm=guestname</screen> |
| 1556 |
</sect2> |
| 1557 |
|
| 1558 |
<sect2 xml:id="virtualization-bhyve-onboot"> |
| 1559 |
<title>Persistent Configuration</title> |
| 1560 |
|
| 1561 |
<para>In order to make the system able to start |
| 1562 |
<application>bhyve</application> guests at boot time, the |
| 1563 |
following configurations must be made in the specified |
| 1564 |
files:</para> |
| 1565 |
|
| 1566 |
<procedure> |
| 1567 |
<step> |
| 1568 |
<title><filename>/etc/sysctl.conf</filename></title> |
| 1569 |
|
| 1570 |
<programlisting>net.link.tap.up_on_open=1</programlisting> |
| 1571 |
</step> |
| 1572 |
|
| 1573 |
<step> |
| 1574 |
<title><filename>/boot/loader.conf</filename></title> |
| 1575 |
|
| 1576 |
<programlisting>vmm_load="YES" |
| 1577 |
nmdm_load="YES" |
| 1578 |
if_bridge_load="YES" |
| 1579 |
if_tap_load="YES"</programlisting> |
| 1580 |
</step> |
| 1581 |
|
| 1582 |
<step> |
| 1583 |
<title><filename>/etc/rc.conf</filename></title> |
| 1584 |
|
| 1585 |
<programlisting>cloned_interfaces="bridge0 tap0" |
| 1586 |
ifconfig_bridge0="addm igb0 addm tap0"</programlisting> |
| 1587 |
</step> |
| 1588 |
</procedure> |
| 1589 |
</sect2> |
| 1277 |
<!-- |
1590 |
<!-- |
| 1278 |
Note: There is no working/end-user ready Xen support for FreeBSD as of 07-2010. |
1591 |
Note: There is no working/end-user ready Xen support for FreeBSD as of 07-2010. |
| 1279 |
Hide all information regarding Xen under FreeBSD. |
1592 |
Hide all information regarding Xen under FreeBSD. |