b4346b9b2d
- Reflect the rename in referencing files Approved by: doceng (implicit)
905 lines
29 KiB
XML
905 lines
29 KiB
XML
<?xml version="1.0" encoding="big5" standalone="no"?>
|
||
<!--
|
||
The FreeBSD Documentation Project
|
||
The FreeBSD Traditional Chinese Documentation Project
|
||
|
||
$FreeBSD$
|
||
Original revision: 1.16
|
||
-->
|
||
|
||
<chapter id="virtualization">
|
||
<chapterinfo>
|
||
<authorgroup>
|
||
<author>
|
||
<firstname>Murray</firstname>
|
||
<surname>Stokely</surname>
|
||
<contrib>Contributed by </contrib>
|
||
</author>
|
||
</authorgroup>
|
||
<!-- Mar 2007 -->
|
||
</chapterinfo>
|
||
|
||
<title>Virtualization(虛擬機器)</title>
|
||
|
||
<sect1 id="virtualization-synopsis">
|
||
<title>Synopsis</title>
|
||
|
||
<para>虛擬機器軟體可以讓同一台機器得以同時執行多種作業系統。 在 PC 上,
|
||
通常這類系統都是在宿主(host)機器上裝虛擬機器軟體,來跑一堆 guest OS
|
||
。</para>
|
||
|
||
<para>讀完這章,您將了解︰</para>
|
||
|
||
<itemizedlist>
|
||
<listitem>
|
||
<para>host OS 以及 guest OS 的區別。</para>
|
||
</listitem>
|
||
|
||
<listitem>
|
||
<para>如何在搭載 &intel; CPU 的 &apple; &macintosh; 電腦上安裝 FreeBSD
|
||
。</para>
|
||
</listitem>
|
||
|
||
<listitem>
|
||
<para>如何在 Linux 上以 <application>&xen;</application> 來安裝
|
||
FreeBSD。</para>
|
||
</listitem>
|
||
|
||
<listitem>
|
||
<para>如何在 µsoft.windows; 上以 <application>Virtual PC</application>
|
||
安裝 FreeBSD。</para>
|
||
</listitem>
|
||
|
||
<listitem>
|
||
<para>如何在虛擬機器對 FreeBSD 系統作性能調校,以取得最佳效能。</para>
|
||
</listitem>
|
||
|
||
</itemizedlist>
|
||
|
||
<para>在開始閱讀這章之前,您需要︰</para>
|
||
|
||
<itemizedlist>
|
||
<listitem>
|
||
<para>瞭解 &unix; 及 FreeBSD 相關基本概念
|
||
(<xref linkend="basics"/>)。</para>
|
||
</listitem>
|
||
|
||
<listitem><para>知道如何安裝 FreeBSD(<xref
|
||
linkend="install"/>)。</para></listitem>
|
||
|
||
<listitem><para>知道如何設定網路(<xref
|
||
linkend="advanced-networking"/>)。</para></listitem>
|
||
|
||
<listitem><para>知道如何以 ports/packages 來安裝應用程式
|
||
(<xref linkend="ports"/>)。</para></listitem>
|
||
</itemizedlist>
|
||
|
||
</sect1>
|
||
|
||
|
||
|
||
<sect1 id="virtualization-guest">
|
||
<title>安裝 FreeBSD 為 Guest OS</title>
|
||
|
||
<sect2 id="virtualization-guest-parallels">
|
||
<title>MacOS 上的 Parallels</title>
|
||
|
||
<para>&mac; 版的 <application>Parallels Desktop</application>
|
||
乃是可用於搭配 &intel; CPU 以及 &macos; 10.4.6 以上的 &apple; &mac;
|
||
電腦的商業軟體。 FreeBSD 是其有完整支援的 guest OS 之一。 在
|
||
&macos; X 裝好 <application>Parallels</application> 後,
|
||
必須針對所欲安裝的 guest OS 來作相關的虛擬機器設定。</para>
|
||
|
||
<sect3 id="virtualization-guest-parallels-install">
|
||
<title>在 Parallels/&macos; X 上安裝 FreeBSD</title>
|
||
|
||
<para>在 &macos; X/<application>Parallels</application> 上安裝 FreeBSD
|
||
的第一步是新增虛擬機器。 如下所示,在提示視窗內請將
|
||
<guimenu>Guest OS Type</guimenu> 勾選為
|
||
<guimenuitem>FreeBSD</guimenuitem>:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/parallels-freebsd1"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>並依據自身需求來規劃硬碟容量跟記憶體的分配。 對大多數在
|
||
<application>Parallels</application> 使用的情況而言,大約 4GB
|
||
硬碟以及 512MB RAM 就夠用了:</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>接下來,選擇網路種類以及網路卡:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/parallels-freebsd6"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/parallels-freebsd7"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>最後,儲存設定檔就完成設定了:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/parallels-freebsd8"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/parallels-freebsd9"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>在 FreeBSD 虛擬機器新增後,就可以繼續以其安裝 FreeBSD。
|
||
安裝方面,比較好的作法是使用官方的 FreeBSD 光碟或者從官方 FTP
|
||
站下載 ISO image 檔。 若您的 &mac; 本機已經有該 ISO 檔,
|
||
或者 &mac; 的光碟機內有放安裝片,那麼就可以在 FreeBSD 的
|
||
<application>Parallels</application> 視窗右下角按下光碟片圖示。
|
||
接著會出現一個視窗,可以把虛擬機器內的光碟機設定到該 ISO 檔,
|
||
或者是實體光碟機。</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/parallels-freebsd11"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>設好光碟片來源之後,就可以按下重開機圖示以重開 FreeBSD
|
||
虛擬機器。 <application>Parallels</application> 會以特殊 BIOS
|
||
開機,並與普通的 BIOS 一樣會先檢查是否有光碟機。</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/parallels-freebsd10"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>此時,它就會找到 FreeBSD 安裝片,並開始在 <xref
|
||
linkend="install"/> 內所介紹到的
|
||
<application>sysinstall</application> 安裝過程。 這時候也可順便裝
|
||
X11,但先不要進行相關設定。</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/parallels-freebsd12"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>完成安裝過程之後,就可以重開剛裝的 FreeBSD 虛擬機器。</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/parallels-freebsd13"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
</sect3>
|
||
|
||
<sect3 id="virtualization-guest-parallels-configure">
|
||
<title>在 &macos; X/Parallels 上設定 FreeBSD</title>
|
||
|
||
<para>把 FreeBSD 成功裝到 &macos; X 的
|
||
<application>Parallels</application> 之後,還需要作一些設定步驟,
|
||
以便將虛擬機器內的 FreeBSD 最佳化。</para>
|
||
|
||
<procedure>
|
||
<step>
|
||
<title>設定 boot loader 參數</title>
|
||
|
||
<para>最重要的步驟乃是藉由調降 <option>kern.hz</option> 來降低
|
||
<application>Parallels</application> 環境內 FreeBSD 的 CPU
|
||
佔用率。 可以在 <filename>/boot/loader.conf</filename>
|
||
內加上下列設定即可:</para>
|
||
|
||
<programlisting>kern.hz=100</programlisting>
|
||
|
||
<para>若不作這設定,那麼光是 idle 狀態的 FreeBSD
|
||
(<application>Parallels</application> guest OS)
|
||
就會在僅單一處理器的 &imac; 上佔了大約 15% 的 CPU 佔用率。
|
||
作上述修改之後,佔用率就會降至大約 5%。</para>
|
||
</step>
|
||
|
||
<step>
|
||
<title>設定新的 kernel 設定檔</title>
|
||
|
||
<para>可以放心把所有 SCSI、FireWire、USB
|
||
相關設備都移除。 <application>Parallels</application>
|
||
有提供 &man.ed.4; 的虛擬網卡,因此,除了 &man.ed.4; 以及
|
||
&man.miibus.4; 以外的其他網路卡也都可以從 kernel 中移除。</para>
|
||
</step>
|
||
|
||
<step>
|
||
<title>設定網路</title>
|
||
|
||
<para>可以替虛擬機器簡單用 DHCP 來設定與 &mac; 相同的 LAN
|
||
網路環境,只要在 <filename>/etc/rc.conf</filename>
|
||
內加上 <literal>ifconfig_ed0="DHCP"</literal> 即可完成。
|
||
其他進階的網路設定方式,請參考 <xref
|
||
linkend="advanced-networking"/>。</para>
|
||
</step>
|
||
</procedure>
|
||
|
||
</sect3>
|
||
|
||
</sect2>
|
||
|
||
<sect2 id="virtualization-guest-xen">
|
||
<sect2info>
|
||
<authorgroup>
|
||
<author>
|
||
<firstname>Fukang</firstname>
|
||
<surname>Chen (Loader)</surname>
|
||
<contrib>Contributed by </contrib>
|
||
</author>
|
||
</authorgroup>
|
||
<!-- Mar/Apr 2007 -->
|
||
</sect2info>
|
||
|
||
<title>在 Linux 透過 &xen; 跑 FreeBSD</title>
|
||
|
||
<para><application>&xen;</application> hypervisor 乃是開放源碼的
|
||
paravirtualization 產品,並由商業公司(XenSource)提供支援。
|
||
Guest OS 通常被稱為 domU domains,而 host OS 則是被稱為 dom0。
|
||
在 Linux 上建立 FreeBSD 虛擬機器的第一步,則是安裝 Linux dom0 的
|
||
<application>&xen;</application>。 在本例中, host OS 乃是 Slackware
|
||
Linux。</para>
|
||
|
||
<sect3 id="xen-slackware-dom0">
|
||
<title>在 Linux dom0 上設定 &xen; 3</title>
|
||
|
||
<procedure>
|
||
<step>
|
||
<title>從 XenSource 網站下載 &xen; 3.0</title>
|
||
|
||
<para>從 <ulink url="http://www.xensource.com/"></ulink> 下載
|
||
<ulink
|
||
url="http://bits.xensource.com/oss-xen/release/3.0.4-1/src.tgz/xen-3.0.4_1-src.tgz">xen-3.0.4_1-src.tgz</ulink>。</para>
|
||
|
||
</step>
|
||
|
||
<step>
|
||
<title>解壓縮</title>
|
||
|
||
<screen>&prompt.root; <userinput>cd xen-3.0.4_1-src</userinput>
|
||
&prompt.root; <userinput>KERNELS="linux-2.6-xen0 linux-2.6-xenU" make world</userinput>
|
||
&prompt.root; <userinput>make install</userinput></screen>
|
||
|
||
<note>
|
||
<para>為 dom0 重新編譯 kernel:</para>
|
||
|
||
<screen>&prompt.root; <userinput>cd xen-3.0.4_1-src/linux-2.6.16.33-xen0</userinput>
|
||
&prompt.root; <userinput>make menuconfig</userinput>
|
||
&prompt.root; <userinput>make</userinput>
|
||
&prompt.root; <userinput>make install</userinput></screen>
|
||
|
||
<para>舊版的 <application>&xen;</application> 可能需要用
|
||
<command>make ARCH=xen menuconfig</command></para>
|
||
</note>
|
||
</step>
|
||
|
||
<step>
|
||
<title>增加選項到 Grub 的 menu.lst 選單</title>
|
||
|
||
<para>修改 <filename>/boot/grub/menu.lst</filename>
|
||
加上下列設定:</para>
|
||
|
||
<programlisting>title Xen-3.0.4
|
||
root (hd0,0)
|
||
kernel /boot/xen-3.0.4-1.gz dom0_mem=262144
|
||
module /boot/vmlinuz-2.6.16.33-xen0 root=/dev/hda1 ro</programlisting>
|
||
</step>
|
||
|
||
<step>
|
||
<title>重開機並進入 &xen;</title>
|
||
|
||
<para>首先,修改
|
||
<filename>/etc/xen/xend-config.sxp</filename>
|
||
加上下列設定:</para>
|
||
|
||
<programlisting>(network-script 'network-bridge netdev=eth0')</programlisting>
|
||
|
||
<para>接下來,就可以啟動 <application>&xen;</application>:</para>
|
||
|
||
<screen>&prompt.root; <userinput>/etc/init.d/xend start</userinput>
|
||
&prompt.root; <userinput>/etc/init.d/xendomains start</userinput></screen>
|
||
|
||
<para>現在 dom0 已經開始運作:</para>
|
||
|
||
<screen>&prompt.root; <userinput>xm list</userinput>
|
||
Name ID Mem VCPUs State Time(s)
|
||
Domain-0 0 256 1 r----- 54452.9</screen>
|
||
</step>
|
||
</procedure>
|
||
</sect3>
|
||
|
||
<sect3>
|
||
<title>FreeBSD 7-CURRENT domU</title>
|
||
|
||
<para>從 <ulink
|
||
url="http://www.fsmware.com/">http://www.fsmware.com/</ulink>
|
||
下載搭配 <application>&xen; 3.0</application> 的 FreeBSD domU
|
||
kernel 相關檔案</para>
|
||
|
||
<itemizedlist>
|
||
<listitem>
|
||
<para><ulink url="http://www.fsmware.com/xenofreebsd/7.0/download/kernel-current">kernel-current</ulink></para>
|
||
</listitem>
|
||
|
||
<listitem>
|
||
<para><ulink url="http://www.fsmware.com/xenofreebsd/7.0/download/mdroot-7.0.bz2">mdroot-7.0.bz2</ulink></para>
|
||
</listitem>
|
||
|
||
<listitem>
|
||
<para><ulink url="http://www.fsmware.com/xenofreebsd/7.0/download/config/xmexample1.bsd">xmexample1.bsd</ulink></para>
|
||
</listitem>
|
||
</itemizedlist>
|
||
|
||
<para>把 <filename>xmexample1.bsd</filename> 設定檔放到
|
||
<filename>/etc/xen/</filename>,並修改 kernel 及 disk image 相關位置。
|
||
以下是示範的例子:</para>
|
||
|
||
<programlisting>kernel = "/opt/kernel-current"
|
||
memory = 256
|
||
name = "freebsd"
|
||
vif = [ '' ]
|
||
disk = [ 'file:/opt/mdroot-7.0,hda1,w' ]
|
||
#on_crash = 'preserve'
|
||
extra = "boot_verbose"
|
||
extra += ",boot_single"
|
||
extra += ",kern.hz=100"
|
||
extra += ",vfs.root.mountfrom=ufs:/dev/xbd769a"</programlisting>
|
||
|
||
<para>其中 <filename>mdroot-7.0.bz2</filename> 檔要記得解壓縮之。</para>
|
||
|
||
<para>接下來,要修改 <filename>kernel-current</filename> 設定檔的
|
||
__xen_guest 小節,並加上 <application>&xen; 3.0.3</application> 所需的
|
||
VIRT_BASE:</para>
|
||
|
||
<screen>&prompt.root; <userinput>objcopy kernel-current -R __xen_guest</userinput>
|
||
&prompt.root; <userinput>perl -e 'print "LOADER=generic,GUEST_OS=freebsd,GUEST_VER=7.0,XEN_VER=xen-3.0,BSD_SYMTAB,VIRT_BASE=0xC0000000\x00"' > tmp</userinput>
|
||
&prompt.root; <userinput>objcopy kernel-current --add-section __xen_guest=tmp</userinput></screen>
|
||
|
||
<screen>&prompt.root; <userinput>objdump -j __xen_guest -s kernel-current</userinput>
|
||
|
||
kernel-current: file format elf32-i386
|
||
|
||
Contents of section __xen_guest:
|
||
0000 4c4f4144 45523d67 656e6572 69632c47 LOADER=generic,G
|
||
0010 55455354 5f4f533d 66726565 6273642c UEST_OS=freebsd,
|
||
0020 47554553 545f5645 523d372e 302c5845 GUEST_VER=7.0,XE
|
||
0030 4e5f5645 523d7865 6e2d332e 302c4253 N_VER=xen-3.0,BS
|
||
0040 445f5359 4d544142 2c564952 545f4241 D_SYMTAB,VIRT_BA
|
||
0050 53453d30 78433030 30303030 3000 SE=0xC0000000. </screen>
|
||
|
||
<para>現在可以新增並啟動 domU 囉:</para>
|
||
|
||
<screen>&prompt.root; <userinput>xm create /etc/xen/xmexample1.bsd -c</userinput>
|
||
Using config file "/etc/xen/xmexample1.bsd".
|
||
Started domain freebsd
|
||
WARNING: loader(8) metadata is missing!
|
||
Copyright (c) 1992-2006 The FreeBSD Project.
|
||
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
|
||
The Regents of the University of California. All rights reserved.
|
||
FreeBSD 7.0-CURRENT #113: Wed Jan 4 06:25:43 UTC 2006
|
||
kmacy@freebsd7.gateway.2wire.net:/usr/home/kmacy/p4/freebsd7_xen3/src/sys/i386-xen/compile/XENCONF
|
||
WARNING: DIAGNOSTIC option enabled, expect reduced performance.
|
||
Xen reported: 1796.927 MHz processor.
|
||
Timecounter "ixen" frequency 1796927000 Hz quality 0
|
||
CPU: Intel(R) Pentium(R) 4 CPU 1.80GHz (1796.93-MHz 686-class CPU)
|
||
Origin = "GenuineIntel" Id = 0xf29 Stepping = 9
|
||
Features=0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,
|
||
DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
|
||
Features2=0x4400<CNTX-ID,<b14>>
|
||
real memory = 265244672 (252 MB)
|
||
avail memory = 255963136 (244 MB)
|
||
xc0: <Xen Console> on motherboard
|
||
cpu0 on motherboard
|
||
Timecounters tick every 10.000 msec
|
||
[XEN] Initialising virtual ethernet driver.
|
||
xn0: Ethernet address: 00:16:3e:6b:de:3a
|
||
[XEN]
|
||
Trying to mount root from ufs:/dev/xbd769a
|
||
WARNING: / was not properly dismounted
|
||
Loading configuration files.
|
||
No suitable dump device was found.
|
||
Entropy harvesting: interrupts ethernet point_to_point kickstart.
|
||
Starting file system checks:
|
||
/dev/xbd769a: 18859 files, 140370 used, 113473 free (10769 frags, 12838 blocks, 4.2% fragmentation)
|
||
Setting hostname: demo.freebsd.org.
|
||
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
|
||
inet6 ::1 prefixlen 128
|
||
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
|
||
inet 127.0.0.1 netmask 0xff000000
|
||
Additional routing options:.
|
||
Mounting NFS file systems:.
|
||
Starting syslogd.
|
||
/etc/rc: WARNING: Dump device does not exist. Savecore not run.
|
||
ELF ldconfig path: /lib /usr/lib /usr/lib/compat /usr/X11R6/lib /usr/local/lib
|
||
a.out ldconfig path: /usr/lib/aout /usr/lib/compat/aout /usr/X11R6/lib/aout
|
||
Starting usbd.
|
||
usb: Kernel module not available: No such file or directory
|
||
Starting local daemons:.
|
||
Updating motd.
|
||
Starting sshd.
|
||
Initial i386 initialization:.
|
||
Additional ABI support: linux.
|
||
Starting cron.
|
||
Local package initialization:.
|
||
Additional TCP options:.
|
||
Starting background file system checks in 60 seconds.
|
||
|
||
Sun Apr 1 02:11:43 UTC 2007
|
||
|
||
FreeBSD/i386 (demo.freebsd.org) (xc0)
|
||
|
||
login: </screen>
|
||
|
||
<para>現在 domU 應該可以跑 &os; 7.0-CURRENT kernel:</para>
|
||
|
||
<screen>&prompt.root; <userinput>uname -a</userinput>
|
||
FreeBSD demo.freebsd.org 7.0-CURRENT FreeBSD 7.0-CURRENT #113: Wed Jan 4 06:25:43 UTC 2006
|
||
kmacy@freebsd7.gateway.2wire.net:/usr/home/kmacy/p4/freebsd7_xen3/src/sys/i386-xen/compile/XENCONF i386</screen>
|
||
|
||
<para>接下來是設定 domU 的網路,&os; domU 會用代號為
|
||
<devicename>xn0</devicename> 的特殊網路卡:</para>
|
||
|
||
<screen>&prompt.root; <userinput>ifconfig xn0 10.10.10.200 netmask 255.0.0.0</userinput>
|
||
&prompt.root; <userinput>ifconfig</userinput>
|
||
xn0: flags=843<UP,BROADCAST,RUNNING,SIMPLEX> mtu 1500
|
||
inet 10.10.10.200 netmask 0xff000000 broadcast 10.255.255.255
|
||
ether 00:16:3e:6b:de:3a
|
||
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
|
||
inet6 ::1 prefixlen 128
|
||
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
|
||
inet 127.0.0.1 netmask 0xff000000 </screen>
|
||
|
||
<para>在 dom0 Slackware 上應該會出現一些 <application>&xen;</application>
|
||
專用的網路卡:</para>
|
||
|
||
<screen>&prompt.root; <userinput>ifconfig</userinput>
|
||
eth0 Link encap:Ethernet HWaddr 00:07:E9:A0:02:C2
|
||
inet addr:10.10.10.130 Bcast:0.0.0.0 Mask:255.0.0.0
|
||
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
||
RX packets:815 errors:0 dropped:0 overruns:0 frame:0
|
||
TX packets:1400 errors:0 dropped:0 overruns:0 carrier:0
|
||
collisions:0 txqueuelen:0
|
||
RX bytes:204857 (200.0 KiB) TX bytes:129915 (126.8 KiB)
|
||
|
||
lo Link encap:Local Loopback
|
||
inet addr:127.0.0.1 Mask:255.0.0.0
|
||
UP LOOPBACK RUNNING MTU:16436 Metric:1
|
||
RX packets:99 errors:0 dropped:0 overruns:0 frame:0
|
||
TX packets:99 errors:0 dropped:0 overruns:0 carrier:0
|
||
collisions:0 txqueuelen:0
|
||
RX bytes:9744 (9.5 KiB) TX bytes:9744 (9.5 KiB)
|
||
|
||
peth0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
|
||
UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
|
||
RX packets:1853349 errors:0 dropped:0 overruns:0 frame:0
|
||
TX packets:952923 errors:0 dropped:0 overruns:0 carrier:0
|
||
collisions:0 txqueuelen:1000
|
||
RX bytes:2432115831 (2.2 GiB) TX bytes:86528526 (82.5 MiB)
|
||
Base address:0xc000 Memory:ef020000-ef040000
|
||
|
||
vif0.1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
|
||
UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
|
||
RX packets:1400 errors:0 dropped:0 overruns:0 frame:0
|
||
TX packets:815 errors:0 dropped:0 overruns:0 carrier:0
|
||
collisions:0 txqueuelen:0
|
||
RX bytes:129915 (126.8 KiB) TX bytes:204857 (200.0 KiB)
|
||
|
||
vif1.0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
|
||
UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
|
||
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
|
||
TX packets:2 errors:0 dropped:157 overruns:0 carrier:0
|
||
collisions:0 txqueuelen:1
|
||
RX bytes:140 (140.0 b) TX bytes:158 (158.0 b)
|
||
|
||
xenbr1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
|
||
UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
|
||
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
|
||
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
|
||
collisions:0 txqueuelen:0
|
||
RX bytes:112 (112.0 b) TX bytes:0 (0.0 b)</screen>
|
||
|
||
<screen>&prompt.root; <userinput>brctl show</userinput>
|
||
bridge name bridge id STP enabled interfaces
|
||
xenbr1 8000.feffffffffff no vif0.1
|
||
peth0
|
||
vif1.0</screen>
|
||
</sect3>
|
||
|
||
</sect2>
|
||
|
||
<sect2 id="virtualization-guest-virtualpc">
|
||
<title>&windows; 上的 Virtual PC</title>
|
||
|
||
<para><application>Virtual PC</application> 是 µsoft; 的
|
||
&windows; 軟體產品,可以免費下載使用。 相關系統需求,請參閱 <ulink
|
||
url="http://www.microsoft.com/windows/downloads/virtualpc/sysreq.mspx">
|
||
system requirements</ulink> 說明。 在 µsoft.windows; 裝完
|
||
<application>Virtual PC</application> 之後,
|
||
必須針對所欲安裝的虛擬機器來作相關設定。</para>
|
||
|
||
<sect3 id="virtualization-guest-virtualpc-install">
|
||
<title>在 Virtual PC/µsoft.windows; 上安裝 FreeBSD</title>
|
||
|
||
<para>在 µsoft.windows;/<application>Virtual PC</application>
|
||
上安裝 FreeBSD 的第一步是新增虛擬機器。 如下所示,
|
||
在提示視窗內請選擇 <guimenuitem>Create a virtual
|
||
machine</guimenuitem>:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/virtualpc-freebsd1"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/virtualpc-freebsd2"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>然後在 <guimenuitem>Operating system</guimenuitem> 處選
|
||
<guimenuitem>Other</guimenuitem>:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/virtualpc-freebsd3"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>並依據自身需求來規劃硬碟容量跟記憶體的分配。
|
||
對大多數在 <application>Virtual PC</application> 使用 FreeBSD
|
||
的情況而言,大約 4GB 硬碟空間以及 512MB RAM 就夠用了:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/virtualpc-freebsd4"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/virtualpc-freebsd5"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>儲存設定檔:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/virtualpc-freebsd6"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>接下來選剛剛所新增的 FreeBSD 虛擬機器,並按下
|
||
<guimenu>Settings</guimenu>,以設定網路種類以及網路卡:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/virtualpc-freebsd7"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/virtualpc-freebsd8"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>在 FreeBSD 虛擬機器新增後,就可以繼續以其安裝 FreeBSD。
|
||
安裝方面,比較好的作法是使用官方的 FreeBSD 光碟或者從官方 FTP
|
||
站下載 ISO image 檔。 若您的 &windows; 檔案系統內已經有該 ISO
|
||
檔, 或者光碟機內有放安裝片,那麼就可以在 FreeBSD
|
||
虛擬機器上連按兩下,以開始啟動。 接著在
|
||
<application>Virtual PC</application> 視窗內按
|
||
<guimenu>CD</guimenu> 再按 <guimenu>Capture ISO Image...</guimenu>
|
||
。 接著會出現一個視窗,可以把虛擬機器內的光碟機設定到該 ISO 檔,
|
||
或者是實體光碟機。</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/virtualpc-freebsd9"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/virtualpc-freebsd10"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>設好光碟片來源之後,就可以重開機,也就是先按
|
||
<guimenu>Action</guimenu> 再按 <guimenu>Reset</guimenu> 即可。
|
||
<application>Virtual PC</application> 會以特殊 BIOS 開機,並與普通
|
||
BIOS 一樣會先檢查是否有光碟機。</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/virtualpc-freebsd11"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>此時,它就會找到 FreeBSD 安裝片,並開始在 <xref
|
||
linkend="install"/> 內所介紹到的 <application>sysinstall</application>
|
||
安裝過程。 這時候也可順便裝 X11,但先不要進行相關設定。</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/virtualpc-freebsd12"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>完成安裝之後,記得把光碟片退出或者 ISO image 退片。 最後,
|
||
把裝好的 FreeBSD 虛擬機器重開機即可。</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/virtualpc-freebsd13"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
</sect3>
|
||
|
||
<sect3 id="virtualization-guest-virtualpc-configure">
|
||
<title>調整 µsoft.windows;/Virtual PC 上的 FreeBSD</title>
|
||
|
||
<para>在 µsoft.windows; 上以 <application>Virtual
|
||
PC</application> 裝好 FreeBSD 後,還需要作一些設定步驟,
|
||
以便將虛擬機器內的 FreeBSD 最佳化。</para>
|
||
|
||
<procedure>
|
||
<step>
|
||
<title>設定 boot loader 參數</title>
|
||
|
||
<para>最重要的步驟乃是藉由調降 <option>kern.hz</option> 來降低
|
||
<application>Virtual PC</application> 環境內 FreeBSD 的 CPU
|
||
佔用率。 可以在 <filename>/boot/loader.conf</filename>
|
||
內加上下列設定即可:</para>
|
||
|
||
<programlisting>kern.hz=100</programlisting>
|
||
|
||
<para>若不作這設定,那麼光是 idle 狀態的 FreeBSD
|
||
<application>Virtual PC</application> guest OS
|
||
就會在僅單一處理器的電腦上佔了大約 40% 的 CPU 佔用率。
|
||
作上述修改之後,佔用率就會降至大約 3%。</para>
|
||
</step>
|
||
|
||
<step>
|
||
<title>設定新的 kernel 設定檔</title>
|
||
|
||
<para>可以放心把所有 SCSI、FireWire、USB 相關設備都移除。
|
||
<application>Virtual PC</application> 有提供 &man.de.4;
|
||
的虛擬網卡,因此除了 &man.de.4; 以及 &man.miibus.4;
|
||
以外的其他網路卡也都可以從 kernel 中移除。</para>
|
||
</step>
|
||
|
||
<step>
|
||
<title>設定網路</title>
|
||
|
||
<para>可以替虛擬機器簡單用 DHCP 來設定與 host(µsoft.windows;)
|
||
相同的 LAN 網路環境,只要在 <filename>/etc/rc.conf</filename>
|
||
加上 <literal>ifconfig_de0="DHCP"</literal> 即可完成。
|
||
其他進階的網路設定方式,請參閱 <xref
|
||
linkend="advanced-networking"/>。</para>
|
||
</step>
|
||
</procedure>
|
||
|
||
</sect3>
|
||
|
||
</sect2>
|
||
|
||
<sect2 id="virtualization-guest-vmware">
|
||
<title>在 MacOS 上的 VMware</title>
|
||
|
||
<para>&mac; 上的 <application>VMWare Fusion</application> 乃是可用於搭配
|
||
&intel; CPU 以及 &macos; 10.4.9 之 &apple; &mac; 以上的 &apple; &mac;
|
||
電腦之商業軟體。 FreeBSD 是其有完整支援的 guest OS 之一。 在 &macos;
|
||
X 上裝完 <application>VMWare Fusion</application> 之後,
|
||
必須針對所欲安裝的 guest OS 來作相關的虛擬機器設定。</para>
|
||
|
||
<sect3 id="virtualization-guest-vmware-install">
|
||
<title>在 VMWare/&macos; X 上安裝 FreeBSD</title>
|
||
|
||
<para>首先執行 VMWare Fusion,而其 Virtual Machine Library
|
||
也會隨之一併載入,這時請按 "New" 來建立 VM(虛擬機器):</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/vmware-freebsd01"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>接著會有 New Virtual Machine Assistant 來協助您建立 VM,請按
|
||
Continue 繼續:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/vmware-freebsd02"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>在 <guimenuitem>Operating System</guimenuitem> 選
|
||
<guimenuitem>Other</guimenuitem>,以及 <guimenu>Version</guimenu>
|
||
處請選擇是否要
|
||
<guimenuitem>FreeBSD</guimenuitem> 或
|
||
<guimenuitem>FreeBSD 64-bit</guimenuitem>,這部份請依自身需求是否有要
|
||
64-bit 支援而定:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/vmware-freebsd03"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>接著設定 VM image 檔要存到何處,以及決定名稱:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/vmware-freebsd04"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>決定該 VM 的虛擬硬碟要用多大:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/vmware-freebsd05"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>選擇要裝 VM 的方式為何,要用 ISO image 檔或者光碟機:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/vmware-freebsd06"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>按 Finish 以完畢,接著就會啟動該 VM:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/vmware-freebsd07"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>接著就照以往安裝 &os; 的方式來裝,若不熟的話請參閱
|
||
<xref linkend="install"/>:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/vmware-freebsd08"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>裝完之後,就可以修改一些 VM 設定,像是記憶體大小:</para>
|
||
|
||
<note>
|
||
<para>VM 在運作之時,不能修改 VM 的硬體設定。</para>
|
||
</note>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/vmware-freebsd09"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>調整 VM 的 CPU 數量:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/vmware-freebsd10"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>光碟機狀態,通常不再需要用的時候,就可以切斷其與 VM 的連接:</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/vmware-freebsd11"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>最後要改的則是 VM 的網路設定。 若除了 Host OS 之外的機器也能連到
|
||
VM,那麼請選 <guimenuitem>Connect directly to the physical network
|
||
(Bridged)</guimenuitem>,否則就選 <guimenuitem>Share the host's
|
||
internet connection (NAT)</guimenuitem> 即可讓 VM 連到 Internet,
|
||
但外面則無法連入該 VM。</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="virtualization/vmware-freebsd12"/>
|
||
</imageobject>
|
||
</mediaobject>
|
||
|
||
<para>改完上述設定之後,就可以啟動新裝妥的 FreeBSD 虛擬機器。</para>
|
||
</sect3>
|
||
|
||
<sect3 id="virtualization-guest-vmware-configure">
|
||
<title>調整 &macos; X/VMWare 上的 FreeBSD</title>
|
||
|
||
<para>把 FreeBSD 成功裝到 &macos; X 的 <application>VMWare</application>
|
||
之後,還需要作一些設定步驟, 以便將虛擬機器內的 FreeBSD 最佳化。</para>
|
||
|
||
<procedure>
|
||
<step>
|
||
<title>設定 boot loader 參數</title>
|
||
|
||
<para>最重要的步驟乃是藉由調降 <option>kern.hz</option> 來降低
|
||
<application>VMWare</application> 環境內 FreeBSD 的 CPU 佔用率。
|
||
可以在 <filename>/boot/loader.conf</filename>
|
||
內加上下列設定即可:</para>
|
||
|
||
<programlisting>kern.hz=100</programlisting>
|
||
|
||
<para>若不作這設定,那麼光是 idle 狀態的 FreeBSD
|
||
(<application>VMWare</application> guest OS) 就會在僅單一處理器的
|
||
&imac; 上佔了大約 15% 的 CPU 佔用率。 作上述修改之後,
|
||
佔用率就會降至大約 5%。</para>
|
||
</step>
|
||
|
||
<step>
|
||
<title>設定新的 kernel 設定檔</title>
|
||
|
||
<para>可以放心把所有 FireWire、USB 相關設備都移除。
|
||
<application>VMWare</application> 有提供 &man.em.4; 的虛擬網卡,
|
||
因此,除了 &man.em.4; 以及 &man.miibus.4; 以外的其他網路卡,
|
||
也都可以從 kernel 中移除。</para>
|
||
</step>
|
||
|
||
<step>
|
||
<title>設定網路</title>
|
||
|
||
<para>可以替虛擬機器簡單用 DHCP 來設定與 host &mac; 相同的 LAN
|
||
網路環境,只要在 <filename>/etc/rc.conf</filename> 加上
|
||
<literal>ifconfig_em0="DHCP"</literal> 即可。
|
||
其他進階的網路設定方式,請參考 <xref
|
||
linkend="advanced-networking"/>。</para>
|
||
</step>
|
||
</procedure>
|
||
</sect3>
|
||
</sect2>
|
||
</sect1>
|
||
|
||
<sect1 id="virtualization-host">
|
||
<title>以 FreeBSD 為 Host OS</title>
|
||
|
||
<para>目前,尚未有任何虛擬機器軟體有官方支援 FreeBSD 作為 host OS,
|
||
但蠻多人都有在用舊版 <application>VMware</application> 所提供的這項功能。
|
||
不過,目前已經有人為讓 <application>&xen;</application> 能夠以 FreeBSD
|
||
為 host OS 為目標,而進行相關工作。</para>
|
||
|
||
</sect1>
|
||
|
||
</chapter>
|