FakeRaid指南
出自Ubuntu中文
目錄 |
[編輯] FakeRaid 指南
原文出處:
原文作者:
授權許可:
翻譯人員:npnufn2006_yan
校正人員:
貢獻人員:
適用版本: 文章狀態:等待翻譯
[編輯] 如何配置Ubuntu來存取fakeRAID硬體設備
在當初Breezy預覽版發布的時候,我花了一個星期的時間將Breezy安裝在我的Via SATA fakeRAID上,並最終在用兩塊萬轉36G西數Rapter硬碟組建的RAID-0系統上實現了Winxp和Ubuntu linux的雙啟動。所以,我想我應該把我如何做得寫下來,以便於他人能得益於我的工作,並同樣添加一些相關的內容。
本頁描述了如何讓linux將RAID看做一塊硬碟並由其上啟動。在我的例子中,我是使用的RAID-0結構,但我所介紹的內容應當也適用於RAID-1,和RAID-5(參見文末的說明)。考慮到一些沒有做過類似操作的朋友,我在此給出的介紹比較詳細,所以不要被這篇文章的長度所嚇倒,其實都很直白。
[編輯] 什麼是fakeRAID?
在前一兩年,市場上出現了自稱是IDE或者SATA RAID控制器的硬體設備。這類硬體出現在一些桌面或工作站的主板上。實際上,這些設備都不是真正的RAID控制器。它們其實只是簡單的多通道磁碟控制器,只不過是可以借助於特殊的BIOS和驅動來協助操作系統實現軟體層面的RAID功能。由於RAID設置是用的BISO設置界面而且系統可以從RAID上啟動,所以這種功能就可以給用戶一個像是硬體RAID的外表。
在windows下,我們必須為其安裝驅動才能操作RAID。而在linux環境下,由於系統內置了軟RAID功能可以對這些設備進行預處理,這些硬體可以就按照它們本來的面目來看待,多硬碟驅動器或者多通道IDE/SATA控制器。也就是,"fakeRAID"。
如果你已經在internet上研究了這個題目並看到了這裡,你一定已經知道通常對於這個問題的反映是,我不知道你是否可以做到,但是沒必要苦惱,因為linux已經內置了軟raid的功能。而且,我們也不知道在linux放棄內置的軟raidn功能而選擇使用fakeRaid是否真的能帶來系統性能上的提升。cpu最後仍然要作這些工作。不過,這不是問題的重點。重點在於,有windows用戶可能會希望將linux也安裝在同一個硬碟組上。對於那些喜歡嘗試各種系統,或者因為工作需要或其他原因必須使用windows的用戶來說,多重啟動是很常見的。這類用戶沒必要為了使用linux就添加一塊硬碟。另外,一些人說RAID-0不安全。不過這要視個人需要而言,看你是更看重安全還是效率。這些問題都不是本文的重點問題,因此我們就假定您需要這麼做並告訴您如何去做。
[編輯] 在RAID陣列上安裝Ubuntu
[編輯] 安裝dmraid
標準的LiveCDs(光碟版系統)和可選擇安裝CD現在還不支持fakeRAID. 我用LiveCDs(光碟版系統)來啟動,然後通過包管理器從通用庫(要開啟Synaptic中的設置為"Universe"或修改 /etc/apt/sources.lst)中下載dmraid包。
注意:Ubuntu 6.06對dmraid的支持已經增強,所以下面的一些步驟理論上說也不是必須的。如果你從Live CD安裝,請在啟動安裝程序(Ubiquity)之前從通用庫中選擇安裝dmraid包。並且要確保你的RAID設備在/dev/mapper下,而不是隨意地以/dev/sd*代替。到目前為止,我聽一位用戶說Ubiquity在安裝整個系統時一切正常。
然而,這顯然只是一小部分,對大部分用戶(包括我自己)來說,Ubuquity安裝失敗了。也許對於較為穩定的6.06來說,這些煩悶的步驟不再需要。然而,在這一過程中,不要氣餒,你會對你的系統更加了解。
如果Ubiquity(Ubuquity?)不能自動完成安裝,你可以按照下面說明中的步驟手動完成。有一點要特別注意,一些步驟對Ubuntu 6.06不再需要,這些會被標記為"Ubuntu 5.10"。
所以,再次提醒,如果你安裝的是Ubuntu 6.06或更新版本,請跳過標記為"Ubuntu 5.10"的步驟。
[編輯] 將RAID陣列分區
在我們創建文件系統(Windows用戶稱作"格式化")之前,必須要把磁碟切成分區來存放我們的文件系統。
如果你喜歡,可以使用gparted來創建和刪除分區或文件系統,但我們並不推薦這樣做,因為:
a)使用gparted,在對分區表修改後不能對它進行更新,所以你不得不修改分區,然後退出gparted,從命令行運行dmraid -ay來探測新分區,然後再次啟動gparted,在這之後,你才能格式化這些分區。
b)它會生成大量的出錯信息,這樣很容易導致混亂,很難知道這些操作是否成功。
c)一些朋友看到上面兩條很容易就退縮了。
While it IS possible to use gparted for this, until it improves, we recommend command-line utilities for partitioning and the creation of filesystems:
fdisk: partitioning (and creation of filesystems on some platforms) parted: partitioning and creation of filesystems mkfs: creation of filesystems
Familiarize yourself with the tools my using the man pages (i.e., "man fdisk", "man parted", "man mkfs"). Work with partitions and filesystems as root (sudo) or the kernel may not be able to re-read the partition table until you reboot.
In my case, I first needed to resize my existing NTFS partition to make space for Ubuntu. (If you don't need to do this, skip to the next paragraph.) Gparted currently can not do this on the mapper device so I had to use the ntfsresize program from the command line. Note that ntfsresize only resizes the filesystem, not the partition, so you have to do that as a following step. Use ntfsresize to shrink the filesystem, note the new size of the filesystem in sectors, then fire up fdisk. Switch fdisk to sector mode with the 'u' command. Use the 'p' command to print the current partition table. Delete the partition that you just resized and recreate it with the same starting sector. Use the new size of the filesystem in sectors to compute the ending sector of the partition. Don't forget to set the partition type to the value it was before. Now you should be able to create a new partition with the free space.
Create the partitions (the actual commands will vary depending on your choice of tool(s)):
sudo fdisk /dev/mapper/via_hfciifae p ?
At a minimum, this should include a root partition and a swap partition (this configuration is recommended for new users). For a multi-user desktop, you may want root, swap, and home. In my case, I wanted to isolate my Windows and Linux files at the primary partition level, so I created an extended partition to hold several logical linux partitions. Also, I wanted a separate /boot partition as a security measure, so I created logical partitions for root, boot, and swap. Also, since you can only have four primary partitions on a DOS-labeled disk, using an extended partition gives me the flexibility to add more linux partitions later if I want them. If I decide to serve web apps or something, I might want logical partitions for boot, root, swap, tmp, var, usr, and home.
[編輯] 在RAID陣列上建立文件系統
Now "format" each partition (create filesystems). In my case I used fdisk and ran a mk2fs on /dev/mapper/via_hfciifae5 and mkreiserfs on /dev/mapper/via_hfciifae7. You can also do this with parted. Or you can exit your partitioning tool and use mkfs (e.g., "mkfs.ext3" and "mkfs.reiserfs") to create the filesystems. Create swap with "mkswap /dev/mapper/etc." and "swapon /dev/mapper/etc.". (Use the man pages.)
The command dmraid -r will show how the partitions have been mapped in RAID: In my case:
via_hfciifae -- the raw raid volume via_hfciifae1 -- the NTFS partition via_hfciifae5 -- /boot via_hfciifae6 -- swap via_hfciifae7 -- /
[編輯] 掛載臨時文件結構
Next, I created a temporary file structure to hold my new installation while I construct it, I and mounted two sets of directories to it: a) Mounted the new partitions I had created for / and /boot (so could install packages to them). b) Mounted the currently running, /dev, /proc, and /sys filesystems, so I could use these to simulate a running system within my temporary file structure.
mkdir /target mount -t reiserfs /dev/mapper/via_hfciifae7 /target mkdir /target/boot mount -t ext2 /dev/mapper/via_hfciifae5 /target/boot mkdir /target/dev mount --bind /dev /target/dev mkdir /target/proc mount -t proc proc /target/proc mkdir /target/sys mount -t sysfs sysfs /target/sys
[編輯] 安裝基本系統
Now we install the base system. debootstrap installs all base packages and does it setup. Afterwards you need to install some additional packages:
cd /target apt-get install debootstrap debootstrap breezy /target ## instead of breezy can be any distribution selected cp /etc/apt/sources.list etc/apt cp /etc/resolv.conf /target/etc cp /etc/hosts /target/etc chroot /target apt-get update apt-get install dmraid apt-get install grub apt-get install linux-k7 apt-get install ubuntu-base ubuntu-desktop
- Temporary Note to other editors: when I tested this howto with 6.06 LTS on 1 June 2006, the install of dmraid failed (--configure), indicating it was unable to start the dmraid initscript. This may have been some kind of error on my part. I was able to fix this with
dpkg-reconfigure dmraid, so I add it here as a possibily useful tip should this turn out to be systemic problem that others encounter. Also, install dmraid first, then the kernel, in order to use the initramfs scripts that are now part of the 6.06 distrubution. This is based on one 6.06 test -- please correct/edit this as appropriate.** - 18 June 2006: another user reported this same problem. dpkg-reconfigure did not work for him, but he reports that after reinstalling dmraid "like ten times" it magically worked. To help reduce the likelihood of this occuring, I have separated the package installs to separate lines (above) to help ensure things are completed in what I'm guessing to be the best order.
- Please contribute your lessons learned regarding this error and how to overcome it.
- Temporary Note to other editors: when I tested this howto with 6.06 LTS on 1 June 2006, the install of dmraid failed (--configure), indicating it was unable to start the dmraid initscript. This may have been some kind of error on my part. I was able to fix this with
[編輯] 為RAID安裝啟動器
Now that you have the debian core, ubuntu-base, linux kernel, dmraid, grub, and ubuntu-desktop installed, you can proceed with the bootloader. If you haven't completed these successfully, don't attempt to proceed, you will just exacerbate any problem you have at this point.
We will demonstrate the installation of GRUB (Grand Unified Bootloader), but there are several alternatives (e.g., LILO). The key information here is how the normal process for use of the bootloader had to be modified to accomodate the RAID mappings, so this general process should be useful regardless of your choice of bootloader.
[編輯] 安裝啟動器包
Now you need to run the grub shell. In a non-RAID scenario, one might use grub-install, but we cannot because it cannot see the RAID device mappings and therefore cannot set up correct paths to our boot and root partitions. So we will install and configure grub manually as follows:
First, make a home for GRUB and put the files there that it needs to get set up:
mkdir /boot/grub cp /lib/grub/<your-cpu-arch>-pc/stage1 /boot/grub/ cp /lib/grub/<your-cpu-arch>-pc/stage2 /boot/grub/ cp /lib/grub/<your-cpu-arch>-pc/<the staging file for your boot partition's filesystem>
The "staging files" look like: "e2fs_stage1_5" (for ext2 or 3); "reiserfs_stage1_5" (for reiserfs); "xfs_stage1_5" (and so on). It is safe to copy them all to your /boot/grub.
Next, go into the grub shell:
grub
You should now see the grub prompt.
Next, tell GRUB which device is the boot device:
device (hd0) /dev/mapper/via_hfciifae
In my case, it was the RAID array mapped as /dev/mapper/via_hfciifae.
Next, tell GRUB where all the stuff is that is needed for the boot process:
root (hd0,4)
CAUTION: This is one of the most common sources of error, so we will explain this in excruciating detail. From GRUB's perspective, "root" is whatever partition holds the contents of /boot. For most people, this is simply your linux root (/) partition. E.g., if / is your 2nd partition on the RAID you indicated above as hd0, you would say "root (hd0,1)". Remember that GRUB starts counting partitions at 0. The first parition is 0, the second is 1, and so on. In my case, however, I have a separate boot partition that GRUB mounts read-only for me at boot time (which helps keep it secure). It's my 5th partition, so I say "root (hd0,4)"
Optional: IF GRUB complains about bad cylinder numbers (i.e, if it did not complain, skip this part about fdisk and geometry):
You may need to tell it about the device's geometry (cylinders, heads, and sectors per track. You can find this information out by using fdisk (quit GRUB) with the command: fdisk (fdisk -l /dev/mapper/via_hfciifae)
...then reenter the GRUB shell and use the command: geometry (hd0) 9001 255 63
Next, now that you've successfully established the "device" and "root", you can go ahead and instantiate GRUB on the boot device. This sets up the stage 1 bootloader in the device's master boot record and the stage 2 boot loader and grub menu in your boot partition:
setup (hd0) quit
[編輯] 配置啟動器
Now run update-grub:
update-grub
This adds your newly installed linux kernel, and the associated initial ram disk image, to the boot options menu that grub presents during start-up. You will find this menu in the boot/grub directory. We need to edit this menu.lst file as follows. (CAUTION: Get this right - this is a common source of error and mistakes result in kernel panic upon reboot, so no typos.):
a) "root=": Correct the path that points to the linux root (in several places). update-grub configures hda1 as root because, not being dmraid-aware, it can't find your current root-device. Put the correct device mapping for your linux root. So put your equivalent of:
root=/dev/mapper/via_hfciifae7
every place you see "root=" (only where you see root and the equal sign). This goes in all the places where update-grub defaulted to root=/dev/hda1 or just left it blank like root= .
Make sure you change this in the Automagic defaults section as well as in each of the multiple alternatives sections that follow. (Important: the Automagic defaults section is nested and therefore uses ## to indicate comments and # to indicate the actual defaults that is uses. So don't "un-comment" the default lines when you edit them. In other words, leave the #). When you update your kernel later on, update-grub will use these defaults so it won't ignorantly "assume hda1" and send your system into a kernel panic when you boot. This ought to end up looking something like:
b) "groot": If necessary, correct the grub root. In places, you will see other lines that also refer to "root" (or "groot") but use syntax such as root (hd0,1) instead of a path. As described earlier, these refer to the "root" for grub's purposes, which is actually your /boot. Also, remember grub's syntax uses partition numbering beginning with zero. So, if you have a separate /boot partition, these lines should instead show something like:
root (hd0,4)
(The same information we used while working with grub interactively earlier.) Change this both for the Automagic defaults as well as for each alternative, including the memtest option.
c) An additional edit is required IF you are using a separate /boot partition. The path pointing to the linux root must be RELATIVE to the grub "root" (your /boot). So if you are using a separate boot partition, the paths in grub's menu.lst file that help grub locate the linux kernel and initrd will not begin with "/boot", and you should delete that portion of the path. For example, {{update-grub</nowiki></pre> initially spat out this:
title Ubuntu, kernel 2.6.15-29-amd64-k8 root (hd0,0) kernel /boot/vmlinuz-2.6.15-29-amd64-k8 root= ro quiet splash initrd /boot/initrd.img-2.6.15-29-amd64-k8 savedefault boot
... and because I have a separate boot parition and opted not to use a grub splash image (which you can learn about elsewhere), my editing looked like this...
title Ubuntu, kernel 2.6.15-29-amd64-k8 root (hd0,4) kernel /vmlinuz-2.6.15-29-amd64-k8 root=/dev/mapper/via_hfciifae ro quiet initrd /initrd.img-2.6.15-29-amd64-k8 savedefault boot
IMPORTANT: Note that I removed "savedefault". If you leave this in, you will get a "file not found" error when you try to boot (you also can't set use default=saved up top as it shows in the menu.lst file's example). Again, if you are not using a separate boot partition, you can leave /boot in the paths.
d) To add a static boot stanza for Windows, you can use and change the example in the menu.lst file or the following:
title Windows XP rootnoverify (hd0,0) chainloader +1Put it at the bottom, below where it says
### END DEBIAN AUTOMAGIC KERNELS LIST. Or if for some unforgivable reason you want your computer to boot Windows by default, you can put it up front above where it says### BEGIN DEBIAN AUTOMAGIC KERNELS LIST
e) Close the gaping security hole! First, set a password where the example shows it. This will be required for any locked menu entries, for the ability to edit the bootlines, or to drop to a command prompt. To do this, in the console type:
grub-md5-crypt
When it prompts you "Password:", it's asking what you want to be the GRUB password (not your user password, the root password, or anything else). You will be prompted to enter it twice, then it will spit out the MD5 hash that you need to paste into menu.lst. This line should end up looking something like:
password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
- Then, to keep your "recovery mode" boot alternative(s) locked each time update-grub runs, set
lockalternative=true.
Unless you do this, anybody will be able to seize root simply by rebooting your computer (e.g., cutting power to it) and selecting your "recovery mode" menu entry when it reboots, or editing the normal bootline to include 'single' mode.
f) Test automagic kernels settings (also completes the locking of alternatives). It is better to find errors now than a month from now when you've forgotten all this stuff and the kernel gets updated.
- first, make a backup of menu.lst
- then run update-grub again
- watch for errors and re-examine menu.lst for discrepancies
- correct as needed.
[編輯] 為RAID 重新配置Initramfs (Ubuntu 5.10)
Reminder: Sections Ubuntu 5.10 should be skipped if you are installing Ubuntu 6.06.
In recent years there has been a trend to try and pull a bunch of code out of the kernel and into EarlyUserspace. This includes stuff like nfsroot configuration, md software RAID, lvm, conventional partition/disklabel support, and so on. Early user space is set up in the form of an initramfs which the boot loader loads with the kernel, and this contains user mode utilities to detect and configure the hardware, mount the correct root device, and boot the rest of the system.
Hardware fakeRAID falls into this category of operation. A device driver in the kernel called device mapper is configured by user mode utilities to access software RAIDs and partitions. If you want to be able to use a fakeRAID for your root filesystem, your initramfs must be configured to detect the fakeRAID and configure the kernel mapper to access it.
So we need to add dmraid to the initramfs. Debian and Ubuntu supports this by way of a set of shell scripts and configuration files placed in /etc/mkinitramfs/. We must tailor these to include dmraid by plugging in two simple scripts and adding a one-line entry to a configuration file. The only real challenge here is to make sure you don't inadvertently screw up the syntax with a typo.
Note that in Ubuntu 6.06, this is taken care of by the dmraid package itself.
[編輯] 在Ubuntu 5.10中配置mkinitramfs
First, create a new file as /etc/mkinitramfs/scripts/local-top/dmraid .
(If you are lazy or don't like to keyboard, you can open this how-to in the browser and copy the text.)
PREREQ="udev"
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
modprobe -q sata_nv
modprobe -q dm-mod
/sbin/dmraid -ay
Second, create another new file as /etc/mkinitramfs/hooks/dmraid.
(Again for the lazy, you can copy it from your browser. Also, it's only slightly different, so if you are manually typing it for some reason, you may want to start with a copy of the first script.)
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
. /usr/share/initramfs-tools/hook-functions
copy_exec /sbin/dmraid /sbin
exit 0
Third, mark both of these new initramfs scripts as executable:
chmod +x /etc/mkinitramfs/hooks/dmraid chmod +x /etc/mkinitramfs/scripts/local-top/dmraid
Last, add the line dm-mod to the file /etc/mkinitramfs/modules. Make sure the file ends with a newline. If you use a RAID-1 (mirror), include dm-mirror as well.
[編輯] 升級initrd (Ubuntu 5.10)
Now the big moment -- use initramfs to update the initrd file. Below, I show the kernel I installed at that time, but stuff following "img-" and following "-c -k " must reflect the version YOU are using (e.g., "2.6.15-29-amd64-k8-smp" or whatever).
Two commands
rm /boot/initrd.img-2.6.12-9-k7 update-initramfs -c -k 2.6.12-9-k7
Now you are ready to set up the new system.
[編輯] 像通常一樣預配置新系統
Ensure that you are still operating as root within the new (temporary) system (i.e., your prompt will be root@ubuntu#. If not, chroot /target again:
sudo chroot /target
(The process from here forward is the same as any bootstrap / network installation, and there are other sources to refer to for more detail.)
UBUNTU 5.10: Enter the command base-config new to configure system defaults.
- UBUNTU 6.06: base-config is deprecated in Dapper Drake. The correct procedure needs to be inserted here, so please contribute. Theoretically, one could do what base-config does manually.
While it is not absolutely necessary, it may be useful to also copy the live hosts and interfaces files into your temporary system before rebooting (after exiting your chroot:
cp /etc/hosts /target/etc/hosts cp /etc/network/interfaces /target/etc/network/interfaces).
It will also be helpful to configure your fstab file at this point. One easy way to do this is:
cat /etc/mtab
(select and copy everything)
nano /target/etc/fstab
(paste everything)
Then delete everything except the proc line, and the lines that refer to your RAID partitions. It might end up something like this (yours will vary - people asked for examples):
proc /proc proc rw 0 0 /dev/mapper/via_hfciifae5 /boot ext3 defaults 0 2 /dev/mapper/via_hfciifae7 / reiserfs notail,noatime 0 1 /dev/mapper/via_hfciifae6 none swap sw 0 0
or
/dev/mapper/nvidia_bggfdgec2 /boot ext3 defaults 0 1 /dev/mapper/nvidia_bggfdgec3 none swap sw 0 0 proc /proc proc rw 0 0
Finally you are ready to reboot. This first time, select the "recovery mode" option. When it asks, you want to "perform maintenance". Set the root password:
passwd
Suggested early set-up tasks: adduser yourself (create a regular user) nano /etc/group (create an admin group) visudo (duplicate the root line except with %admin where root was) reboot, and you should be able to log in a normal user through gdm, and continue normally with sudo privileges.
(more is needed here, or a reference to whatever replaces the howto that describes a general debootstrap install)
[編輯] 升級到Ubuntu 6.06 (Dapper Drake)
The dmraid package in Ubuntu 6.06 has the necessary scripts included (under /usr). After upgrading the dmraid package, you can therefore delete the old scripts that you've made (under /etc). To be sure the package scripts are baked into the initrd, update the initrd again by reconfiguring dmraid:
sudo rm /etc/mkinitramfs/hooks/dmraid sudo rm /etc/mkinitramfs/scripts/local-top/dmraid sudo dpkg-reconfigure dmraid
[編輯] RAID 5的特別說明
While trying to install dmraid for a Raid 5 Nvidia setup received a error 139 forced exit and upon further investigation in the TODO doc in /usr/share/doc/dmraid found that dmraid doesn't support raid modes above 1 yet. Here's the exact wording from the TODO,"higher RAID levels above 1; main restriction to support these is the need for device-mapper targets which map RAID3,4,5."
EDIT: Further research has lead me to dmraid 1.0.0.rc10, which in it's changelog notes Raid5 support for nvidia. Current Ubuntu version is 1.0.0.rc9 which explains the lack of Raid5 support. Will update with more info on how well it works.
NOTE: The kernel device mapper ( which dmraid depends on ) does not yet support raid 5. There are some early development patches availible, so they might get merged into Linus's kernel in time for Dapper+1, but I'd say it's not all that likely.
