特殊:Badtitle/NS100:BootFromUSB/zh
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/BootFromUSB }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/af | • {{#if: UbuntuHelp:BootFromUSB|Afrikaans| [[::BootFromUSB/zh/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/ar | • {{#if: UbuntuHelp:BootFromUSB|العربية| [[::BootFromUSB/zh/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/az | • {{#if: UbuntuHelp:BootFromUSB|azərbaycanca| [[::BootFromUSB/zh/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/bcc | • {{#if: UbuntuHelp:BootFromUSB|جهلسری بلوچی| [[::BootFromUSB/zh/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/bg | • {{#if: UbuntuHelp:BootFromUSB|български| [[::BootFromUSB/zh/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/br | • {{#if: UbuntuHelp:BootFromUSB|brezhoneg| [[::BootFromUSB/zh/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/ca | • {{#if: UbuntuHelp:BootFromUSB|català| [[::BootFromUSB/zh/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/cs | • {{#if: UbuntuHelp:BootFromUSB|čeština| [[::BootFromUSB/zh/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/de | • {{#if: UbuntuHelp:BootFromUSB|Deutsch| [[::BootFromUSB/zh/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/el | • {{#if: UbuntuHelp:BootFromUSB|Ελληνικά| [[::BootFromUSB/zh/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/es | • {{#if: UbuntuHelp:BootFromUSB|español| [[::BootFromUSB/zh/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/fa | • {{#if: UbuntuHelp:BootFromUSB|فارسی| [[::BootFromUSB/zh/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/fi | • {{#if: UbuntuHelp:BootFromUSB|suomi| [[::BootFromUSB/zh/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/fr | • {{#if: UbuntuHelp:BootFromUSB|français| [[::BootFromUSB/zh/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/gu | • {{#if: UbuntuHelp:BootFromUSB|ગુજરાતી| [[::BootFromUSB/zh/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/he | • {{#if: UbuntuHelp:BootFromUSB|עברית| [[::BootFromUSB/zh/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/hu | • {{#if: UbuntuHelp:BootFromUSB|magyar| [[::BootFromUSB/zh/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/id | • {{#if: UbuntuHelp:BootFromUSB|Bahasa Indonesia| [[::BootFromUSB/zh/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/it | • {{#if: UbuntuHelp:BootFromUSB|italiano| [[::BootFromUSB/zh/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/ja | • {{#if: UbuntuHelp:BootFromUSB|日本語| [[::BootFromUSB/zh/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/ko | • {{#if: UbuntuHelp:BootFromUSB|한국어| [[::BootFromUSB/zh/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/ksh | • {{#if: UbuntuHelp:BootFromUSB|Ripoarisch| [[::BootFromUSB/zh/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/mr | • {{#if: UbuntuHelp:BootFromUSB|मराठी| [[::BootFromUSB/zh/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/ms | • {{#if: UbuntuHelp:BootFromUSB|Bahasa Melayu| [[::BootFromUSB/zh/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/nl | • {{#if: UbuntuHelp:BootFromUSB|Nederlands| [[::BootFromUSB/zh/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/no | • {{#if: UbuntuHelp:BootFromUSB|norsk| [[::BootFromUSB/zh/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/oc | • {{#if: UbuntuHelp:BootFromUSB|occitan| [[::BootFromUSB/zh/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/pl | • {{#if: UbuntuHelp:BootFromUSB|polski| [[::BootFromUSB/zh/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/pt | • {{#if: UbuntuHelp:BootFromUSB|português| [[::BootFromUSB/zh/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/ro | • {{#if: UbuntuHelp:BootFromUSB|română| [[::BootFromUSB/zh/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/ru | • {{#if: UbuntuHelp:BootFromUSB|русский| [[::BootFromUSB/zh/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/si | • {{#if: UbuntuHelp:BootFromUSB|සිංහල| [[::BootFromUSB/zh/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/sq | • {{#if: UbuntuHelp:BootFromUSB|shqip| [[::BootFromUSB/zh/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/sr | • {{#if: UbuntuHelp:BootFromUSB|српски / srpski| [[::BootFromUSB/zh/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/sv | • {{#if: UbuntuHelp:BootFromUSB|svenska| [[::BootFromUSB/zh/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/th | • {{#if: UbuntuHelp:BootFromUSB|ไทย| [[::BootFromUSB/zh/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/tr | • {{#if: UbuntuHelp:BootFromUSB|Türkçe| [[::BootFromUSB/zh/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/vi | • {{#if: UbuntuHelp:BootFromUSB|Tiếng Việt| [[::BootFromUSB/zh/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/yue | • {{#if: UbuntuHelp:BootFromUSB|粵語| [[::BootFromUSB/zh/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/zh | • {{#if: UbuntuHelp:BootFromUSB|中文| [[::BootFromUSB/zh/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/zh-hans | • {{#if: UbuntuHelp:BootFromUSB|中文(简体)| [[::BootFromUSB/zh/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB/zh}}/zh-hant | • {{#if: UbuntuHelp:BootFromUSB|中文(繁體)| [[::BootFromUSB/zh/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:BootFromUSB|:BootFromUSB/zh|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :BootFromUSB/zh/zh | | {{#ifexist: BootFromUSB/zh/zh | | {{#ifeq: {{#titleparts:BootFromUSB/zh|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:BootFromUSB/zh|1|-1|}} | zh | | }}
本文解释如何从一个不支持USB启动的计算机上启动已安装在USB设备上的Ubuntu系统.
介绍
如果你把Ubuntu安装在USB设备上,如记忆棒,移动硬盘,通常是不可能在老机器上启动这个系统的.本指南是解释如何制作一个可以加载USB系统的启动CD.
现在的有些电脑没有从USB启动的BIOS选项(或菜单项),但它们往往都可以检测到USB设备,这种情况下可以用grub 来启动设备.
How It Works
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.
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.
Booting via grub
This is the easiest way, and has been proven to work on several laptops from 2002-2005.
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 root
command to choose a drive/partition and the find
command to see if you found the right one. You can go through your devices like in this example:
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
(If you have 2 internal drives, the USB drive probably is hd2,0
and so on.)
Or, if you know that there is a file called e.g. "MYDRIVE" on the drive, just run
grub> find /MYDRIVE
and grub will look through all drives and partitions that it can access. It will list the correct device to use for the root
command.
Boot the drive by entering:
chainloader +1 boot
For convenience, add these commands to your grub configuration (usually in /boot/grub/menu.lst
):
title Boot USB drive root (hd1,0) chainloader +1 boot
Of course, if you don't have grub installed on your hard drive, change the menu.lst on your grub floppy or CD.
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.
Using a Linux Kernel
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.
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.
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:
gksudo gedit /wherever_you_have_mounted_your_system/etc/mkinitramfs/modules
Which will open the text editor with that file. You need to add these lines to the end of the file:
usbcore sd_mod ehci_hcd uhci_hcd ohci_hcd usb-storage scsi_mod
(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:
gksudo gedit /wherever_you_have_mounted_your_system/etc/mkinitramfs/initramfs.conf
Now to this you should add at the very top the lines:
WAIT=15
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:
sudo mount --bind /dev /wherever_you_have_mounted_your_system/dev sudo chroot /wherever_you_have_mounted_your_system mount -a
Now that you are in your system you can rebuild your initrd by reconfiguring Linux with the command
dpkg-reconfigure linux-image-<kernelversion>
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):
apt-cache search linux-image-2.6
Or
ls /lib/modules
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:
cp /wherever_your_system_is_mounted/boot/initrd.img-<kernelversion> ~ cp /wherever_your_system_is_mounted/boot/vmlinuz-<kernelversion> ~ cp /wherever_your_system_is_mounted/boot/grub/menu.lst ~
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 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.
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):
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
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):
sudo mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o UbuntuBootCDForUSB.iso bootcd
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:
sudo cp UbuntuBootCDForUSB.iso /wherever_you_have_mounted_your_system sudo cp -r bootcd /wherever_you_have_mounted_your_system
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.
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.
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)
See Also
Building a bootable GRUB CD - This is GNU GRUB's official documentation which I used when writing this guide
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 / .
- 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).