LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1725|回复: 11

[ZZ] Boot Linux from a FireWire device (also for USB device)

[复制链接]
发表于 2005-7-24 11:21:20 | 显示全部楼层 |阅读模式
This is a very good article from IBM developerworks that clearly explain the principle on how to boot Linux from Firewire and USB devices.

Hope it is useful for anyone interested in installing Linux to external devices.

Original URL http://www-128.ibm.com/developer ... ned/l-fireboot.html

**************************************************************
Boot Linux from a FireWire device

Installing Linux on removable drives

Level: Intermediate

Martyn Honeyford (martynh@uk.ibm.com), Software Engineer, IBM UK Labs

15 Jul 2004

    Obtaining an external drive is a great way to breathe new life into older hardware, or allow you to use Linux on machines on which you can't (or don't want to) alter the internal hard drives.

Say you want to use Linux in a dual-boot arrangement, but you don't have any free space on your computer's hard drive. One solution would be to use a "live" Linux distribution such as Knoppix, which can be run directly from CD. This is certainly viable for occasional use, but it has a number of serious drawbacks:

    * You will still require some permanent storage for your data files. A floppy disk may be suitable if you only work with very small files, or a USB flash memory key may suffice for medium-sized files, but neither of these is ideal.
    * When using a "live" CD, it is at best difficult -- and at worst, impossible -- to install your own applications, or to customize existing applications.
    * There is a performance penalty to using live distributions, most notably on start-up while all of the devices are being detected -- but also while running (as everything has to be loaded from CD, which is usually much slower than from the hard drive).

To be sure, other options also exist. For instance, you could buy another internal drive and install Linux on that. But often, you may not have any free drive bays in your case (this is particularly true of laptops, which typically only allow one internal hard drive).

Or, you could replace the current drive with a larger one, and install Linux in the resulting extra space. This, however, is a very time-intensive option, as it requires you to reinstall your existing OS on the new drive, reinstall and reconfigure all of your applications, and restore all of your data.

A much better solution is to purchase an external hard drive and install Linux on that. This lets you leave your existing hardware and software untouched and simply connect the external drive when you want to use Linux.

Removable drive options

The range of removable devices onto which Linux may be installed ranges from floppy drives, through USB-flash devices, on to USB/FireWire hard drives, and more.

While it is certainly possible to install Linux on a small-capacity device such as a 1.44MB floppy or a 32MB USB-key, these are usually (necessarily) specialized, cut-down distributions intended for, for instance, rescuing broken installations.

External hard drives, however, offer the most flexibility for a general purpose Linux distribution at a reasonable cost.

External drives are available in a large number of different sizes from a number of different manufacturers (Maxtor, Western Digital, and so on). These drives tend to consist of an external box, which holds a standard 3-1/2 inch or 2-1/2 inch IDE drive. These drives then are typically connected to the computer via USB or IEEE1394 (FireWire) connection.

USB comes in two main versions, 1.1 and 2.0. Version 1.1 has a maximum transfer speed of 12 Mbit/s (megabits per second), whereas version 2.0 supports transfer speeds of up to 480 Mbit/s. While most 2.0-compatible drives are backwardly compatible with 1.1, it is generally advisable to avoid using 1.1 unless there is no other option (due to its slow speed).

The FireWire standard also defines a number of different possible speeds, but in reality, whenever people say FireWire, they mean "FireWire400," which supports transfers up to 400 Mbit/s.

