个人工具

“UbuntuHelp:BootFromUSB/zh”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(New page: {{Translation|}} {{From|https://help.ubuntu.com/community/BootFromUSB}} {{Translator|ekeng}} {{Languages|UbuntuHelp:BootFromUSB}} This page explains how to boot an Ubuntu system which is ...)
 
 
(未显示6个用户的30个中间版本)
第1行: 第1行:
{{Translation|}}
+
{{Copyedit translation|from=https://help.ubuntu.com/community/BootFromUSB}}
 
{{From|https://help.ubuntu.com/community/BootFromUSB}}
 
{{From|https://help.ubuntu.com/community/BootFromUSB}}
{{Translator|ekeng}}
+
{{Translator|ekeng dewafer}}
 +
{{Verifier|}}
 
{{Languages|UbuntuHelp:BootFromUSB}}
 
{{Languages|UbuntuHelp:BootFromUSB}}
  
This page explains how to boot an Ubuntu system which is installed on a USB device when the computer does not support USB booting
+
本文解释如何从一个不支持USB启动的计算机上启动已安装在USB设备上的Ubuntu系统.
  
== Introduction ==
 
  
If you want to install Ubuntu onto a USB drive, such as a large "USB stick" or an external hard drive it is often impossible to boot this system on slightly older computers. This guide explains how to create a bootable CD which will load the USB system.
+
== 介绍 ==
  
Some recent computers lack the BIOS option (or menu entry) to boot from a USB drive, but they are often capable of detecting the USB drive, in which case ''grub'' can be used to boot the drive.
+
安装在 USB 设备(如记忆棒,移动硬盘)上的 Ubuntu,通常是不能在老机器上启动的。本指南是解释如何制作一个可以加载 USB 系统的启动 CD。
  
== How It Works ==
+
现在的有些电脑没有从 USB 启动的 BIOS 选项(或菜单项),但它们往往都可以检测到 USB 设备。这种情况下,我们可以用 ''grub'' 来启动 USB 设备。("grub"是一种系统引导管理器——译者注)
  
PCs use a system called the BIOS (Basic Input/Output System) to start the machine. Even though a few features have been added to many BIOSs over the last 25 years the BIOS system is still extremely limited, as it is part of the "bootup" procedure (so called because the computer has to "pull itself up by its boot straps", a feat which is impossible in real life but aptly describes how a simple electrical current supplied with a power switch can start a chain reaction of activating ever more complex electronics until the computer system is up and running. The BIOS is key to this, so it cannot be very complex). There have been several alternatives for the BIOS system such as the Amiga Kickstart, which uses up to half a megabyte of ROM chips to store large parts of the operating system (although this makes booting Linux on an Amiga slightly more difficult since we do not want the AmigaOS which is in the Kickstart chips) and more recently the EFI system used in Intel based Apple Macs, but for now the PC system is stuck with the BIOS, and this guide is for those of you who's "extra features" don't extend to USB support. So, how do we get around these inherent limitations in the computer's boot system? The answer is that we can't. Instead we must add another layer to the bootup procedure by adding a piece of software which the BIOS can access, and which in turn can access the USB drive for us. Luckily there is already an excellent piece of software which can understand USB devices and its name is Linux. As long as there is a Linux kernel on a device which the BIOS can understand then we can let this Linux kernel take over to do what we want. Additionally, in some cases the ''grub'' boot loader can do the job directly, without the need of a linux kernel.
+
== 它是如何工作的 ==
  
A stripped down Linux kernel will fit onto a high density (1.44MB) floppy disk, but the standard Ubuntu kernel doesn't quite. Also, the standard Ubuntu kernel does not have all of the drivers needed to boot a USB drive, thus these extra driver modules must be put into the "initial RAM disk" image (abbreviated to "initrd") which gets copied into the RAM during boot to enable the kernel to access the extra modules it contains. Most PCs can boot from a CDROM drive, and writable CDs can store more than enough data to allow Linux and an initrd to fit comfortably (that's how "live CDs" work) so we will use this method to boot. Since the kernel and initrd get copied into RAM during boot and run from there (the RAM based initrd is not needed once the kernel has access to the main drive anyway) it is not necessary for the CD to be in the drive after booting has finished, so if you only have one CDROM drive it will not be tied up like it would with a live CD.
+
个人计算机使用一种叫 BIOS(基本输入/输出系统)的系统来启动。因为只是"启动"过程的一部份,所以过去25年来,虽然很多 BIOS 已经增加了少数特性,但 BIOS 系统的作用仍然十分有限(由于计算机需通过引导程序启动, 这种在现实生活中不可能发生的方式,但是却恰如其分地描述了在计算机启动和运行时,由电源开关控制的一个简单的电流可以启动一系列的连锁行为直至更加复杂的电子行为。这就是 BIOS 的关键,还不算太复杂)。
  
So now we know how Ubuntu can be booted from CD into a USB drive in theory, it is time to put it into practice.
+
目前有很多 BIOS 系统的替代品,例如 Amiga Kickstart,它使用高达 1M 字节的 ROM 芯片来存储操作系统的大部分东西(但是这使在 Amiga 上启动 Linux 变得更加困难,因此我们不使用在 Kickstart 芯片上的 AmigaOS),以及最近的 EFI 系统使用的是基于 Intel 的苹果操作系统,但是现在的个人计算机仍然停留在BIOS。本指南给那些计算机的"额外特征"没有 USB 支持的扩展功能的用户。然而,我们可以从这些在计算机启动系统中固有的限制里得到什么呢?答案是不能。相反,我们还要在启动过程增加其他的层通过增加 BIOS 能访问的软件,接着就可访问 USB 设备。幸运的是,已经有一款优秀的软件可以读取 USB 设备,它就是 Linux。只要在设备里写入 BIOS 能识别的 Linux 内核,我们就可以让 Linux 内核接管我们想要做的事。另外,一些情况下,''grub'' 启动引导器可以不用 Linux 内核而直接工作。
  
== Booting via grub ==
+
精简了的 Linux 内核可以放进一张高密度 (1.44MB) 软盘,但标准的 Ubuntu 内核则不大可能。而且,标准的 Ubuntu 内核并没有从 USB 设备启动所需要的所有驱动程序。因此这些额外的驱动模块必须被放进“初始化 RAMDISK ”映像 (缩写为 "initrd")。这一映像在启动过程中被复制到 RAM,以使内核能够读取它所包含的那些额外模块。多数 PC 都能从 CDROM 启动,可写的 CD 能够存储比足够数据更多的内容,这使得 Linux 和一个 initrd 可以很容易地被写入其中(这也就是“live CD"的原理),因此我们就用这种方法来启动。既然内核和 initrd 在启动时被复制到了 RAM 并在那里运行(一旦内核可以读取主要的驱动器,那么以 RAM 为基础的 initrd 就不再需要了),启动完毕后就没有必要把 CD 继续留在光驱里了。所以如果你只有一个CDROM驱动器,那么除了使用 live CD 时必须用到它,光驱并非一刻也离不开的。
  
This is the easiest way, and has been proven to work on several laptops from 2002-2005.
+
那么我们现在已经知道 Ubuntu 理论上如何才能从 CD 启动到 USB 驱动器,下一步应该将其付诸实践了。
To check if your BIOS is able to detect the USB drive and hand it over to grub, just run grub (from your hard drive if it already installed, or from a grub boot floppy or CD). At the grub menu, hit 'c' to enter command mode. Now search for your USB drive, using the <code><nowiki>root</nowiki></code> command to choose a drive/partition and the <code><nowiki>find</nowiki></code> command to see if you found the right one. You can go through your devices like in this example:<pre><nowiki>
+
grub> root (hd0,0)  # first harddrive, first partition
+
grub> find /[tab]    # type the slash then press [tab], and it will try to list files on this partition
+
Error 17: Cannot mount selected partition  # Oops no file system here
+
grub> root (hd0,1)  # first harddrive, second partition
+
grub> find /[tab]
+
Possible files are: lost+found var etc media ...  # That was my hard drive with my linux install
+
grub> root (hd1,0)  # second hard drive usually is the USB drive if you have only one internal drive
+
grub> find /[tab]
+
Possible files are: ldlinux.sys mydoc myfile mystick syslinux.cfg  # Bingo, that's the USB stick
+
</nowiki></pre>
+
(If you have 2 internal drives, the USB drive probably is <code><nowiki>hd2,0</nowiki></code> and so on.)
+
  
Or, if you know that there is a file called e.g. "MYDRIVE" on the drive, just run
+
== 通过grub启动 ==
<pre><nowiki>
+
grub> find /MYDRIVE
+
</nowiki></pre>
+
and grub will look through all drives and partitions that it can access. It will list the correct device to use for the <code><nowiki>root</nowiki></code> command.
+
  
Boot the drive by entering:
+
这是最简单的办法了。从 2002-2005 就已经被证明适合于数种笔记本电脑。要想检查你的 BIOS 是否能检测 USB 驱动器并交付给 grub,只需运行 grub(如果已经安装,那就在硬盘上运行,也可以从 grub 启动软件或 CD 运行)。在 grub 菜单中,选 'c' 即可进入命令行模式。现在搜索 USB 驱动器,用 <code><nowiki>root</nowiki></code> 命令选择一个驱动器或分区,用 <code><nowiki>find</nowiki></code> 命令查看是否找到了正确的那一个。可以像下面这个例子一样浏览各个设备:
<pre><nowiki>
+
<pre>grub&gt; root (hd0,0) # 我们选择第一个驱动器上的第一个分区
chainloader +1
+
grub&gt; find /[tab] # 键入斜杠(/),然后按下 [tab],它会列出分区中的所有文件
 +
Error 17: Cannot mount selected partition # 喔,这个分区不存在...
 +
grub&gt; root (hd0,1) # 选择第一个驱动器上的第二个分区
 +
grub&gt; find /[tab]
 +
Possible files are: lost+found var etc media ... # 这就是我的 Linux 系统分区
 +
grub&gt; root (hd1,0) # 第二个驱动器应该就是 USB 设备了,如果你只有一个硬盘的话
 +
grub&gt; find /[tab]
 +
Possible files are: ldlinux.sys mydoc myfile mystick syslinux.cfg # OK,我的 U 盘找到了
 +
</pre>
 +
(如果你有两个内部驱动器,USB 驱动器可能是 <code><nowiki>hd2,0</nowiki></code> 等。)
 +
 
 +
或者如果你知道在驱动器上存在某个文件,比如叫作 "MYDRIVE",那么只要运行
 +
<pre>grub&gt; find /MYDRIVE
 +
</pre>
 +
这样 grub 就可以搜索它能访问的所有驱动器和分区。它会列出 <code><nowiki>root</nowiki></code> 这一命令使用的正确设备。
 +
 
 +
启动这一驱动器,输入如下内容:
 +
<pre>chainloader +1
 
boot
 
boot
</nowiki></pre>
+
</pre>  
For convenience, add these commands to your grub configuration (usually in <code><nowiki>/boot/grub/menu.lst</nowiki></code>):
+
为方便起见,可把这些命令加到你的grub配置中去(通常在<code><nowiki>/boot/grub/menu.lst</nowiki></code>):
<pre><nowiki>
+
<pre>title Boot USB drive
title   Boot USB drive
+
root (hd1,0)
root     (hd1,0)
+
 
chainloader +1
 
chainloader +1
 
boot
 
boot
</nowiki></pre>
+
</pre>  
Of course, if you don't have grub installed on your hard drive, change the menu.lst on your grub floppy or CD.
+
当然如果你的硬盘上没有安装 grub,那就把你的 grub 软盘或 CD 上的 menu.lst 改一下。
  
If you are not able to find the drive with the help of grub, you have to use the linux kernel as explained in the next section.
+
如果你在 grub 的帮助下找不到驱动器,那就只能使用 linux 内核了,下个部分会有解释。
  
== Using a Linux Kernel ==
+
== 使用Linux内核==
  
You can install Ubuntu using a regular CD or DVD, since you will be booting from discs which contain a Linux kernel and all of the driver modules needed to acces your USB drive. The only difference you may notice is that your drive will be called "/dev/sda" instead of the regular "/dev/hda" which you may find in many guides.
+
你可能使用常规的CD光盘或DVD来安装Ubuntu, 因为您将从包含Linux内核和所有必需的驱动模块的盘片上启动,从而控制您的USB设备.有唯一的不同点应该注意一下,就是这时称您的驱动器为 "/dev/sda"而不是常规的"/dev/hda",这也可以从很多指南中找到.
  
Once the installation has finished using the disc you must reboot into your new USB system. This is where you need a bootable CD. It is easiest to make such a CD from another Ubuntu system, slightly harder from a different Linux system, and quite hard on a Windows system. It is usually easiest to boot from an Ubuntu Live CD.
+
一旦使用盘片安装完成,您必须重启进入新的USB系统.这里需要一个可启动的CD.从其他的Ubuntu系统制作这样一个CD是最简单的,从其他的Linux系统更难些,在Windows中制作就相当的难了.从Ubuntu Live CD启动通常最简单的.
  
To build your own boot CD you will need to mount your system from within the Live CD (this is describe here [[UbuntuHelp:Mount]]). Once that is done it is time to add the needed modules to your initrd. To do this you must run:
+
 
 +
为了建立您自己的boot CD,您将需要从Live CD内装载您的系统(请参考 [[UbuntuHelp:Mount]])。一旦装载完成,就该把需要的模块加入您的initrd中去了。您可以运行:
 
<pre><nowiki>
 
<pre><nowiki>
gksudo gedit /wherever_you_have_mounted_your_system/etc/mkinitramfs/modules
+
gksudo gedit /''挂载您系统的目录''/etc/mkinitramfs/modules
 
</nowiki></pre>
 
</nowiki></pre>
Which will open the text editor with that file. You need to add these lines to the end of the file:
+
该命令会使用一个文本编辑器打开该文件,您需要在该文件末尾加入下列几行:
 
<pre><nowiki>
 
<pre><nowiki>
 
usbcore
 
usbcore
第78行: 第79行:
 
scsi_mod
 
scsi_mod
 
</nowiki></pre>
 
</nowiki></pre>
(It is always a good idea to put comments in any manually changed configurations so you don't get confused later) Now save the file and exit gedit.
+
(在手动修改的配置文件中加入注释是一个很好的习惯,这样您就不会在以后搞糊涂了)现在可以保存文件并退出文本编辑器了。
  
There is one small problem before we carry on. USB drives take a few seconds before they are set up properly by Linux, and your boot would fail before your drive becomes accessible. To sort this we need to tell the initrd to wait a few seconds before it gets carried away and fails. You can do this by running:
+
在我们继续之前有个小问题,Linux在正确建立USB驱动器之前需要几秒钟时间,在驱动器可用之前启动可能会失败。为了解决这个问题,我们需要告诉initrd在继续启动和失败之前等待几秒钟,您可以通过运行下列代码解决:
 
<pre><nowiki>
 
<pre><nowiki>
gksudo gedit /wherever_you_have_mounted_your_system/etc/mkinitramfs/initramfs.conf
+
gksudo gedit /''挂载您系统的目录''/etc/mkinitramfs/initramfs.conf
 
</nowiki></pre>
 
</nowiki></pre>
Now to this you should add at the very top the lines:
+
现在在这个文件最顶部加入:
 
<pre><nowiki>
 
<pre><nowiki>
 
WAIT=15
 
WAIT=15
 
</nowiki></pre>
 
</nowiki></pre>
Then save the file and exit the text editor.
+
然后保存文件并退出文本编辑器。
  
Now that we have corrected the initrd's setup we must use this setup to rebuild the initrd using our new guidelines. To do this you must enter your system by running:
+
现在我们已经修正了initrd的设置,我们必须使用这些设置来重新建立使用我们新策略的initrd。如此您必须运行下列代码来进入您的系统:
 
<pre><nowiki>
 
<pre><nowiki>
sudo mount --bind /dev /wherever_you_have_mounted_your_system/dev
+
sudo mount --bind /dev /''挂载您系统的目录''/dev
sudo chroot /wherever_you_have_mounted_your_system
+
sudo chroot /''挂载您系统的目录''
 
mount -a
 
mount -a
 
</nowiki></pre>
 
</nowiki></pre>
Now that you are in your system you can rebuild your initrd by reconfiguring Linux with the command
+
现在您已经进入了系统,您可以使用以下代码重新配置Linux来重建您的initrd
 
<pre><nowiki>
 
<pre><nowiki>
 
dpkg-reconfigure linux-image-<kernelversion>
 
dpkg-reconfigure linux-image-<kernelversion>
 
</nowiki></pre>
 
</nowiki></pre>
Where <kernelversion> is the version of Linux you have installed that you wish to reconfigure. The default for Dapper is 2.6.15-23-386, but you can see all of the possible versions with (from within your system):
+
kernelversion>代表您想重新配置的已安装的Linux版本。Dapper默认是2.6.15-23-386。您也可以使用以下代码查看所有可用的版本(从您的系统中)
 
<pre><nowiki>
 
<pre><nowiki>
 
apt-cache search linux-image-2.6
 
apt-cache search linux-image-2.6
 
</nowiki></pre>
 
</nowiki></pre>
Or
+
或者
 
<pre><nowiki>
 
<pre><nowiki>
 
ls /lib/modules
 
ls /lib/modules
 
</nowiki></pre>
 
</nowiki></pre>
If the reconfigure command was successful there should be some lines about rebuilding initrd, updating GRUB, etc. Now you can find your new initrd and matching kernel in /boot of your system (that is /wherever_you_mounted_your_system/boot in the Live CD's system) and they are called initrd.img-<kernelversion> and vmlinuz-<kernelversion>. You should exit from the chroot now by pressing ctrl-d. Now you need to copy these files, along with a configuration file for the bootloader GRUB, to the Live CD's home folder with the commands:
+
如果重新配置命令运行成功了,您应该会看到一些有关重新建立的initrd、更新的GRUB等的命令行。您能在/boot(在Live的文件系统中的 /''挂载您系统的目录''/boot)中找到新的initrd和相应的内核了,并且名为initrd.img-<kernelversion>和vmlinuz-<kernelversion>。现在按键ctrl-d从chroot中退出。然后您需要用以下命令来复制这些文件到Live CD的主文件夹中,包括一个为启动引导GRUB准备的配置文件。
 
<pre><nowiki>
 
<pre><nowiki>
cp /wherever_your_system_is_mounted/boot/initrd.img-<kernelversion> ~
+
cp /''挂载您系统的目录''/boot/initrd.img-<kernelversion> ~
cp /wherever_your_system_is_mounted/boot/vmlinuz-<kernelversion> ~
+
cp /''挂载您系统的目录''/boot/vmlinuz-<kernelversion> ~
cp /wherever_your_system_is_mounted/boot/grub/menu.lst ~
+
cp /''挂载您系统的目录''/boot/grub/menu.lst ~
 
</nowiki></pre>
 
</nowiki></pre>
Now that you have a kernel which can boot your USB drive it is time to put it on a bootable CD. You will need to download [ftp://alpha.gnu.org/gnu/grub/grub-0.97.tar.gz this archive of the GRUB source code] and extract it to obtain the "stage2_eltorito" file inside. Now that you have the needed files we can make your CD.
+
现在您已经有一个能从您USB驱动器启动的核心了,可以把它放到可启动CD上。您需要下载[ftp://alpha.gnu.org/gnu/grub/grub-0.97.tar.gz 这个 GRUB 源代码包]解压缩后获得其中的"stage2_eltorito"这个文件。现在制作您CD所需要的文件已经集齐了。
 +
 
 +
在Live CD的主文件中新建一个文件夹,将其命名为"bootcd"。然后在"bootcd"文件夹中创建另外一个文件夹,命名为"boot"。同样在"boot"文件夹中建一个名为"grub"的文件夹。现在复制stage2_eltorito和menu.lst到这个新建的"grub"文件夹,在"grub"上层文件夹"boot"中,将vmlinuz和initrd文件复制进去。将vmlinuz-<version>文件重命名为简单的"vmlinuz",同样将initrd.img-<version>文件重命名为简单的"initrd.img"(这意味着您等会儿将不需要更改您的配置文件来指向任何新文件名)使用文本编辑器编辑menu.lst文件,查找文件最底部实际OS启动入口所在之处,删除旧的建立两个新的启动入口(如果不正确请将/dev/sda1更改为您的启动分区):
  
Make a folder in the Live CD's home folder called "bootcd", then inside there make another called "boot" and inside there one called "grub". Now copy the stage2_eltorito and menu.lst to this new "grub" folder and copy the vmlinuz and initrd files into the "boot" folder above it. Rename the vmlinuz-<version> file to simply "vmlinuz" and the initrd.img-<version> file to simply "initrd.img" (this means you won't have to change your configuration later to point to any new filenames) Edit the menu.lst file with the text editor and look at the bottom where the actual OS entries are. Delete what is there and make two new entries (replace /dev/sda1 with your root partition if this is not correct):
 
 
<pre><nowiki>
 
<pre><nowiki>
 
title          Ubuntu
 
title          Ubuntu
第130行: 第132行:
 
boot
 
boot
 
</nowiki></pre>
 
</nowiki></pre>
By default the top entry will be booted. You can change some of the other options here if you want a hidden menu or a different timeout before the default entry is booted (never set this to zero or you will not be able to enter recovery mode). That is the entire contents of your bootable CD, so now we have to build it. Open a terminal (by default it will be in the home folder) and run (all on one line):
+
默认会从第一个启动入口启动,您可以随意更改一些其他选项,例如您希望有一个隐藏的目录或者在默认启动入口启动之前有一个不同的等待时间(绝不要将其设置为零,否则您将不能启动恢复模式).这就是您可自启动CD的所有内容,所以现在我们来创建它,打开一个终端窗口(它将默认在主文件夹中)并且运行(所有的命令都在一行中):
 +
 
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o UbuntuBootCDForUSB.iso bootcd
 
sudo mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o UbuntuBootCDForUSB.iso bootcd
 
</nowiki></pre>
 
</nowiki></pre>
You should now have a CD image called UbuntuBootCDForUSB.iso which you can write to a recordable CD using many common CD writing programs such as the one built into the Nautilus file manager (Ubuntu's default file manager), GnomeBaker, k3b, Nero and many more. If you don't have your CDR/W drive accessible (because you are running a LiveCD in it) then you can copy the CD image to /wherever_you_have_mounted_your_system to keep it safely stored on a real drive. You should also copy over the "bootcd" folder. This can be done with:
+
现在您有了一个名为UbuntuBootCDForUSB.iso的CD镜像.您可以使用许多常用的CD刻录程序,如内建的Nautilus文件管理器(Ubuntu的默认文件管理器)GnomeBaker,k3b,Nero等将它烧入可写入CD.如果您的CDR/W驱动器不可用(譬如您正在其中运行LiveCD),您可以将CD镜像拷贝到/''挂载您系统的目录''来保证它储存在一个可靠的驱动器上.您同样需要拷贝"bootcd"文件夹,可以使用以下命令:
 +
 
 +
 
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo cp UbuntuBootCDForUSB.iso /wherever_you_have_mounted_your_system
 
sudo cp UbuntuBootCDForUSB.iso /wherever_you_have_mounted_your_system
 
sudo cp -r bootcd /wherever_you_have_mounted_your_system
 
sudo cp -r bootcd /wherever_you_have_mounted_your_system
 
</nowiki></pre>
 
</nowiki></pre>
They will now be accessible in your / directory (move them out of there once your system is set up as this is an important directory and should not be cluttered). You can save the iso file to a FAT formatted USB stick (obviously not one you have just set up with Linux) to transfer the CD image to Windows where it can be written by Nero.
+
现在它们可进入您的/目录(一旦系统装好后就把它们移除,因为这个目录很重要,不应该太杂乱).您可以保存ISO文件到FAT格式的USB盘中(当然不是您刚刚安装Linux的那个),将CD镜像转到Windows下,这样可以用Nero刻录.
  
Now you just have to boot off the CD you have written whilst your USB drive is plugged in and (depending on how you set up GRUB) you will be sent into Ubuntu's boot procedure. (Notice the "Waiting for root filesystem" line? You did that!). If GRUB gives an error then you can edit the bootup lines by pressing "e" with the right entry highlighted in the menu.
+
当USB盘插入后现在您只要从您刻录好的CD启动,接着(这取决于GRUB的安装方式)就进入Ubuntu的启动过程.(注意"Waiting for root filesystem" 这行.您成功了!).如果GRUB发生错误,您可按"e"键编辑菜单上的当前的高亮启动命令行.
  
=== Disadvantages Of This System ===
+
=== 这个系统的缺点 ===
  
Whenever Ubuntu's kernel is updated you will not notice. This is because you will still be running the older kernel from your CD. You can fix this easily by replacing the "vmlinuz" and "initrd.img" files by the new ones in the "bootcd/boot" folder and making a new image by rerunning the above "sudo mkisofs" command (new kernels will automatically contain our modifications since we added the changes to the system's configuration files) After writing the new image to disc you can use it to boot into your new kernel (I would not recommend using a single CDRW disc and overwriting it everytime as you will be in trouble if it doesn't work. Instead I suggest using 2 CDRW discs and updating one. Once that updated disc has been tested and it works then you should update the second disc)
+
当Ubuntu内核更新的时候你并不会注意到,这是因为你仍是从你的CD上运行旧内核。这很容易纠正,只需把"vmlinuz""initrd.img"这两个文件用"bootcd/boot"文件夹中的新版本代替,并重新运行上述"sudo mkisofs"命令来创建一个新的映像(新内核将自动包含我们所做的改动,因为我们已经把变化加入到了系统的配置文件中)。将新映像写到磁盘上之后,你就可以用它来启动新内核了。(我不推荐只使用一张CDRW光盘、每次都覆盖写入,因为如果这样无效的话你就会遇到麻烦。我建议使用两张CDRW光盘,更新一张。一旦这张更新光盘已经被检测并可正常使用,那么你就应该更新第二张光盘了。)
  
== See Also ==
+
== 参考 ==
[http://www.gnu.org/software/grub/manual/html_node/Making-a-GRUB-bootable-CD-ROM.html Building a bootable GRUB CD] - This is GNU GRUB's official documentation which I used when writing this guide
+
[http://www.gnu.org/software/grub/manual/html_node/Making-a-GRUB-bootable-CD-ROM.html 创建一张可启动的GRUB CD] - 这是我写这个指南时使用的GNU GRUB的官方文件。
  
=== Comments ===
+
===评论===
The instructions above assume an Ubuntu system in one partition. I had an extra partition for /boot and I ran into some troubles. In order to avoid this, build the CD from an Ubuntu system mounted generally in / .
+
上述指南假设只在一个分区上安装Ubuntu系统。我曾用另一个分区作为/boot,结果遇到了麻烦。为避免这一点,在从/ 一般挂载的Ubuntu系统中创建CD。
  
 
* Thanks for the info, I added a line to bind /dev to the chroot and a mount -a command, which should take care of that. A /boot partition becomes basically redundant if you use this LiveCD method, so I don't think it would be a common situation. Personally I have only made /boot seperate when using LVM, but with a few extra modules this CD could boot directly to LVM, I may add that later (the CD image is tiny, so more features wouldn't hurt).
 
* Thanks for the info, I added a line to bind /dev to the chroot and a mount -a command, which should take care of that. A /boot partition becomes basically redundant if you use this LiveCD method, so I don't think it would be a common situation. Personally I have only made /boot seperate when using LVM, but with a few extra modules this CD could boot directly to LVM, I may add that later (the CD image is tiny, so more features wouldn't hurt).
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2008年3月1日 (六) 12:56的最新版本


本文解释如何从一个不支持USB启动的计算机上启动已安装在USB设备上的Ubuntu系统.


介绍

安装在 USB 设备(如记忆棒,移动硬盘)上的 Ubuntu,通常是不能在老机器上启动的。本指南是解释如何制作一个可以加载 USB 系统的启动 CD。

现在的有些电脑没有从 USB 启动的 BIOS 选项(或菜单项),但它们往往都可以检测到 USB 设备。这种情况下,我们可以用 grub 来启动 USB 设备。("grub"是一种系统引导管理器——译者注)

它是如何工作的

个人计算机使用一种叫 BIOS(基本输入/输出系统)的系统来启动。因为只是"启动"过程的一部份,所以过去25年来,虽然很多 BIOS 已经增加了少数特性,但 BIOS 系统的作用仍然十分有限(由于计算机需通过引导程序启动, 这种在现实生活中不可能发生的方式,但是却恰如其分地描述了在计算机启动和运行时,由电源开关控制的一个简单的电流可以启动一系列的连锁行为直至更加复杂的电子行为。这就是 BIOS 的关键,还不算太复杂)。

目前有很多 BIOS 系统的替代品,例如 Amiga Kickstart,它使用高达 1M 字节的 ROM 芯片来存储操作系统的大部分东西(但是这使在 Amiga 上启动 Linux 变得更加困难,因此我们不使用在 Kickstart 芯片上的 AmigaOS),以及最近的 EFI 系统使用的是基于 Intel 的苹果操作系统,但是现在的个人计算机仍然停留在BIOS。本指南给那些计算机的"额外特征"没有 USB 支持的扩展功能的用户。然而,我们可以从这些在计算机启动系统中固有的限制里得到什么呢?答案是不能。相反,我们还要在启动过程增加其他的层通过增加 BIOS 能访问的软件,接着就可访问 USB 设备。幸运的是,已经有一款优秀的软件可以读取 USB 设备,它就是 Linux。只要在设备里写入 BIOS 能识别的 Linux 内核,我们就可以让 Linux 内核接管我们想要做的事。另外,一些情况下,grub 启动引导器可以不用 Linux 内核而直接工作。

精简了的 Linux 内核可以放进一张高密度 (1.44MB) 软盘,但标准的 Ubuntu 内核则不大可能。而且,标准的 Ubuntu 内核并没有从 USB 设备启动所需要的所有驱动程序。因此这些额外的驱动模块必须被放进“初始化 RAMDISK ”映像 (缩写为 "initrd")。这一映像在启动过程中被复制到 RAM,以使内核能够读取它所包含的那些额外模块。多数 PC 都能从 CDROM 启动,可写的 CD 能够存储比足够数据更多的内容,这使得 Linux 和一个 initrd 可以很容易地被写入其中(这也就是“live CD"的原理),因此我们就用这种方法来启动。既然内核和 initrd 在启动时被复制到了 RAM 并在那里运行(一旦内核可以读取主要的驱动器,那么以 RAM 为基础的 initrd 就不再需要了),启动完毕后就没有必要把 CD 继续留在光驱里了。所以如果你只有一个CDROM驱动器,那么除了使用 live CD 时必须用到它,光驱并非一刻也离不开的。

那么我们现在已经知道 Ubuntu 理论上如何才能从 CD 启动到 USB 驱动器,下一步应该将其付诸实践了。

通过grub启动

这是最简单的办法了。从 2002-2005 就已经被证明适合于数种笔记本电脑。要想检查你的 BIOS 是否能检测 USB 驱动器并交付给 grub,只需运行 grub(如果已经安装,那就在硬盘上运行,也可以从 grub 启动软件或 CD 运行)。在 grub 菜单中,选 'c' 即可进入命令行模式。现在搜索 USB 驱动器,用 root 命令选择一个驱动器或分区,用 find 命令查看是否找到了正确的那一个。可以像下面这个例子一样浏览各个设备:

grub> root (hd0,0) # 我们选择第一个驱动器上的第一个分区
grub> find /[tab] # 键入斜杠(/),然后按下 [tab],它会列出分区中的所有文件
Error 17: Cannot mount selected partition # 喔,这个分区不存在...
grub> root (hd0,1) # 选择第一个驱动器上的第二个分区
grub> find /[tab]
Possible files are: lost+found var etc media ... # 这就是我的 Linux 系统分区
grub> root (hd1,0) # 第二个驱动器应该就是 USB 设备了,如果你只有一个硬盘的话
grub> find /[tab]
Possible files are: ldlinux.sys mydoc myfile mystick syslinux.cfg # OK,我的 U 盘找到了

(如果你有两个内部驱动器,USB 驱动器可能是 hd2,0 等。)

或者如果你知道在驱动器上存在某个文件,比如叫作 "MYDRIVE",那么只要运行

grub> find /MYDRIVE

这样 grub 就可以搜索它能访问的所有驱动器和分区。它会列出 root 这一命令使用的正确设备。

启动这一驱动器,输入如下内容:

chainloader +1
boot

为方便起见,可把这些命令加到你的grub配置中去(通常在/boot/grub/menu.lst):

title Boot USB drive
root (hd1,0)
chainloader +1
boot

当然如果你的硬盘上没有安装 grub,那就把你的 grub 软盘或 CD 上的 menu.lst 改一下。

如果你在 grub 的帮助下找不到驱动器,那就只能使用 linux 内核了,下个部分会有解释。

使用Linux内核

你可能使用常规的CD光盘或DVD来安装Ubuntu, 因为您将从包含Linux内核和所有必需的驱动模块的盘片上启动,从而控制您的USB设备.有唯一的不同点应该注意一下,就是这时称您的驱动器为 "/dev/sda"而不是常规的"/dev/hda",这也可以从很多指南中找到.

一旦使用盘片安装完成,您必须重启进入新的USB系统.这里需要一个可启动的CD.从其他的Ubuntu系统制作这样一个CD是最简单的,从其他的Linux系统更难些,在Windows中制作就相当的难了.从Ubuntu Live CD启动通常最简单的.


为了建立您自己的boot CD,您将需要从Live CD内装载您的系统(请参考 UbuntuHelp:Mount)。一旦装载完成,就该把需要的模块加入您的initrd中去了。您可以运行:

gksudo gedit /''挂载您系统的目录''/etc/mkinitramfs/modules

该命令会使用一个文本编辑器打开该文件,您需要在该文件末尾加入下列几行:

usbcore
sd_mod
ehci_hcd
uhci_hcd
ohci_hcd
usb-storage
scsi_mod

(在手动修改的配置文件中加入注释是一个很好的习惯,这样您就不会在以后搞糊涂了)现在可以保存文件并退出文本编辑器了。

在我们继续之前有个小问题,Linux在正确建立USB驱动器之前需要几秒钟时间,在驱动器可用之前启动可能会失败。为了解决这个问题,我们需要告诉initrd在继续启动和失败之前等待几秒钟,您可以通过运行下列代码解决:

gksudo gedit /''挂载您系统的目录''/etc/mkinitramfs/initramfs.conf

现在在这个文件最顶部加入:

WAIT=15

然后保存文件并退出文本编辑器。

现在我们已经修正了initrd的设置,我们必须使用这些设置来重新建立使用我们新策略的initrd。如此您必须运行下列代码来进入您的系统:

sudo mount --bind /dev /''挂载您系统的目录''/dev
sudo chroot /''挂载您系统的目录''
mount -a

现在您已经进入了系统,您可以使用以下代码重新配置Linux来重建您的initrd

dpkg-reconfigure linux-image-<kernelversion>

kernelversion>代表您想重新配置的已安装的Linux版本。Dapper默认是2.6.15-23-386。您也可以使用以下代码查看所有可用的版本(从您的系统中)

apt-cache search linux-image-2.6

或者

ls /lib/modules

如果重新配置命令运行成功了,您应该会看到一些有关重新建立的initrd、更新的GRUB等的命令行。您能在/boot(在Live的文件系统中的 /挂载您系统的目录/boot)中找到新的initrd和相应的内核了,并且名为initrd.img-<kernelversion>和vmlinuz-<kernelversion>。现在按键ctrl-d从chroot中退出。然后您需要用以下命令来复制这些文件到Live CD的主文件夹中,包括一个为启动引导GRUB准备的配置文件。

cp /''挂载您系统的目录''/boot/initrd.img-<kernelversion> ~
cp /''挂载您系统的目录''/boot/vmlinuz-<kernelversion> ~
cp /''挂载您系统的目录''/boot/grub/menu.lst ~

现在您已经有一个能从您USB驱动器启动的核心了,可以把它放到可启动CD上。您需要下载这个 GRUB 源代码包解压缩后获得其中的"stage2_eltorito"这个文件。现在制作您CD所需要的文件已经集齐了。

在Live CD的主文件中新建一个文件夹,将其命名为"bootcd"。然后在"bootcd"文件夹中创建另外一个文件夹,命名为"boot"。同样在"boot"文件夹中建一个名为"grub"的文件夹。现在复制stage2_eltorito和menu.lst到这个新建的"grub"文件夹,在"grub"上层文件夹"boot"中,将vmlinuz和initrd文件复制进去。将vmlinuz-<version>文件重命名为简单的"vmlinuz",同样将initrd.img-<version>文件重命名为简单的"initrd.img"(这意味着您等会儿将不需要更改您的配置文件来指向任何新文件名)使用文本编辑器编辑menu.lst文件,查找文件最底部实际OS启动入口所在之处,删除旧的建立两个新的启动入口(如果不正确请将/dev/sda1更改为您的启动分区):

title          Ubuntu
root           (cd)
kernel         /boot/vmlinuz root=/dev/sda1 ro quiet splash
initrd         /boot/initrd.img
boot

title          Ubuntu Recovery Mode
root           (cd)
kernel         /boot/vmlinuz root=/dev/sda1 ro single
initrd         /boot/initrd.img
boot

默认会从第一个启动入口启动,您可以随意更改一些其他选项,例如您希望有一个隐藏的目录或者在默认启动入口启动之前有一个不同的等待时间(绝不要将其设置为零,否则您将不能启动恢复模式).这就是您可自启动CD的所有内容,所以现在我们来创建它,打开一个终端窗口(它将默认在主文件夹中)并且运行(所有的命令都在一行中):

sudo mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o UbuntuBootCDForUSB.iso bootcd

现在您有了一个名为UbuntuBootCDForUSB.iso的CD镜像.您可以使用许多常用的CD刻录程序,如内建的Nautilus文件管理器(Ubuntu的默认文件管理器)GnomeBaker,k3b,Nero等将它烧入可写入CD.如果您的CDR/W驱动器不可用(譬如您正在其中运行LiveCD),您可以将CD镜像拷贝到/挂载您系统的目录来保证它储存在一个可靠的驱动器上.您同样需要拷贝"bootcd"文件夹,可以使用以下命令:


sudo cp UbuntuBootCDForUSB.iso /wherever_you_have_mounted_your_system
sudo cp -r bootcd /wherever_you_have_mounted_your_system

现在它们可进入您的/目录(一旦系统装好后就把它们移除,因为这个目录很重要,不应该太杂乱).您可以保存ISO文件到FAT格式的USB盘中(当然不是您刚刚安装Linux的那个),将CD镜像转到Windows下,这样可以用Nero刻录.

当USB盘插入后现在您只要从您刻录好的CD启动,接着(这取决于GRUB的安装方式)就进入Ubuntu的启动过程.(注意"Waiting for root filesystem" 这行.您成功了!).如果GRUB发生错误,您可按"e"键编辑菜单上的当前的高亮启动命令行.

这个系统的缺点

当Ubuntu内核更新的时候你并不会注意到,这是因为你仍是从你的CD上运行旧内核。这很容易纠正,只需把"vmlinuz"和"initrd.img"这两个文件用"bootcd/boot"文件夹中的新版本代替,并重新运行上述"sudo mkisofs"命令来创建一个新的映像(新内核将自动包含我们所做的改动,因为我们已经把变化加入到了系统的配置文件中)。将新映像写到磁盘上之后,你就可以用它来启动新内核了。(我不推荐只使用一张CDRW光盘、每次都覆盖写入,因为如果这样无效的话你就会遇到麻烦。我建议使用两张CDRW光盘,更新一张。一旦这张更新光盘已经被检测并可正常使用,那么你就应该更新第二张光盘了。)

参考

创建一张可启动的GRUB CD - 这是我写这个指南时使用的GNU GRUB的官方文件。

评论

上述指南假设只在一个分区上安装Ubuntu系统。我曾用另一个分区作为/boot,结果遇到了麻烦。为避免这一点,在从/ 一般挂载的Ubuntu系统中创建CD。

  • Thanks for the info, I added a line to bind /dev to the chroot and a mount -a command, which should take care of that. A /boot partition becomes basically redundant if you use this LiveCD method, so I don't think it would be a common situation. Personally I have only made /boot seperate when using LVM, but with a few extra modules this CD could boot directly to LVM, I may add that later (the CD image is tiny, so more features wouldn't hurt).