个人工具

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

来自Ubuntu中文

跳转至: 导航, 搜索
(New page: {{From|https://help.ubuntu.com/community/BootFromUSB}} {{Languages|php5}} This page explains how to boot an Ubuntu system which is installed on a USB device when the computer does not supp...)
 
 
(未显示2个用户的17个中间版本)
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/BootFromUSB}}
 
{{From|https://help.ubuntu.com/community/BootFromUSB}}
{{Languages|php5}}
+
{{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
+
<<Include(Tag/ContentCleanup)>>
 
+
<<Include(Tag/StyleCleanup)>>
 
== Introduction ==
 
== Introduction ==
 +
It is impossible to boot an Ubuntu system which is installed on a USB memory stick or external hard drive on many older computers. There are two common problems:
 +
<ol><li>They may lack a BIOS setting to allow booting from USB
 +
</li><li>They may not recognize USB drives initially, and may require operating system drivers to accomplish this</li></ol>
  
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.
+
This page explains how to get around these limitations by using ''Grub'' for problem #1 and, a boot medium, rather than the BIOS, for problem #2.
 
+
The boot medium can be either a specially made boot CD, or a small special boot partition on an internal hard drive.
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.
+
This guide explains how to use ''Grub'' and how to create a boot CD (or a boot partition on a hard drive) which will load USB drivers to continue booting the USB system.
 
+
== The BIOS and your USB Linux system ==
== How It Works ==
+
PCs use a system called the BIOS (Basic Input/Output System) to start the machine. A modern BIOS (written after 2002) usually contains USB drivers, and a boot from USB option, but older computers often don't have these features.  
 
+
An alternative strategy for older machines is to let the BIOS start a minimal Linux system on a BIOS supported drive such as a floppy disk, CD, or HD, and then transfer control to the USB drive to continue booting the full operating system.
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 minimal Linux system contains the necessary USB drivers to continue the boot process.  
 
+
Note: If the computer was made between 2002 and 2005, it may contain USB drivers, but not an option to boot from USB. In this case the ''Grub'' bootloader can do the job directly, without the need of an initial Linux system.
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 ==
 
== Booting via grub ==
 
 
This is the easiest way, and has been proven to work on several laptops from 2002-2005.
 
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 <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>
 
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>
第30行: 第28行:
 
grub> find /[tab]
 
grub> find /[tab]
 
  Possible files are: ldlinux.sys mydoc myfile mystick syslinux.cfg  # Bingo, that's the USB stick
 
  Possible files are: ldlinux.sys mydoc myfile mystick syslinux.cfg  # Bingo, that's the USB stick
</nowiki></code>
+
</nowiki></pre>
 
(If you have 2 internal drives, the USB drive probably is <code><nowiki>hd2,0</nowiki></code> and so on.)
 
(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
 
Or, if you know that there is a file called e.g. "MYDRIVE" on the drive, just run
 
<pre><nowiki>
 
<pre><nowiki>
 
grub> find /MYDRIVE
 
grub> find /MYDRIVE
</nowiki></code>
+
</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.
 
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:
 
Boot the drive by entering:
 
<pre><nowiki>
 
<pre><nowiki>
 
chainloader +1
 
chainloader +1
 
boot
 
boot
</nowiki></code>
+
</nowiki></pre>
 
For convenience, add these commands to your grub configuration (usually in <code><nowiki>/boot/grub/menu.lst</nowiki></code>):
 
For convenience, add these commands to your grub configuration (usually in <code><nowiki>/boot/grub/menu.lst</nowiki></code>):
 
<pre><nowiki>
 
<pre><nowiki>
# to boot from a usb device
+
# to boot from a USB device
 
title    Boot USB drive
 
title    Boot USB drive
 
root    (hd1,0)
 
root    (hd1,0)
 
chainloader +1
 
chainloader +1
 
boot
 
boot
</nowiki></code>
+
</nowiki></pre>
 
Of course, if you don't have grub installed on your hard drive, change the menu.lst on your grub floppy or CD.
 
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.
 
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.
 
+
== The Minimal Linux Method ==
== Using a Linux Kernel ==
+
The most minimal system would be the Linux kernel itself. Though a stripped-down Linux kernel is actually small enough to fit onto a high density (1.44MB) floppy disk, the standard Ubuntu kernel is a little larger than this. Therefore a CD or HD boot is easier to create. Besides, the standard Ubuntu kernel does not have all of the drivers needed to boot a USB drive.
 
+
To solve this problem, extra driver modules must be put into an "initial RAM disk" image (called ''initrd''). ''initrd'' gets copied into the RAM during boot to enable the kernel to access the extra modules it contains.
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.
+
Most PCs can boot from a CDROM drive, and writable CDs can easily store enough data to allow  a Linux kernel and an ''initrd'' to fit comfortably. In fact these two components are used to make "live CDs" bootable, as well. So we will use this method to boot from USB.  
 
+
Note: Since the kernel and ''initrd'' are copied into RAM during the boot and run from there, it is not necessary for the CD to be in the drive after booting has finished. Thus, if you only have one CDROM drive, it will not be tied up like it would be with a live CD.
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.
+
So we now know how Ubuntu can be booted from CD into a USB drive in theory, it is time to put it into practice.
 
+
== Booting the kernel from a bootable 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:
+
=== Prepare your bootable CD ===
 +
To build your own boot CD, you can either use an Ubuntu system or the Live CD. Since an Ubuntu system could not be available, we will show how to build it from the Live CD.
 +
Boot your Live CD (this procedure was tested with Ubuntu 9.04 Jaunty beta) and wait for the whole system to load.
 +
Open a terminal and create the cd folder structure:
 +
<pre><nowiki>
 +
mkdir -p iso/boot/grub
 +
</nowiki></pre>
 +
Copy initrd and vmlinuz to the boot folder:
 +
<pre><nowiki>
 +
cp /cdrom/casper/initrd.gz iso/boot/
 +
cp /cdrom/casper/vmlinuz iso/boot/
 +
</nowiki></pre>
 +
We need to include some more modules to initrd, so we do:
 
<pre><nowiki>
 
<pre><nowiki>
gksudo gedit /wherever_you_have_mounted_your_system/etc/mkinitramfs/modules
+
gksudo gedit /etc/initramfs-tools/modules
</nowiki></code>
+
</nowiki></pre>
Which will open the text editor with that file. You need to add these lines to the end of the file:
+
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
第73行: 第80行:
 
uhci_hcd
 
uhci_hcd
 
ohci_hcd
 
ohci_hcd
usb-storage
+
usb_storage
 
scsi_mod
 
scsi_mod
</nowiki></code>
+
</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.
+
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 engaged properly by Linux, and your boot would fail before the 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:
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:
+
 
<pre><nowiki>
 
<pre><nowiki>
gksudo gedit /wherever_you_have_mounted_your_system/etc/mkinitramfs/initramfs.conf
+
gksudo gedit /etc/initramfs-tools/initramfs.conf
</nowiki></code>
+
</nowiki></pre>
 
Now to this you should add at the very top the lines:
 
Now to this you should add at the very top the lines:
 
<pre><nowiki>
 
<pre><nowiki>
 
WAIT=15
 
WAIT=15
</nowiki></code>
+
</nowiki></pre>
 
Then save the file and exit the text editor.
 
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:
 
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:
 
<pre><nowiki>
 
<pre><nowiki>
sudo mount --bind /dev /wherever_you_have_mounted_your_system/dev
+
sudo mkinitramfs -o iso/boot/initrd.gz <kernelversion>
sudo chroot /wherever_you_have_mounted_your_system
+
</nowiki></pre>
mount -a
+
Where <kernelversion> is the version of Linux you have installed that you wish to reconfigure. The default for Ubuntu 9.04 is 2.6.28-11-generic.
</nowiki></code>
+
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 copy the "stage2_eltorito" file to the top folder of the live CD (the location varies slightly between 32bit and 64bit PCs):
Now that you are in your system you can rebuild your initrd by reconfiguring Linux with the command
+
 
<pre><nowiki>
 
<pre><nowiki>
dpkg-reconfigure linux-image-<kernelversion>
+
cp /usr/lib/grub/i386-pc/stage2_eltorito iso/boot/grub/
</nowiki></code>
+
</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):
+
Next we need to create Grub's menu:
 
<pre><nowiki>
 
<pre><nowiki>
apt-cache search linux-image-2.6
+
gedit iso/boot/grub/menu.lst
</nowiki></code>
+
</nowiki></pre>
Or
+
and add:
 
<pre><nowiki>
 
<pre><nowiki>
ls /lib/modules
+
title Run Ubuntu 9.04 beta from USB DISK
</nowiki></code>
+
root (cd)
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:
+
kernel /boot/vmlinuz file=/cdrom/preseed/ubuntu.seed boot=casper noprompt cdrom-detect/try-usb=true persistent
 +
initrd /boot/initrd.gz
 +
boot
 +
</nowiki></pre>
 +
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):
 
<pre><nowiki>
 
<pre><nowiki>
cp /wherever_your_system_is_mounted/boot/initrd.img-<kernelversion> ~
+
sudo mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o UbuntuBootCDForUSB.iso iso/
cp /wherever_your_system_is_mounted/boot/vmlinuz-<kernelversion> ~
+
</nowiki></pre>
cp /wherever_your_system_is_mounted/boot/grub/menu.lst ~
+
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), [[UbuntuHelp:GnomeBaker|GnomeBaker]], k3b, Nero and many more. If you don't have your CD-RW drive accessible (because you are running the live CD from it) then you can copy the CD image somewhere to keep it safely stored on a real drive. You should also copy over the "iso" folder. This can be done with:
</nowiki></code>
+
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.
+
 
+
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
+
sudo cp UbuntuBootCDForUSB.iso /somewhereelse
root          (cd)
+
sudo cp -r iso /somewhereelse
kernel        /boot/vmlinuz root=/dev/sda1 ro quiet splash
+
</nowiki></pre>
initrd        /boot/initrd.img
+
=== Boot the system with your own bootable CD ===
boot
+
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.
 
+
=== Disadvantages of this system ===
title          Ubuntu Recovery Mode
+
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 every time, as you will be in trouble if it doesn't work. Instead I suggest using 2 CDRW discs and updating one at a time.)
root          (cd)
+
== Booting the kernel from an internal hard drive ==
kernel        /boot/vmlinuz root=/dev/sda1 ro single
+
This section is only for those who have an internal drive that can be written to and has grub installed. It makes sense if you prefer to install Ubuntu to an external hard drive instead of the internal one, but still have the possibility to customize the internal hard drive a little in order to boot the Ubuntu installation on your external drive.
initrd        /boot/initrd.img
+
Basically, you just copy the initrd file and vmlinuz from your Ubuntu installation onto the internal disk. If you have the possibility to repartition the disk, you can make a new ext3 partition (anything more than 20MB should be enough) and use it as a "boot" partition.
boot
+
''Note:'' You don't have to make an ext3 partition, but you need to use a partition type that grub can read, which is pretty much everything except NTFS. I.e. if your disk has a FAT32 partition already, you can copy vmlinuz and initrd there instead of making a new partition.
</nowiki></code>
+
In the case you only have an NTFS partition, there's still one solution: Install "GRUB for DOS" (grubldr.exe) on the NTFS partition. See https://gna.org/projects/grub4dos/ for more information. Note that the [http://wubi-installer.org/ WUBI installer] uses this method to boot a Ubuntu system completely contained on a Windows partition.
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):
+
=== Prepare your hard disk and grub for usb booting ===
 +
Either boot from the Ubuntu Desktop Live CD or mount it in the filesystem.
 +
Suppose that Ubuntu is running and the live cd is mounted in /media/cdrom (as simple as "sudo mount karmic-desktop-i386.iso /media/cdrom"), let's make a new dir and store vmlinuz and initrd in it:
 
<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 mkdir /boot/usb-boot
</nowiki></code>
+
sudo cp /media/cdrom/casper/vmlinuz /boot/usb-boot
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 /media/cdrom/casper/initrd.lz /boot/usb-boot
 +
</nowiki></pre>
 +
Edit your grub's menu (with "gksudo gedit /boot/grub/menu.lst") and add at the end:
 
<pre><nowiki>
 
<pre><nowiki>
sudo cp UbuntuBootCDForUSB.iso /wherever_you_have_mounted_your_system
+
title USB FLASH DRIVE
sudo cp -r bootcd /wherever_you_have_mounted_your_system
+
root (hd0,6)
</nowiki></code>
+
kernel /boot/usb-boot/vmlinuz file=/cdrom/preseed/ubuntu.seed boot=casper noprompt cdrom-detect/try-usb=true persistent
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.
+
initrd /boot/usb-boot/initrd.lz
 
+
boot
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.
+
</nowiki></pre>
 
+
Now you can reboot your system with your Ubuntu Bootable usb device plugged in and choose 'USB FLASH DRIVE' (tested with Karmic Koala Alpha 3)
=== 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 ==
 
== 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 Building a bootable GRUB CD] - This is GNU GRUB's official documentation which I used when writing this guide
 
+
* https://wiki.ubuntu.com/Booting
=== Comments ===
+
== 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 / .
 
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 [[UbuntuHelp:LiveCD|LiveCD]] method, so I don't think it would be a common situation. Personally I have only made /boot separate 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).
+
==== KBoot ====
 +
For systems that won't boot from a USB device and/or don't even provide HDD/FDD emulation for USB devices in the BIOS, [http://kboot.sourceforge.net/ KBoot] might be an option - it uses the Linux kernel itself as a boot loader. For example, you could burn a KBoot CD that could boot a kernel stored on a USB mass storage device. Maybe it could even be integrated in the live or alternate CDs? -- SteveDodd
 +
* An installation guide for KBoot in Italian: [http://www.webalice.it/lorenzo.chiodi/usbdisk/index.html Come installare Ubuntu su un hard disk esterno USB]
 +
==== Using UUID ====
 +
In the section 'Booting the kernel from a bootable CD', I would suggest creating menu.lst with references to the UUID of the partition, not the device name. This tutorial has in mind a USB hard disk that boots always from the same computer, but you can also carry the disk with you, and use it to boot any computer. But then at every computer, your USB disk will be assigned a different device name.
 +
Just in case you are curious, the other modification you need in order to switch computers while using the same external disk is to delete /etc/X11/xorg.conf, so that it is created on the fly every time. X server configuration so much varies from one PC to another that you cannot use a single file for all computers. The rest goes about the same, and the CD created using this tutorial (with the UUID modification) works great.
 +
Indeed, if you are using Intrepid, you don't need to delete /etc/X11/xorg.conf any more, and the experience has become very smooth. We have tested on many old and new computers, and it will make the most of any system (compiz will appear automatically if the free driver supports 3D: eg, ati). A portable laptop drive is light and not very expensive, and makes a good middle point between a persistent usb drive and an actual laptop.
 +
Just a small example for using the UUID of the partition on the usb hard drive to locate root.
 +
<pre><nowiki>
 +
title Run Ubuntu 9.04 beta from USB DISK
 +
root (cd)
 +
kernel /boot/vmlinuz root=UUID=<uuid of the partition you installed ubuntu on> rw splash quiet
 +
initrd /boot/initrd.gz
 +
boot
 +
</nowiki></pre>
 +
----
 +
[[category:CategoryBootAndPartition]] [[category:CategoryUsb]]
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2010年5月19日 (三) 21:46的最新版本


<<Include(Tag/ContentCleanup)>> <<Include(Tag/StyleCleanup)>>

Introduction

It is impossible to boot an Ubuntu system which is installed on a USB memory stick or external hard drive on many older computers. There are two common problems:

  1. They may lack a BIOS setting to allow booting from USB
  2. They may not recognize USB drives initially, and may require operating system drivers to accomplish this

This page explains how to get around these limitations by using Grub for problem #1 and, a boot medium, rather than the BIOS, for problem #2. The boot medium can be either a specially made boot CD, or a small special boot partition on an internal hard drive. This guide explains how to use Grub and how to create a boot CD (or a boot partition on a hard drive) which will load USB drivers to continue booting the USB system.

The BIOS and your USB Linux system

PCs use a system called the BIOS (Basic Input/Output System) to start the machine. A modern BIOS (written after 2002) usually contains USB drivers, and a boot from USB option, but older computers often don't have these features. An alternative strategy for older machines is to let the BIOS start a minimal Linux system on a BIOS supported drive such as a floppy disk, CD, or HD, and then transfer control to the USB drive to continue booting the full operating system. A minimal Linux system contains the necessary USB drivers to continue the boot process. Note: If the computer was made between 2002 and 2005, it may contain USB drivers, but not an option to boot from USB. In this case the Grub bootloader can do the job directly, without the need of an initial Linux system.

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):

# to boot from a USB device
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.

The Minimal Linux Method

The most minimal system would be the Linux kernel itself. Though a stripped-down Linux kernel is actually small enough to fit onto a high density (1.44MB) floppy disk, the standard Ubuntu kernel is a little larger than this. Therefore a CD or HD boot is easier to create. Besides, the standard Ubuntu kernel does not have all of the drivers needed to boot a USB drive. To solve this problem, extra driver modules must be put into an "initial RAM disk" image (called initrd). initrd 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 easily store enough data to allow a Linux kernel and an initrd to fit comfortably. In fact these two components are used to make "live CDs" bootable, as well. So we will use this method to boot from USB. Note: Since the kernel and initrd are copied into RAM during the boot and run from there, it is not necessary for the CD to be in the drive after booting has finished. Thus, if you only have one CDROM drive, it will not be tied up like it would be with a live CD. So we now know how Ubuntu can be booted from CD into a USB drive in theory, it is time to put it into practice.

Booting the kernel from a bootable CD

Prepare your bootable CD

To build your own boot CD, you can either use an Ubuntu system or the Live CD. Since an Ubuntu system could not be available, we will show how to build it from the Live CD. Boot your Live CD (this procedure was tested with Ubuntu 9.04 Jaunty beta) and wait for the whole system to load. Open a terminal and create the cd folder structure:

mkdir -p iso/boot/grub

Copy initrd and vmlinuz to the boot folder:

cp /cdrom/casper/initrd.gz iso/boot/
cp /cdrom/casper/vmlinuz iso/boot/

We need to include some more modules to initrd, so we do:

gksudo gedit /etc/initramfs-tools/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 engaged properly by Linux, and your boot would fail before the 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 /etc/initramfs-tools/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 mkinitramfs -o iso/boot/initrd.gz <kernelversion>

Where <kernelversion> is the version of Linux you have installed that you wish to reconfigure. The default for Ubuntu 9.04 is 2.6.28-11-generic. 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 copy the "stage2_eltorito" file to the top folder of the live CD (the location varies slightly between 32bit and 64bit PCs):

cp /usr/lib/grub/i386-pc/stage2_eltorito iso/boot/grub/

Next we need to create Grub's menu:

gedit iso/boot/grub/menu.lst

and add:

title Run Ubuntu 9.04 beta from USB DISK
root (cd)
kernel /boot/vmlinuz file=/cdrom/preseed/ubuntu.seed boot=casper noprompt cdrom-detect/try-usb=true persistent
initrd /boot/initrd.gz
boot

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 iso/

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 CD-RW drive accessible (because you are running the live CD from it) then you can copy the CD image somewhere to keep it safely stored on a real drive. You should also copy over the "iso" folder. This can be done with:

sudo cp UbuntuBootCDForUSB.iso /somewhereelse
sudo cp -r iso /somewhereelse

Boot the system with your own bootable CD

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.

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 every time, as you will be in trouble if it doesn't work. Instead I suggest using 2 CDRW discs and updating one at a time.)

Booting the kernel from an internal hard drive

This section is only for those who have an internal drive that can be written to and has grub installed. It makes sense if you prefer to install Ubuntu to an external hard drive instead of the internal one, but still have the possibility to customize the internal hard drive a little in order to boot the Ubuntu installation on your external drive. Basically, you just copy the initrd file and vmlinuz from your Ubuntu installation onto the internal disk. If you have the possibility to repartition the disk, you can make a new ext3 partition (anything more than 20MB should be enough) and use it as a "boot" partition. Note: You don't have to make an ext3 partition, but you need to use a partition type that grub can read, which is pretty much everything except NTFS. I.e. if your disk has a FAT32 partition already, you can copy vmlinuz and initrd there instead of making a new partition. In the case you only have an NTFS partition, there's still one solution: Install "GRUB for DOS" (grubldr.exe) on the NTFS partition. See https://gna.org/projects/grub4dos/ for more information. Note that the WUBI installer uses this method to boot a Ubuntu system completely contained on a Windows partition.

Prepare your hard disk and grub for usb booting

Either boot from the Ubuntu Desktop Live CD or mount it in the filesystem. Suppose that Ubuntu is running and the live cd is mounted in /media/cdrom (as simple as "sudo mount karmic-desktop-i386.iso /media/cdrom"), let's make a new dir and store vmlinuz and initrd in it:

sudo mkdir /boot/usb-boot
sudo cp /media/cdrom/casper/vmlinuz /boot/usb-boot
sudo cp /media/cdrom/casper/initrd.lz /boot/usb-boot

Edit your grub's menu (with "gksudo gedit /boot/grub/menu.lst") and add at the end:

title USB FLASH DRIVE
root (hd0,6)
kernel /boot/usb-boot/vmlinuz file=/cdrom/preseed/ubuntu.seed boot=casper noprompt cdrom-detect/try-usb=true persistent
initrd /boot/usb-boot/initrd.lz
boot 

Now you can reboot your system with your Ubuntu Bootable usb device plugged in and choose 'USB FLASH DRIVE' (tested with Karmic Koala Alpha 3)

See Also

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 separate 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).

KBoot

For systems that won't boot from a USB device and/or don't even provide HDD/FDD emulation for USB devices in the BIOS, KBoot might be an option - it uses the Linux kernel itself as a boot loader. For example, you could burn a KBoot CD that could boot a kernel stored on a USB mass storage device. Maybe it could even be integrated in the live or alternate CDs? -- SteveDodd

Using UUID

In the section 'Booting the kernel from a bootable CD', I would suggest creating menu.lst with references to the UUID of the partition, not the device name. This tutorial has in mind a USB hard disk that boots always from the same computer, but you can also carry the disk with you, and use it to boot any computer. But then at every computer, your USB disk will be assigned a different device name. Just in case you are curious, the other modification you need in order to switch computers while using the same external disk is to delete /etc/X11/xorg.conf, so that it is created on the fly every time. X server configuration so much varies from one PC to another that you cannot use a single file for all computers. The rest goes about the same, and the CD created using this tutorial (with the UUID modification) works great. Indeed, if you are using Intrepid, you don't need to delete /etc/X11/xorg.conf any more, and the experience has become very smooth. We have tested on many old and new computers, and it will make the most of any system (compiz will appear automatically if the free driver supports 3D: eg, ati). A portable laptop drive is light and not very expensive, and makes a good middle point between a persistent usb drive and an actual laptop. Just a small example for using the UUID of the partition on the usb hard drive to locate root.

title Run Ubuntu 9.04 beta from USB DISK
root (cd)
kernel /boot/vmlinuz root=UUID=<uuid of the partition you installed ubuntu on> rw splash quiet
initrd /boot/initrd.gz
boot