369 lines
12 KiB
XML
369 lines
12 KiB
XML
<?xml version="1.0" encoding="big5"?>
|
||
<!--
|
||
The FreeBSD Documentation Project
|
||
$FreeBSD$
|
||
Original revision: 1.21
|
||
|
||
-->
|
||
|
||
<chapter id="GEOM">
|
||
<chapterinfo>
|
||
<authorgroup>
|
||
<author>
|
||
<firstname>Tom</firstname>
|
||
<surname>Rhodes</surname>
|
||
<contrib>Written by </contrib>
|
||
</author>
|
||
</authorgroup>
|
||
</chapterinfo>
|
||
|
||
<title>GEOM: Modular Disk Transformation Framework</title>
|
||
|
||
<sect1 id="GEOM-synopsis">
|
||
<title>概述</title>
|
||
|
||
<indexterm>
|
||
<primary>GEOM</primary>
|
||
</indexterm>
|
||
<indexterm>
|
||
<primary>GEOM Disk Framework</primary>
|
||
<see>GEOM</see>
|
||
</indexterm>
|
||
|
||
<para>本章涵蓋如何在 &os; 的 GEOM 架構下使用磁碟,
|
||
包含用來設定幾種常用的 <acronym
|
||
role="Redundant Array of Inexpensive Disks,磁碟陣列系統">RAID</acronym>
|
||
的控制工具。本章不會深入探討 GEOM 如何處理底層的 I/O,這類資訊請參考
|
||
&man.geom.4; 及相關的 SEE ALSO 部份。本章也非 <acronym>RAID</acronym>
|
||
設定指南,在這裡只會討論目前 GEOM 支援的 <acronym>RAID</acronym> 模式。
|
||
</para>
|
||
|
||
<para>讀完這章,您將了解︰</para>
|
||
<itemizedlist>
|
||
<listitem>
|
||
<para>透過 GEOM 可支援哪些模式的 <acronym>RAID</acronym>。</para>
|
||
</listitem>
|
||
|
||
<listitem>
|
||
<para>如何使用基本工具來配置、操作、維護不同模式的
|
||
<acronym>RAID</acronym>。</para>
|
||
</listitem>
|
||
|
||
<listitem>
|
||
<para>如何透過 GEOM 來完成鏡射(mirror)、分散連結(stripe)、加密(encrypt)
|
||
、遠端連接磁碟等。</para>
|
||
</listitem>
|
||
|
||
<listitem>
|
||
<para>當 GEOM 架構下的磁碟發生問題,如何排除。</para>
|
||
</listitem>
|
||
|
||
</itemizedlist>
|
||
|
||
<para>在開始閱讀這章之前,您需要︰</para>
|
||
|
||
|
||
<itemizedlist>
|
||
<listitem>
|
||
<para>了解 &os; 如何看待磁碟(<xref linkend="disks"/>) 。</para>
|
||
</listitem>
|
||
|
||
<listitem>
|
||
<para>知道如何設定、安裝新的 &os; 核心
|
||
(<xref linkend="kernelconfig"/>) 。</para>
|
||
</listitem>
|
||
</itemizedlist>
|
||
</sect1>
|
||
|
||
<sect1 id="GEOM-intro">
|
||
<title>GEOM 導論</title>
|
||
|
||
<para>GEOM 透過 privoder(即 <filename class="directory">/dev/</filename>
|
||
下的特殊裝置檔案) 來操控 classes(如 Master Boot Records、
|
||
<acronym>BSD</acronym> labels 等) 。GEOM 支援多種軟體
|
||
<acronym>RAID</acronym> 配置,透過 GEOM 存取時,
|
||
作業系統和應用程式不會意識到 GEOM 存在。</para>
|
||
</sect1>
|
||
|
||
<sect1 id="GEOM-striping">
|
||
<sect1info>
|
||
<authorgroup>
|
||
<author>
|
||
<firstname>Tom</firstname>
|
||
<surname>Rhodes</surname>
|
||
<contrib>Written by </contrib>
|
||
</author>
|
||
<author>
|
||
<firstname>Murray</firstname>
|
||
<surname>Stokely</surname>
|
||
</author>
|
||
</authorgroup>
|
||
</sect1info>
|
||
|
||
<title>RAID0 - 分散連結(striping)</title>
|
||
|
||
<indexterm>
|
||
<primary>GEOM</primary>
|
||
</indexterm>
|
||
<indexterm>
|
||
<primary>分散連結(Striping)</primary>
|
||
</indexterm>
|
||
|
||
<para>分散連結(striping) 可用來連結多個磁碟成為一大塊空間。
|
||
很多時候硬體控制器可以完成這件事,不過 GEOM 也提供了軟體版本的
|
||
<acronym>RAID</acronym>0,也就是分散連結(striping)。</para>
|
||
|
||
<para>在 <acronym>RAID</acronym>0 裡,資料會被切分成很多塊,
|
||
再分散寫入全部的磁碟。例如要寫入 256k 的資料到單一磁碟,在
|
||
四個磁碟的 <acronym>RAID</acronym>0 中可同時寫入 64k 到四個磁碟裡,
|
||
因此可大幅提升 I/O 效能。如果使用更多的磁碟控制器,
|
||
I/O 效能可再提升。</para>
|
||
|
||
<para>由於讀或寫時會同步交錯對許多磁碟進行 I/O 處理,因此
|
||
<acronym>RAID</acronym>0 的每個磁碟必須大小一樣。</para>
|
||
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="geom/striping" align="center"/>
|
||
</imageobject>
|
||
|
||
<textobject>
|
||
<phrase>Disk Striping Illustration</phrase>
|
||
</textobject>
|
||
</mediaobject>
|
||
|
||
<procedure>
|
||
<title>用未格式化的 ATA 磁碟來建立分散連結(striping)</title>
|
||
|
||
<step><para>載入 <filename>geom_stripe</filename>
|
||
kernel module:</para>
|
||
|
||
<screen>&prompt.root; <userinput>kldload geom_stripe.ko</userinput></screen>
|
||
</step>
|
||
|
||
<step><para>確定掛載點(mount point)存在。
|
||
如果想用分散連結(striping)的空間做為根目錄(root partition,即 <filename class="directory">/</filename> ),
|
||
則先用個暫時的掛載點,如
|
||
<filename class="directory">/mnt</filename>:</para>
|
||
|
||
<screen>&prompt.root; <userinput>mkdir /mnt</userinput></screen>
|
||
</step>
|
||
|
||
|
||
<step><para>確認要用來分散連結(striping)的裝置名稱,接著建立新的分散連結(striping)。
|
||
例如下面的指令會分散連結(striping)兩個未使用、尚未分割區的 <acronym>ATA</acronym>
|
||
磁碟(<filename>/dev/ad2</filename> 和
|
||
<filename>/dev/ad3</filename>) :</para>
|
||
<screen>&prompt.root; <userinput>
|
||
gstripe label -v st0 /dev/ad2 /dev/ad3</userinput></screen>
|
||
|
||
<screen>&prompt.root; <userinput>gstripe label -v st0 /dev/ad2 /dev/ad3</userinput></screen>
|
||
|
||
<!--
|
||
<para>A message should be returned explaining that meta data has
|
||
been stored on the devices.
|
||
XXX: What message? Put it inside the screen output above.
|
||
-->
|
||
</step>
|
||
|
||
<step><para>用下面的指令來建立分割區表(partition table):</para>
|
||
|
||
<screen>&prompt.root; <userinput>bsdlabel -wB /dev/stripe/st0</userinput></screen>
|
||
|
||
</step>
|
||
|
||
<step><para>除了先前建立的 <devicename>st0</devicename> ,這個步驟還會在
|
||
<filename class="directory">/dev/stripe</filename> 下新增兩個裝置:
|
||
<devicename>st0a</devicename> 和 <devicename>st0c</devicename>。
|
||
利用 <command>newfs</command> 指令可以在
|
||
<devicename>st0a</devicename> 建立檔案系統:</para>
|
||
|
||
<screen>&prompt.root; <userinput>newfs -U /dev/stripe/st0a</userinput></screen>
|
||
|
||
<para>螢幕上會有一堆數字傾瀉而過,幾秒鐘後就會完成。此時空間已建立,
|
||
可用來掛載使用了。</para>
|
||
</step>
|
||
</procedure>
|
||
|
||
<para>下面指令可用來手動掛載分散連結(striping)空間:</para>
|
||
|
||
<screen>&prompt.root; <userinput>mount /dev/stripe/st0a /mnt</userinput></screen>
|
||
|
||
<para>如果要在開機時自動掛載,在 <filename>/etc/fstab</filename>
|
||
加入這塊空間的資訊:</para>
|
||
|
||
<screen>&prompt.root; <userinput>echo "/dev/stripe/st0a /mnt ufs rw 2 2" \</userinput>
|
||
<userinput>>> /etc/fstab</userinput></screen>
|
||
|
||
<para>而 <filename>geom</filename> kernel module 必須在系統初始化時自動載入,
|
||
因此在 <filename>/boot/lodaer.conf</filename> 加入一行:</para>
|
||
|
||
<screen>&prompt.root; <userinput>echo 'geom_stripe_load="YES"' >> /boot/loader.conf</userinput></screen>
|
||
|
||
</sect1>
|
||
|
||
<sect1 id="GEOM-mirror">
|
||
<title>RAID1 - 鏡射(Mirroring)</title>
|
||
|
||
<indexterm>
|
||
<primary>GEOM</primary>
|
||
</indexterm>
|
||
<indexterm>
|
||
<primary>磁碟鏡射(Disk Mirroring)</primary>
|
||
</indexterm>
|
||
|
||
<para>許多企業或個人用戶用鏡射(mirroring) 來不中斷系統進行備份。
|
||
鏡射簡單來說就是在 B 磁碟上重覆一份 A 磁碟的資料,
|
||
或者 C+D 磁碟重覆 A+B 磁碟的資料。不論設定如何,
|
||
最重要的是所有磁碟或分割區(partition) 上的資料都會被複製,
|
||
之後可在不中斷服務的情況下復原、備份資料,使儲存的資料更安全。</para>
|
||
|
||
<para>開始之前,請先確定系統上有兩個容量相同的磁碟,
|
||
後面的範例假設這兩顆磁碟是 direct access(&man.da.4;)
|
||
<acronym>SCSI</acronym> 磁碟。</para>
|
||
|
||
<para>首先我們假設 &os; 安裝在第一個磁碟上,且只有兩個分割區(partition)。
|
||
其中一個是交換分割區(swap partition,大小為 <acronym>RAM</acronym>
|
||
的兩倍),而剩下的全用於根目錄(即 <filename class="directory">/</filename>,
|
||
root file system)。當然要在不同掛載點(mount point) 切出更多分割區
|
||
(partition) 也可以,不過難度會大幅提升,因為必須手動操作 &man.bsdlabel.8;
|
||
和 &man.fdisk.8; 工具。</para>
|
||
|
||
<para>重開機並等到系統完全初始化完畢,用 <username>root</username>
|
||
登入。</para>
|
||
|
||
<para>建立 <filename>/dev/mirror/gm</filename> 裝置並以
|
||
<filename>/dev/da1</filename> 連結:</para>
|
||
|
||
<screen>&prompt.root; <userinput>gmirror label -vnb round-robin gm0 /dev/da1</userinput></screen>
|
||
|
||
<para>這時系統應該會回應:</para>
|
||
<screen>
|
||
Metadata value stored on /dev/da1.
|
||
Done.</screen>
|
||
|
||
<para>初始化 GEOM,這動作會自動載入
|
||
<filename>/boot/kernel/geom_mirror.ko</filename> kernel module:</para>
|
||
|
||
<screen>&prompt.root; <userinput>gmirror load</userinput></screen>
|
||
|
||
<note>
|
||
<para>這動作應該會在 <filename class="directory">/dev/mirror</filename>
|
||
下建立 <devicename>gm0</devicename> 裝置結點(device node)。</para>
|
||
</note>
|
||
|
||
<para>在這個新建的 <devicename>gm0</devicename> 裝置上安置一般的
|
||
<command>fdisk</command> label 和開機磁區:</para>
|
||
|
||
<screen>&prompt.root; <userinput>fdisk -vBI /dev/mirror/gm0</userinput></screen>
|
||
|
||
<para>接著安置 <command>bsdlabel</command> 資訊:</para>
|
||
|
||
<screen>&prompt.root; <userinput>bsdlabel -wB /dev/mirror/gm0s1</userinput></screen>
|
||
|
||
<note>
|
||
<para>如果存在多個 slice 和分割區(partition),
|
||
記得修改上兩指令的參數,且另一個磁碟上的 slice 和分割區(partition)
|
||
大小必須相同。</para>
|
||
</note>
|
||
|
||
<para>用 &man.newfs.8; 工具在 <devicename>gm0s1a</devicename>
|
||
裝置結點建立預設的檔案系統:</para>
|
||
|
||
<screen>&prompt.root; <userinput>newfs -U /dev/mirror/gm0s1a</userinput></screen>
|
||
|
||
<para>系統會印出許多資訊和一大堆數字,這是正常的。
|
||
確認是否有認何錯誤,接著就可以將這個裝置掛載到
|
||
<filename class="directory">/mnt</filename> 掛載點(mount mount):</para>
|
||
|
||
<screen>&prompt.root; <userinput>mount /dev/mirror/gm0s1a /mnt</userinput></screen>
|
||
|
||
<para>接著將原本開機磁碟的資料搬移到新的檔案系統
|
||
(<filename class="directory">/mnt</filename>)。範例是用
|
||
&man.dump.8; 和 &man.restore.8; ,不過用 &man.dd.1; 也可以。</para>
|
||
|
||
<screen>&prompt.root; <userinput>dump -L -0 -f- / |(cd /mnt && restore -r -v -f-)</userinput></screen>
|
||
|
||
<para>執行上述指令時,只要將恰當的檔案系統掛在正確的位置,應該就能成功。
|
||
</para>
|
||
|
||
<para>接著編輯 <filename>/mnt/etc/fstab</filename>
|
||
檔將 swap file 那行移除或註解起來。
|
||
<footnote>
|
||
<para>請注意,將 <filename>fstab</filename> 的 swap file
|
||
那行註解起來,通常表示:您得用別的方法來重建 swap。詳情請參考
|
||
<xref linkend="adding-swap-space"/>。</para>
|
||
</footnote>請參考下面範例,並根據新磁碟修改其它的檔案系統資訊:</para>
|
||
|
||
<programlisting># Device Mountpoint FStype Options Dump Pass#
|
||
#/dev/da0s2b none swap sw 0 0
|
||
/dev/mirror/gm0s1a / ufs rw 1 1</programlisting>
|
||
|
||
<para>在目前的根目錄及新的根目錄建立 <filename>boot.conf</filename> 檔案,
|
||
這個檔案可以『幫助』系統 <acronym>BIOS</acronym> 開機:</para>
|
||
|
||
<screen>&prompt.root; <userinput>echo "1:da(1,a)/boot/loader" > /boot.config</userinput></screen>
|
||
|
||
<screen>&prompt.root; <userinput>echo "1:da(1,a)/boot/loader" > /mnt/boot.config</userinput></screen>
|
||
|
||
<note>
|
||
<para>在兩個根目錄上都新增檔案是為了安全起見,
|
||
如果因為某些原因新的根目錄無法開機,至少還可用原本的根目錄。</para>
|
||
</note>
|
||
|
||
<para>接著在 <filename>/boot/loader.conf</filename> 新增兩行:</para>
|
||
|
||
<screen>&prompt.root; <userinput>echo 'geom_mirror_load="YES"' >> /mnt/boot/loader.conf</userinput></screen>
|
||
|
||
<para>這會指示 &man.loader.8; 在開機時載入
|
||
<filename>geom_mirror.ko</filename> kernel module。</para>
|
||
|
||
<para>重開機:</para>
|
||
|
||
<screen>&prompt.root; <userinput>shutdown -r now</userinput></screen>
|
||
|
||
<para>如果一切順利,系統應該會從 <devicename>gm0s1a</devicename> 裝置開機,
|
||
接下來出現 <command>login</command> 提示畫面。如果出錯了,
|
||
請參閱下面 Troubleshooting 那一節。 現在可以將
|
||
<devicename>da0</devicename> 磁碟加入 <devicename>gm0</devicename>
|
||
裝置:</para>
|
||
|
||
<screen>&prompt.root; <userinput>gmirror configure -a gm0</userinput>
|
||
&prompt.root; <userinput>gmirror insert gm0 /dev/da0</userinput></screen>
|
||
|
||
<para>其中 <option>-a</option> 旗標告訴 &man.gmirror.8;
|
||
使用「自動同步(automatic synchronization)」,例如自動同步寫入磁碟的動作。
|
||
manual 說明了如何重建、取代磁碟等,不過 manual 裡的範例是用
|
||
<devicename>data</devicename> 而不是 <devicename>gm0</devicename>。</para>
|
||
|
||
<sect2>
|
||
<title>Troubleshooting</title>
|
||
|
||
<sect3>
|
||
<title>系統無法開機</title>
|
||
|
||
<para>如果開機提示類似這樣:</para>
|
||
|
||
<programlisting>ffs_mountroot: can't find rootvp
|
||
Root mount failed: 6
|
||
mountroot></programlisting>
|
||
|
||
<para>請用機器面板上的 Power 按鈕或 reset 按鈕來重開機,並在開機選單選 (6),
|
||
這樣子,系統就會進入 &man.loader.8;
|
||
交談模式。這時候,請照下面指令來手動載入所需的 kernel module
|
||
,也就是 <filename>geom_mirror.ko</filename>:</para>
|
||
|
||
<screen>OK? <userinput>load geom_mirror.ko</userinput>
|
||
OK? <userinput>boot</userinput></screen>
|
||
|
||
<para>如果這樣成功了的話,表示因為某些原因無法自動載入 kernel module。
|
||
請將:</para>
|
||
|
||
<programlisting>options GEOM_MIRROR</programlisting>
|
||
|
||
<para>加入到核心設定檔(kernel configuration file),重編並安裝核心。
|
||
這應該能解決這個問題。</para>
|
||
</sect3>
|
||
</sect2>
|
||
</sect1>
|
||
</chapter>
|