特殊:Badtitle/NS100:BootFromUSB:修订间差异
小无编辑摘要 |
小无编辑摘要 |
||
第55行: | 第55行: | ||
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. | 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 == | == Booting the kernel from a 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> | <pre><nowiki> | ||
mkdir -p iso/boot/grub | |||
</nowiki></pre> | </nowiki></pre> | ||
Copy initrd and vmlinuz to the boot folder: | |||
<pre><nowiki> | <pre><nowiki> | ||
cp /cdrom/casper/initrd.gz iso/boot/ | |||
cp /cdrom/casper/vmlinuz iso/boot/ | |||
</nowiki></pre> | </nowiki></pre> | ||
We need to include some more modules to initrd, so we do: | |||
<pre><nowiki> | |||
gksudo gedit /etc/initramfs-tools/modules | |||
</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 | ||
第76行: | 第80行: | ||
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 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 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: | ||
<pre><nowiki> | <pre><nowiki> | ||
gksudo gedit | gksudo gedit /etc/initramfs-tools/initramfs.conf | ||
</nowiki></pre> | </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: | ||
第93行: | 第92行: | ||
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 | sudo mkinitramfs -o iso/boot/initrd.gz <kernelversion> | ||
</nowiki></pre> | </nowiki></pre> | ||
Now that you | 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): | |||
<pre><nowiki> | <pre><nowiki> | ||
cp /usr/lib/grub/i386-pc/stage2_eltorito iso/boot/grub/ | |||
</nowiki></pre> | </nowiki></pre> | ||
Next we need to create Grub's menu: | |||
<pre><nowiki> | <pre><nowiki> | ||
gedit iso/boot/grub/menu.lst | |||
</nowiki></pre> | </nowiki></pre> | ||
and add: | |||
<pre><nowiki> | <pre><nowiki> | ||
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 | |||
root | |||
kernel | |||
boot | |||
initrd | |||
boot | boot | ||
</nowiki></pre> | </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> | ||
sudo mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o UbuntuBootCDForUSB.iso | sudo mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o UbuntuBootCDForUSB.iso iso/ | ||
</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), [[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 | 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: | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo cp UbuntuBootCDForUSB.iso / | sudo cp UbuntuBootCDForUSB.iso /somewhereelse | ||
sudo cp -r | sudo cp -r iso /somewhereelse | ||
</nowiki></pre> | </nowiki></pre> | ||
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. | |||
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 === | === 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.) | 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.) | ||
第167行: | 第152行: | ||
* [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 | * https://wiki.ubuntu.com/Booting | ||
* [http://ubuntuforums.org/showthread.php?t=992426 Ubuntuforums HOWTO: Boot from USB Flash Drive using Grub] - the method exposed in this post should be included here as it can be an alternative to the cd rom method (uses an existing grub partition) | |||
== 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 / . |
2009年5月12日 (二) 16:03的版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/BootFromUSB }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/af | • {{#if: UbuntuHelp:BootFromUSB|Afrikaans| [[::BootFromUSB/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/ar | • {{#if: UbuntuHelp:BootFromUSB|العربية| [[::BootFromUSB/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/az | • {{#if: UbuntuHelp:BootFromUSB|azərbaycanca| [[::BootFromUSB/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/bcc | • {{#if: UbuntuHelp:BootFromUSB|جهلسری بلوچی| [[::BootFromUSB/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/bg | • {{#if: UbuntuHelp:BootFromUSB|български| [[::BootFromUSB/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/br | • {{#if: UbuntuHelp:BootFromUSB|brezhoneg| [[::BootFromUSB/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/ca | • {{#if: UbuntuHelp:BootFromUSB|català| [[::BootFromUSB/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/cs | • {{#if: UbuntuHelp:BootFromUSB|čeština| [[::BootFromUSB/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/de | • {{#if: UbuntuHelp:BootFromUSB|Deutsch| [[::BootFromUSB/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/el | • {{#if: UbuntuHelp:BootFromUSB|Ελληνικά| [[::BootFromUSB/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/es | • {{#if: UbuntuHelp:BootFromUSB|español| [[::BootFromUSB/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/fa | • {{#if: UbuntuHelp:BootFromUSB|فارسی| [[::BootFromUSB/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/fi | • {{#if: UbuntuHelp:BootFromUSB|suomi| [[::BootFromUSB/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/fr | • {{#if: UbuntuHelp:BootFromUSB|français| [[::BootFromUSB/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/gu | • {{#if: UbuntuHelp:BootFromUSB|ગુજરાતી| [[::BootFromUSB/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/he | • {{#if: UbuntuHelp:BootFromUSB|עברית| [[::BootFromUSB/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/hu | • {{#if: UbuntuHelp:BootFromUSB|magyar| [[::BootFromUSB/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/id | • {{#if: UbuntuHelp:BootFromUSB|Bahasa Indonesia| [[::BootFromUSB/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/it | • {{#if: UbuntuHelp:BootFromUSB|italiano| [[::BootFromUSB/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/ja | • {{#if: UbuntuHelp:BootFromUSB|日本語| [[::BootFromUSB/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/ko | • {{#if: UbuntuHelp:BootFromUSB|한국어| [[::BootFromUSB/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/ksh | • {{#if: UbuntuHelp:BootFromUSB|Ripoarisch| [[::BootFromUSB/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/mr | • {{#if: UbuntuHelp:BootFromUSB|मराठी| [[::BootFromUSB/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/ms | • {{#if: UbuntuHelp:BootFromUSB|Bahasa Melayu| [[::BootFromUSB/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/nl | • {{#if: UbuntuHelp:BootFromUSB|Nederlands| [[::BootFromUSB/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/no | • {{#if: UbuntuHelp:BootFromUSB|norsk| [[::BootFromUSB/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/oc | • {{#if: UbuntuHelp:BootFromUSB|occitan| [[::BootFromUSB/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/pl | • {{#if: UbuntuHelp:BootFromUSB|polski| [[::BootFromUSB/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/pt | • {{#if: UbuntuHelp:BootFromUSB|português| [[::BootFromUSB/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/ro | • {{#if: UbuntuHelp:BootFromUSB|română| [[::BootFromUSB/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/ru | • {{#if: UbuntuHelp:BootFromUSB|русский| [[::BootFromUSB/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/si | • {{#if: UbuntuHelp:BootFromUSB|සිංහල| [[::BootFromUSB/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/sq | • {{#if: UbuntuHelp:BootFromUSB|shqip| [[::BootFromUSB/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/sr | • {{#if: UbuntuHelp:BootFromUSB|српски / srpski| [[::BootFromUSB/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/sv | • {{#if: UbuntuHelp:BootFromUSB|svenska| [[::BootFromUSB/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/th | • {{#if: UbuntuHelp:BootFromUSB|ไทย| [[::BootFromUSB/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/tr | • {{#if: UbuntuHelp:BootFromUSB|Türkçe| [[::BootFromUSB/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/vi | • {{#if: UbuntuHelp:BootFromUSB|Tiếng Việt| [[::BootFromUSB/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/yue | • {{#if: UbuntuHelp:BootFromUSB|粵語| [[::BootFromUSB/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/zh | • {{#if: UbuntuHelp:BootFromUSB|中文| [[::BootFromUSB/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/zh-hans | • {{#if: UbuntuHelp:BootFromUSB|中文(简体)| [[::BootFromUSB/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BootFromUSB | UbuntuHelp:BootFromUSB | {{#if: | :}}BootFromUSB}}/zh-hant | • {{#if: UbuntuHelp:BootFromUSB|中文(繁體)| [[::BootFromUSB/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:BootFromUSB|:BootFromUSB|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :BootFromUSB/zh | | {{#ifexist: BootFromUSB/zh | | {{#ifeq: {{#titleparts:BootFromUSB|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:BootFromUSB|1|-1|}} | zh | | }}
<<Include(Tag/NeedsExpansion)>>
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
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
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. 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. Boot from the Ubuntu Desktop (live) CD. Mount the hard drive partition by using the terminal: (replace sda2 with the partition name of your boot partition)
sudo mkdir /vols sudo mount /dev/sda2 /vols
and copy kernel and initrd to your hard drive partition:
cp /boot/vmlinuz-(your kernel version) /vols cp /boot/initrd.img-(your kernel version) /vols
If you don't have grub installed on the hard drive, you'll need to run grub from a bootable CD like in the previous section. If you have grub on a CD-RW disk, add this to your menu.lst (replace the hd number with the one for your hard drive partition):
title Ubuntu root (hd0,1) kernel /vmlinuz-(your number) root=/dev/sdb1 ro quiet splash initrd /initrd.img-(your version)
Or if you are using CD-R disks, please go to command line (c) when grub appears and type the same thing. Note: Replace sdb1 with the device name of the Ubuntu partition on the external drive, or even better use the UUID as can be seen in /boot/grub/menu.lst on your Ubuntu partition.
See Also
- Building a bootable GRUB CD - This is GNU GRUB's official documentation which I used when writing this guide
- https://wiki.ubuntu.com/Booting
- Ubuntuforums HOWTO: Boot from USB Flash Drive using Grub - the method exposed in this post should be included here as it can be an alternative to the cd rom method (uses an existing grub partition)
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
- An installation guide for KBoot in Italian: 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.