There is little to choose between USB 2.0 and FireWire in terms of speed: although USB 2.0 has a higher quoted speed, in practice they both tend to be comparable due to differences in the protocols. If your machine has both, it is probably worth going for USB rather than FireWire (for reasons I'll explain later), but if it has only FireWire, then of course you will go for that. For maximum flexibility, choose one of a number of drives that support both USB 2.0 and FireWire (such as the one I use later in this article).

For machines that do not have the required ports, PCI (for desktop) and PCMCIA (for laptop), FireWire and USB 2.0 cards are now available very inexpensively: for example, the PCMCIA FireWire card I use later in this article was purchased for approximately 10 GBP (under $20 US).

For the purposes of this article, I have purchased a 5-1/4 inch external drive enclosure. This is a very flexible enclosure, which is supplied with no drive and can be filled with any standard IDE device, including 3-1/2 inch hard drives and 5-1/4 inch IDE devices such as CD-RW/DVD-RW drives. The enclosure has both USB 2.0 and FireWire connections.

In order to connect the enclosure to my IBM Thinkpad T30 laptop, I also purchased a PCMCIA FireWire card (as the built-in USB ports only support USB 1.1).

Both the enclosure and the FireWire card were relatively inexpensive (approximately 50 GBP and 10 GBP, respectively).

For testing purposes, I fitted the enclosure with a 13GB 3-1/2 inch IDE drive I had laying around -- for real world usage, I would buy a larger capacity drive, which again are now very cheap (approximately 50 GBP per gig!)

Linux support

As you may expect, Linux support for these enclosures is very good indeed. Any device that adheres to the SBP (Serial Bus Protocol) standard for "Mass Storage Devices" can easily be used with Linux.

In general, to enable support for these devices you will need to have a number of things supported in your kernel (either directly compiled in or via modules).

For both USB and FireWire, SBP device support is implemented via SCSI emulation -- that is to say, the devices appear to Linux as though they were SCSI disks. This is a common way to abstract storage devices within the Linux world (for instance, IDE CD/DVD drives are typically also connected using SCSI emulation). For this reason, the following kernel support is required:

    * SCSI support
    * SCSI emulation
    * SCSI disk support

In addition, the following support will be required according to the connection method:

    * For FireWire:
    * IEEE1394 support
    * OHCI1394 support
    * RAW1394 support
    * SBP-2 support

    * For USB:
    * (host-side) USB support
    * OHCI support
    * UHCI support
    * USB mass-storage support

You will obviously have to have all the normal support for the rest of your hardware (graphics cards and so on), and may require some additional modules, depending on your exact hardware.

For instance, I am using a PCMCIA (cardbus) FireWire card, so I needed to add:

    * PCMCIA support
    * cardbus support

Installation

Now that we have our nice external drive, we shall start by installing Linux on it.

The easiest way to install Linux these days (certainly in my opinion), is to connect all of your hardware (in my case, this consisted of plugging in the PCMCIA FireWire card, attaching the FireWire cable to the PCMCIA card and the drive, and turning on the drive's power switch); then boot up your machine with the installation CD from your distribution of choice.

My distribution of choice is Gentoo (see Resources for a link), so I used the latest "Universal" x86 Live CD (2004.1). The steps required for other distributions should be more or less comparable to those outlined here.

Once you have booted with the install CD, with a bit of luck it should have recognized your drive. The drive should appear as a disk under /dev/sdX, where X is a lowercase letter starting at "a." On my system, the external drive was detected as /dev/sda, but this will vary if you have other SCSI disks (or emulated SCSI disks); in that case, it might be /dev/sdb or some other letter. If your drive is not detected automatically, some further steps may be required -- for instance, you might have to pass boot options to enable FireWire or PCMCIA, or you might have to manually load some kernel modules, or other things of that sort (see Resources for links to troubleshooting guides).

Once the drive has been recognized, it should behave exactly like an internal hard drive as far as the rest of the installation is concerned; so you should be able to partition it as required and install Linux as normal.

One word of caution, however: care needs to be taken when deciding on where to install the boot loader (usually GRUB or LILO) -- I would recommend not installing it in the Master Boot Record (MBR) (which is usually the default). Rather, it should be installed in the root partition (or boot partition, if you use a separate one) of the external drive.

Now that we have Linux installed on the device, we want to boot it up. This is where things can start to get a little tricky.

Booting

Before I discuss booting up your new drive, a little boot loader theory is required.

Boot loaders are usually installed in the MBR of the first hard disk in the machine. When the boot loader is invoked (the BIOS automatically executes the code in the MBR), it usually displays a menu of possible OSes to boot. Selecting a given OS causes it to boot up.

Two things should be noted about this scenario:

    * The menu of OS choices is (usually) loaded from disk
    * To boot the relevant OS, the bootloader needs to read the relevant kernel from disk

As the above takes place before the OS has been loaded, it means that all of the disk reading must take place by way of BIOS calls. This has a very serious implication: namely, that in order to boot the disk directly, your BIOS must support disks connected via FireWire or USB. This can typically be seen as a BIOS option to boot from these types of disk. FireWire BIOS support is currently very rare indeed, but USB support is becoming reasonably common. Therefore, if you are using USB on a relatively recent machine, it should be possible to boot the drive into Linux directly.

After installing GRUB in the MBR of the external drive, I was able to boot it directly when connected via USB. Simply enter the BIOS setup utility while booting with the disk connected. The external disk will appear as a regular hard drive: move it so it is before the internal drive in the boot order.

I was also able to install a boot loader in the MBR of the internal drive and use that to boot the USB drive (where it appeared as hd1 in GRUB). If you are using FireWire, chances are that your BIOS will not be able to boot the drive directly, and a little more work will be required.

Luckily, due to the flexibility of Linux, there is a fairly simple solution if you cannot boot directly (which is certainly the case in my situation, with a PCMCIA FireWire card!) You can perform the preliminary boot steps from a supported device such as a floppy drive, CD, USB key, or a tiny partition on the main drive, and then use the external drive for everything else.

Building the boot image

There are two methods we can use to boot:

    * One-phase boot
      The kernel boots, mounts the root filesystem, and continues initialization by calling the initialization scripts (usually /sbin/init)
    * Two-phase (initrd) boot
      The kernel boots, mounts an initial ram disk (initrd), performs further customizable initialization, then mounts the root filesystem and continues initialization (again, usually by calling /sbin/init)

Each of these methods has its own advantages and disadvantages.

One-phase boot

In order to use the one-phase boot, we need to build a kernel that has all the drivers needed to mount the root file system built in (any other drivers can be built at modules that can be loaded from the root partition during normal initialization).

If we are attempting to boot from a very small device, such as a floppy disk, the best approach is to build a kernel with just enough drivers built in to allow us to mount the root external file system -- and build everything else as modules. For example, I have the SCSI support, PCMCIA support, IEE1394, SBP, and like support built in, but everything else -- including graphics card support, networking device support, and so on -- is built as modules that are stored on the root partition (on the external drive), rather than on the floppy.

With a simple (one-phase) boot procedure, we should be able to build a kernel with the required support, put it on a floppy drive, install a boot loader on the floppy (I use GRUB, but there are other options, such as LILO), then boot with something similar to this (for GRUB):

root (fd0)
kernel (fd0)/boot/bzImage root=/dev/sda1

This almost works, except for two problems:

   1. Because of the fact that SBP support uses SCSI emulation, the emulated SCSI bus need to be "rescanned" in order to detect the disk and allow /dev/sda1 to be mounted. This scanning is performed with a couple of simple commands. Unfortunately, however, using a one-phase boot, we cannot run any commands until the kernel has finished booting, and the kernel cannot finish booting until the root file system is mounted -- a classic Catch-22 situation. Thankfully, there is a patch available for 2.4 kernels that causes the SCSI bus to be scanned on startup (see Resources for more details). By applying this patch, I was able to have the external drive automatically detected by the kernel during bootup with no rescanning commands required. This leads us to the next problem.
   2. There is a timing window within the kernel, which means that often, the kernel will proceed to try to mount the root device before it has had a chance to be properly detected or initialized. Again, there is a patch available for this (please see Resources for a link) that simply makes the kernel wait for a short period of time on startup, and retry if it fails to mount the root filesystem (to give the external drive time to be recognized).

By applying these two patches, I was successfully able to build a kernel on a bootable floppy disk, which would boot and then use the external FireWire drive as root.

The main problem with this approach is that it requires us to patch the kernel source -- which is at best a pain (when new kernel versions are released) and at worst, a real problem (if the patches are not maintained to keep in step with the other changes occurring to the kernel).

It may have occurred to you that we can avoid these two problems if our BIOS supports USB or FireWire and we are booting directly. Unfortunately, this is not the case: while this method uses BIOS calls to access the disk during boot up, once the kernel begins to initialize, the BIOS is no longer used, and the disk is accessed using the kernel drivers -- so the same problems are encountered.

Two-phase boot

As of kernel version 2.0.X, an interesting capability was added to the Linux kernel -- the ability to use an "initial RAM disk" (or initrd) to give a two-phase boot process.

In a nutshell, the kernel is booted as normal; but instead of mounting the "real" root file system, a miniature root filesystem is created in RAM, and that is mounted. Any number of arbitrary steps can then be performed in this initial environment before the real root is mounted and we switch to using the real root and destroy the initial RAM disk.

This is useful in all sorts of circumstances, but for our purposes we will simply be using our mini environment to rescan the SCSI bus, wait for the external disk to be recognized, then switch to using this as our real root and continue to boot.

In order to use this method, we need to create two things, a kernel and an initrd image.

The kernel is just a regular kernel which has initrd support built in. The initrd image is a loopback filesystem image which contains our mini-root filesystem (this image can optionally compressed with gzip to reduce its size).

You can check the Resources section for more information on creating or customizing your own initrd image.

Within the initrd image, there is a file called linuxrc. This is the file that is executed when initrd is loaded, so make sure it has execute permission! For our purposes, the linuxrc is very simple:

Listing 1. initrd linuxrc


#!/bin/sh
REAL_ROOT=/dev/sda1
# mount the /proc filesystem
mount -t proc none /proc

#for scsi-emulation
# modprobe sd_mod

#for pcmcia
# modprobe pcmcia_core

#for FireWire
# modprobe ieee1394
# modprobe ohci1394
# modprobe raw1394
# modprobe sbp2

#for USB
# modprobe usbcore
# modprobe ohci-hcd
# modprobe uhci-hcd
# modprobe usb-storage

# loop rescanning the scsi bus + rerunning devfsd
retries=5
i=1
until [ -e $REAL_ROOT ]
do
  if [ $i -gt $retries ]
  then
     echo "Unable to mount real root ($REAL_ROOT) - Giving up!"
     /bin/ash
     exit
  fi

  echo "Real root ($REAL_ROOT) not found, retrying ($i)"
  sleep 1
  echo "scsi add-single-device 0 0 0" > /proc/scsi/scsi
  echo "scsi add-single-device 1 0 0" > /proc/scsi/scsi
  echo "scsi add-single-device 2 0 0" > /proc/scsi/scsi
  /bin/devfsd /dev -np
  i=$((i+1))
done

#umount /proc as it will be remounted by the normal init process
umount /proc

#now we simply exit, and the normal boot process should continue
exit 0


All we are doing is loading the appropriate modules to support the external drive: they should be uncommented as required. (I built all the required support into my kernel, hence no modules are required.) We then loop, rescanning the SCSI bus (by echoing a command to a special file in the /proc pseudo-filesystem and calling devfsd) until the root device (/dev/sda1 in my case) is present. In my case, the emulated FireWire SCSI bus in question is 1 0 0, but it doesn't hurt to try a few others -- if you know which one you will be using, you can tailor the script. Also, if you have other SCSI devices (or emulated SCSI devices), the drive may have a different letter (for example, /dev/sdb1). And if you are not using the first partition on the external drive, you will need to use a different number (for example, /dev/sda2).

All we now need to do is copy the relevant files into the initrd image (you can mount the uncompressed image using the mount -o loop command). In particular, we need to ensure that we have the linuxrc file, all of the commands used therein, and any libraries that those commands rely on. The (unmounted) image can then be optionally compressed.

The kernel (bzImage) and the initrd image (initrd.gz) are then copied to the (bootable, ext3) floppy.

The final step is to install a boot loader on the floppy, and boot the kernel with the following options: kernel bzImage root=/dev/sda1 initrd=initrd.gz.

You should now be able to boot using the floppy: it will load the kernel from the floppy, load the initrd image into RAM, wait for the root device to be recognized, and then continue to boot as normal from there. From this point onwards, the floppy can be removed.

If a floppy is not appropriate (for example, if the machine has no floppy drive), then any device that can be booted by your BIOS can be used. Personally, I use a little 32Mb USB key for this purpose. Alternatively, if you don't mind altering your internal hard drive, a small partition can be created there for more convenient booting.
发表于 2005-7-25 02:12:18 | 显示全部楼层
在ibm那个网站上看过,呵呵
回复 支持 反对

使用道具 举报

发表于 2005-7-25 09:59:49 | 显示全部楼层
我来 翻译试试看。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-7-25 13:12:57 | 显示全部楼层
Usually, articles from IBM developerworks have Chinese version.  I just unable to find the corresponding article.
回复 支持 反对

使用道具 举报

发表于 2005-7-25 21:22:28 | 显示全部楼层
今天上班的时候翻译了点点.按照这个速度要3天才好翻译出来.现在觉得翻译是件麻烦的事情.要做到雅达信还点难度的.
回复 支持 反对

使用道具 举报

发表于 2005-7-26 00:10:09 | 显示全部楼层
这是来自 IBM developerworks 的一个非常好的文章可以清楚地解释如何启动火线和USB设备 Linux操作系统的原理。

希望它在对任何有兴趣把Linux操作系统安装到外部设备的人有所帮助。
原始的网址http://www-128.ibm.com/developerwor...l-fireboot.html

从火线设备上启动Linux

可移动驱动器上安装Linux操作系统

难度等级:中等

Martyn Honeyford(martynh@uk.ibm.com) IBM英国实验室 软件工程师
宣可达(austin.dada@gmail.com)翻译 webzi@linuxsir


2004年7月15日
2005年7月26日开始翻译

使用一个外部驱动器是一个极棒的方法,能给你的老硬件带来新生和让你在你不能(或者不想)改变内置硬盘的计算机上使用Linux系统。
假设你想使用Linux在一个双启动环境,但是你的计算机硬盘又没有任何空余的空间。一种解决方法是使用"live"的linux发行版本象是Knoppix,他们这能直接从CD启动运行。 对于偶尔使用,这是一种可行的办法,但是它有若干的劣势:

*你将会仍然需要些固定文件存储。如果你只是操作少量的文件,一张1.44MB的磁盘就可以胜任,或者一个USB闪存棒适合中等量的文件,但是这些都不够理想。
*当使用一个LiveCD 的时候,最困难、最糟糕、最不可能的是安装你自己的应用程序或者定制现存的程序。
*使用LiveCD在性能上的牺牲,在启动初所有的设备检测时尤为明显,同样发生使用中(所有的文件从 CD 载入通常是比从硬盘中载入慢的多)。

的确,还有其他可选方案。举例来说,你可以买额外的内置驱动器并且在此安装Linux操作系统。但是常常,你可能没有任何空闲的扩展阜。(这特别容易发生在笔记本上,通常他们只允许一个内置硬盘。)

或者,你可以使用一个较大的硬盘取代当前的硬盘, 获得额外空间用于安装 Linux操作系统。 然而,这的确是一个耗费大量时间的方案,需要你重新安装现有的操作系统在新的硬盘, 重新安装和配置你所有应用程序, 和恢复所有数据。

更好的解决方案是购买一个外置硬盘并安装 Linux操作系统。 这样使得你在想使用Linux系统时候不必涉及现有的硬件和软件而只是简单连接外部驱动器。

可选的可移动设备

可用于安装Linux操作系统设备涵盖磁盘驱动器、USB-闪存设备、通过USB/火线连接的硬盘等等。

在一个小容量的设备中安装linux是可行的,例如在一个1.44MB的磁盘或者一个32MB的USB棒中,他们通常(必须)为特定目的定制,采用裁减的发行版本,例如,拯救中断的安装过程。

外置的硬盘在为使用一个常规目的的linux系统提供最大的灵活性同时,带来一个合理的成本。

许多不同的厂商提供许多种不同容量的外置的驱动器。 (Maxtor, 西西部数据, 等等)。这些驱动器还会包含一个外置盒子,用于固定标准的 3-1/2 寸或 2-1/2 寸 IDE 硬盘。 然后这些驱动器经由 USB 或 IEEE1394(火线) 连接到计算机。

USB 受到在二个主要的版本中的影响,1.1 和 2.0. 1.1 版速度为12 Mbit/ s(每秒1Mbit) ,而 2.0 版支持最高达到 480 Mbit/s 的传输速度。 大多数2.0相容的驱动器也向后兼容1.1,通常建议尽量不要采用1.1接口除非没有其他的选择(因为其低速不适应此环境。)

火线标准也定义若干不同的速度, 实际上,大部分人所指的FireWire ,是“FireWire400”标准 ,支持最大传输速度为 400 Mbit/s 。

USB2.0和火线在速度上不分伯仲: 虽然 USB 2.0 有比较高的传输速度, 但是实际中因为协议的不同两者速度十分的接近。 如果你的计算机拥有2种接口, 最好使用USB而非火线(理由我将后将解释), 但是如果只有火线接口,当然你就选择它了。为了实现最大的灵活性, 可以选择众多同时支持 USB 2.0 和火线的驱动器中的一种。(像我稍后将在这一个文章中使用的那个一样。)

对于那些没有必须的接口, PCI(对于桌面) 和 PCMCIA(对于笔记本型电脑) ,现在火线和USB 2.0扩展卡也并非贵不可及: 举例来说, 我稍后将在文章中提及PCMCIA火线扩展卡大约为10英镑.($20 美元以下)

为了达到本文的目的,我已经购买 5-1/4寸外置驱动器的硬盘盒。 这是一件非常灵活的硬盘盒,并没提供驱动器而且能固定任何的标准 IDE 设备,包括 3-1/2 寸驱动器和像CD-RW/DVD-RW等5-1/4 寸 IDE 设备 。硬盘盒兼有 USB 2.0 和火线接口。

为了把硬盘盒连接到我的IBM Thinkpad T30笔记本电脑,我也购买了一个 PCMCIA 火线转接卡。 ( 因为内置的USB 接口只支持USB 1.1)

硬盘盒和火线转接卡相对比较便宜。 (大约分别为50英镑和10英镑。)

测试期间, 我把一个手边闲置的13 GB 3-1/2 寸 IDE 硬盘放进硬盘盒——对于真实情况,我会买一个较大的容量驱动器, 现在另购一个硬盘相当低廉( 大约每个50英镑!)
回复 支持 反对

使用道具 举报

发表于 2005-7-26 00:13:12 | 显示全部楼层
先贴今天翻译的。第一次翻译。如有何处不妥,请各位指出。
回复 支持 反对

使用道具 举报

发表于 2005-7-26 13:48:11 | 显示全部楼层
Linux 支持

正如你所期待,linux对这些硬盘盒支持的确非常好。任何遵从SBP(串行总线协议)标准的大储存设备在linux中使用非常简单。

大体上, 使对这些装置的支持你能够将会需要在你的核心中支持某些选项( 或直接地编译或通过模块。)

对于USB和火线,SBP 装置通过SCSI模拟来实现-- 也就是说,Linux会把他们当作SCSI硬盘来处理 。 这是在 Linux 世界里面使用存储设备的一个常规方法。 ( 举例来说, IDE CD/DVD设备通常通过SCSI模拟来连接)。基于以上原因,下列的选项需要被内核支持:

* SCSI support
* SCSI emulation
* SCSI disk support

除此之外,不同连接方式需要一下的内核支持:

* 针对火线:
* IEEE1394 support
* OHCI1394 support
* RAW1394 support
* SBP-2 support

* 针对USB:
*(host-side) USB support
* OHCI support
* UHCI support
* USB mass-storage support

明显地,你还必须为其他的硬件 ( 如显卡等等)编译常规的支持, 而且可能需要一些额外的模块,取决你的具体硬件。

举例来说,我正在使用 PCMCIA(cardbus) 火线转接卡,因此,我还需要增加:

* PCMCIA support
* cardbus support

安装

现在我们有很完美外置驱动器,我们将开始安装在其安装Linux美妙之旅。

目前最简单的安装linux方法(当然仅个人意见) , 是连接你的所有硬件;(我的情况是,插入火线转接卡,连上转接线盒驱动器,然后打开驱动器的电源) 然后从你选择的发行版安装CD上启动你的计算机。

我采用的发行版是Gentoo(资源详见链接),因此,我用了最新的 “通用”x86 LiveCD。 (2004.1) 其他的发行版本必须的步骤大致和此相似。

一旦你使用安装CD启动,要藉由一点运气让他要辨认出你的驱动器。 磁盘应该出现在/dev/sdX, X 是一个小写字母从“a”开始。 在我的系统上,外置硬盘被当做 /dev/sda, 但是如果你有其他的 SCSI硬盘,这数字将会改变;( 或模拟了SCSI硬盘) 那种情况下,它可能是 /dev/sdb 或一些其他的字母。 如果你的驱动器不能被自动检测到, 就需要进一步采取措施 -- 举例来说,你可能必须打开启动选项使用火线或者PCMCIA接口, 或你可能必须手动装载一些内核模块 , 或其他一类选项。 (资源详见故障发现与维修指导链接)

一旦驱动器被辨认出来,安装过程种其运作起来就像一个内置的硬盘。然后就你可以对其分区并且用常规方法安装linux。

有一句话我着重要提醒,小心选择何处安装boot loader(通常是GRUB和LILO)--我建议不要装到主引导记录(MBR)中( 通常是默认值) 而是装到外置驱动器的根分区 ( 或/boot分区,如果你单独分了一个话)。

既然我们已经安装 Linux 在这个设备上,我们想要从上面启动它。 事情到此开始变的有点复杂了。
回复 支持 反对

使用道具 举报

发表于 2005-7-26 15:23:33 | 显示全部楼层
启动

在我前讨论在如何的新驱动器上面启动,我要讲解一些boot loader的小知识。

boot loader程序通常安装在计算机的第一个硬盘的MBR上。 当boot loader被调用 (BIOS自动地运行MBR里的代码),它通常显示一份可启动操作系统的菜单。以便选择一个给定的操作系统启动计算机。

两件细节在这个章节中应该注意:

* 操作系统选择菜单(通常)从磁盘中载入。
*为了启动有关的操作系统, boot loader 需要从磁盘中读取相关的内核。

在操作系统被装载之前 ,以上各步骤已经执行,这意味着所有的磁盘读取在BIOS调用时。 这是一个必须的前提,即,为了直接启动磁盘,你的 BIOS必须支持通过火线或USB被连接的磁盘。通常能在BIOS中看到关于从这些设备上启动选项。 火线BIOS支持现在的确非常的少见,但是 USB 支持正在变得相当的平常。 因此,如果你正在使用一部相对比较新的计算机上的USB接口,应该可以直接启动驱动器进Linux。

当经由 USB 连接,在安装外部的驱动器的 MBR 的幼虫之后,我能够直接地启动它。 当以被连接的磁盘片启动的时候,只是进入 BIOS 装备公用程序。 外部的磁盘片将会出现如一个一般的硬盘: 移动它,如此它在启动次序中的内在驱动器之前。

我也能够在一个内置的硬盘的MBR上安装一个boot loader而且使用其启动USB硬盘(在GRUB中被成为hd1)。 如果你正在使用火线, 有可能你的 BIOS 将会无法直接地启动硬盘,而且你需要更多一点步骤。

幸运的是,由于 Linux 的多样性,这有非常容易解决,如果你不能直接地启动,( 我就是这样的情况,使用一个PCMCIA转接卡!) 你能运行初始启动步骤,来自一个支持的设备 , 像是一台软驱,CD-ROM,USB棒,或在主硬盘上的小分区, 然后使用外部的驱动器继续其他步骤。

创建一个启动镜像

我们有2种方法启动:

*单阶启动
内核启动, 挂载根分区文件系统, 接着调用初始化教本继续初始化( 通常是/sbin/init)
*双阶启动 (initrd)的启动
内核启动,挂载一个初始ram disk (initrd),进一步运行定制的初始化, 然后挂载根分区文件系统继续初始化(同样, 通常调用/sbin/init)

每种方法都有它自己的优点和缺点。

单阶启动

为了要使用一个单阶的启动,我们需要建立一个内核包含挂载一个根分区文件系统所需的所有驱动程序。( 任何其他的驱动能作为模块编译并在根分区载入时候进行常规初始化。)

如果我们正在从像软盘这样的一个非常小的装置尝试启动, 最好的方式是创建的一个正合适内核,编译进所有挂载根外部分区系统所需驱动 -- 而且编译其他的作为模块。 举例来说,我的内核编译进了SCSI支持, PCMCIA 支持, IEE1394 , SBP ,和其他相似的支持, 但是其他的(包括显卡支持,网络设备支持,等等)当做模块编译并储存在根分区上(在外部的驱动器的),而不是存储在软盘上。
回复 支持 反对

使用道具 举报

发表于 2005-7-28 00:22:57 | 显示全部楼层
这种方法的主要问题是需要我们给内核源代码打补丁-- 那是一种最糟糕的痛苦(当新的内核发布),而真正的问题是如果补丁没有在维护,这样就不能跟上内核的变化。

你可能以为如果计算机BIOS支持USB和火线直接启动,我们能避免发生以上的2个问题。 不幸地,事情不是这样:这一个方法使用BIOS在启动时调用磁盘,一旦内核开始初始化, BIOS就失去了作用,而且使用内核驱动来调用磁盘-- 所以你仍然会碰到同样的问题。

二阶启动

内核2.0.X版本 ,添加了一个有趣的功能到内核 -- 使用“initial RAM disk(初始内存磁盘)”(or initrd)来实现二阶启动。

简言之,内核一概既往的启动;挂载一个创建在内存里迷你的根分区文件系统取代挂载“真正”的根分区系统。 无论任何命令都在这个初始环境中执行在“真正”的根分区系统被挂载之前直到我们切换到真正的根分区文件系统并销毁初始内存磁盘(initial RAM disk)。

这点在各种环境中都非常有用,但是我们的目标仅仅是简单的利用我们的迷你环境去重新扫描SCSI总线,等待外部驱动器识别,然后用它切换到我们真正的根而后继续启动。

使用这种方法,我们需要创建2个文件,一个内核和一个初始镜像文件。

内核仅是一个内建启动镜像(initrd)支持常规内核。 initrd 镜像是一个包涵我们迷你根分区系统的环路(loopback)文件系统镜像。 (该镜像可以有选折地使用gzip压缩来减小它的大小)。

你能在资源章节里找到关于如何创建和定制你自己的初始镜像的更多信息。

在镜像文件里,有一个linuxrc的文件。当镜像给载入时,该文件自动运行,所以请确定其有运行权限!为了达到我们的目的,linuxrc文件非常的简单:

列举 1. initrd linuxrc

#!/bin/sh
REAL_ROOT=/dev/sda1
# mount the /proc filesystem
mount -t proc none /proc

#for scsi-emulation (SCSI模拟)
# modprobe sd_mod

#for pcmcia (PCNCIA卡)
# modprobe pcmcia_core

#for FireWire (火线)
# modprobe ieee1394
# modprobe ohci1394
# modprobe raw1394
# modprobe sbp2

#for USB (USB)
# modprobe usbcore
# modprobe ohci-hcd
# modprobe uhci-hcd
# modprobe usb-storage

# loop rescanning the scsi bus + rerunning devfsd
retries=5
i=1
until [ -e $REAL_ROOT ]
do
if [ $i -gt $retries ]
then
echo "Unable to mount real root ($REAL_ROOT) - Giving up!"
/bin/ash
exit
fi

echo "Real root ($REAL_ROOT) not found, retrying ($i)"
sleep 1
echo "scsi add-single-device 0 0 0" > /proc/scsi/scsi
echo "scsi add-single-device 1 0 0" > /proc/scsi/scsi
echo "scsi add-single-device 2 0 0" > /proc/scsi/scsi
/bin/devfsd /dev -np
i=$((i+1))
done

#umount /proc as it will be remounted by the normal init process
(解除挂载/proc分区当它会给常规的INIT进程重新挂载)
umount /proc

#now we simply exit, and the normal boot process should continue
(现在我们可以退出了,常规的启动进程将会继续)
exit 0

我们正在做的是载入适当的模块去支持外部驱动器: 请按需注视相应行。 (我把所有需要的支持编译进内核,因此不需要模块)。 然后循环, 再扫描 SCSI 总线 (回应一个命令到/proc虚拟文件系统下一个特别文件并调用devfsd程序) 直到根分区设备出现(我的情况是/dev/sda1 )。在我的情况,被访问的火线模拟SCSI总线是1 0 0,但是并不影响尝试部分其他的总线 -- 如果你知道将会使用哪一个,你可以裁减这个教本。 同时, 如果你有其他的 SCSI 设备 (或模拟 SCSI设备), 驱动器可能有一个不同的字母。(例如,/dev/sdb1) 而且如果你没有使用外置驱动器上的第一个分区, 你将会需要使用一个不同的数字。( 例如,/dev/sda2)

现在我们需要做的全部是复制相关的文件进initrd镜像.( 你能够使用mount -o loop 命令挂载未压缩的镜像)尤其,我们需要确定我们有 linuxrc 文件、所有被用到的命令和其依赖的库。 这个(未挂载的)镜像可以有选折的压缩。

复制内核 (bzImage) 和 initrd 镜像 (initrd.gz)到磁盘。

最后的步是在磁盘上安装一个boot loader, 而且用下列的选项启动内核: kernel bzImage root=/dev/sda1 initrd=initrd.gz.

你现在应该可以使用磁盘来启动了:它会从软盘中载入内核,载入initrd镜像入内存,然后从那里继续常规启动。这点以后,磁盘就可以拿开了。

如果磁盘不合适 ( 例如,计算机没有软驱),任何设备在BIOS能用于启动都可以使用。 个人而言,我就使用一个小小的32MB的USB棒来达到这个目的。 另外,如果你不介意改变你的内置硬盘,这里创建一个小的硬盘分区更方便启动。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表