Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 07-09-2006, 09:18 PM   #1
Registered: Aug 2005
Posts: 235

Rep: Reputation: 30
How do I install a bootloader to a USB Flash Drive?


I'm looking for a way to install a bootloader, like GRUB or something, to my 2GB USB stick... But at the same time, I still want to use the same USB stick for other things as well... (I've tried to boot DSL off of a USB, and it stole the whole thing from me... >_> and I dont want that to happen with this...)

I recently got a new laptop... with a 120gb HDD (supposedly) but the manufactorer partitioned the disc in 2 54gb halfs (where did the rest go? XD)... and rather than merging the particians... I thought this was a good opertunity to install Linux on the other partician, and dual boot it for my laptop... But, from personal experaince... I've disliked messing up the MBR with a bootloader... and for speed reasons, it would be easier to just pop in a usb drive and have it boot up linux, when I want to go into Linux... and when I want to go Windows, just leave the USB stick out.

If thats understandable... can anyone suggest a way I can do this? also, when I'm ready to install Debian... which i haven't done in a while... i forget if it gives me the option to manually deal with the bootloader, or what i have to do... anyway...

So thanks in advance for any help you can give me! ^_^;

Last edited by pxumsgdxpcvjm; 07-09-2006 at 09:21 PM.
Old 07-09-2006, 09:36 PM   #2
Registered: Sep 2005
Location: Guatemala
Distribution: Debian, FreeBSD, NetBSD
Posts: 35

Rep: Reputation: 15
Two ways to count bytes

The difference between 54 GB times 2 and 120 GB is the way that bytes are counted. One way is to think of 1 MB as 1000 KB but really the accurate way to count is 1 MB equals 1024 KB. Do the math and you will see it.

The other question about usb memory drive is that you don't need a bootloader other than the one that will be installed when you install one of the versions of Linux that can be installed to usb memory. What you do need is a BIOS that will let you boot from usb, if so there will be no problem booting from usb. Just make it the first booting option in the BIOS. The booting order should be 1. usb, 2. cdrom, 3. hdd.

If you decide to install a version of Linux to the second partion on the hard drive the bootloader in that version of Linux will "see" Windows and add it to the booting menu. I am thinking of GRUB which is the one most versions of Linux use. Lilo too will boot Windows but you have to configure it manually, not hard.

The next question is if you have enough RAM to install Linux on one partition without making a swap partition. There is no absolute rule but the more RAM the less swap is needed. If you have 512 MB of RAM you won't need a swap partition.
Old 07-09-2006, 10:05 PM   #3
LQ Newbie
Registered: Oct 2005
Distribution: Linux Mint 6; Ubuntu 8.04
Posts: 8

Rep: Reputation: 0
You don't need to mess up the windows MBR if you specify a /boot partition in addition to /, and /home.

I've set up my Lenovo 3000 N100 by shrinking the windows partition, creating a /boot of a couple 100MB and an extended partition with a FAT32 a partition where I can share data with windows, and then I created a / and home directory in the extended partition as well.

My windows/ubuntu dual boot system is working great!
Old 07-09-2006, 11:17 PM   #4
Registered: Aug 2005
Posts: 235

Original Poster
Rep: Reputation: 30
For me, its not really a question of how well it will work... but more a question of how i can do it the way I want too.

First of all, yes, my computer's Bios does let be boot of USB... but i dont want to install something like DSL to my usb... it just doesn't have the perminant feel that installing it to the HDD would have... lol but hear out my reasoning...

I understand using the bootloader that installs with Linux, will work just fine... but what I want to do, is put the actual bootloader onto a USB drive, which I will then boot from (via bios setting) when I want to go to linux. That bootloader on the USB drive will then point to my Linux partician.
Maybe bootloader isn't the best word... but thats the only term i can think of.

My reasoning behind this is... so when I DONT use the USB stick to boot, Linux will be practically undetectable... at least when someone watches the boot process. Without the USB connected on booting, the computer will just turn on normally and go straight into Windows, without running any bootloader.
I probably could just create a small boot partician or something, but this is not my strong point in knowledge, and I still think I'd have to alter where the computer's boot record points... alsp so if I deleted the Linux partican later, Windows wouldn't load correctly or something @_@ (bad experainces)... and I'd understand it better if I can just use the USB stick.

There is also that novalty cool feel, to pluging in my USB at boot, and having THAT cause Linux to load. Which is another reason I want to try this... if its even possible.

Anyway is this possible, and how do I go about doing it? and if I do this, can i still use the USB for other things?

Last edited by pxumsgdxpcvjm; 07-09-2006 at 11:19 PM.
Old 07-10-2006, 03:13 AM   #5
Registered: Sep 2005
Location: Guatemala
Distribution: Debian, FreeBSD, NetBSD
Posts: 35

Rep: Reputation: 15
It isn't used much anymore but some distros provide for making a boot floppy. I think Kanotix, knoppix, maybe even Mepis not during the install but later from the menu. Maybe you can put the floppy data on usb memory? A couple of years ago with Slackware I made a boot floppy that booted before the regular bootloader.Then the reasoning was that a person would have a backup way to boot into Slackware if the normal bootloader got corrupted.
Old 04-06-2008, 12:32 AM   #6
LQ Newbie
Registered: Sep 2005
Distribution: Kubuntu 8.04 Remix
Posts: 6

Rep: Reputation: 0
USB flash drive bootloader

I have been trying to make a flash drive I could take from computer to computer and run linux with my apps without changing anything on the system but the boot order in the bios, but I have run into a major problem. Many motherboards USB boot differently. For example I got my USB boot flash drive to work on one computer but it won't work on 3 others which support USB booting. The problem lies in how the motherboards handle reporting the USB drive. The GNU GRUB project knows about the problem and it is on their TODO list but I don't have any idea when it is going to get addressed. Here is a link to where they talk about it:

(look under the section: Support for USB devices on i386-pc)
Old 04-06-2008, 10:55 AM   #7
Senior Member
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 112Reputation: 112
Booting from a USB pen drive – a few technical considerations

Many Linux users want to boot from a solid state USB memory device. There seems to be various problems of booting reported. I hope the following points may help to reduce the problems or at least clarify the type of problems.

(1) The motherboard (or mobo) must have the ability to boot from a USB device first.

Most mobo do this now. Very old mobo, say more than 5 or 7 years old may not support booting from a USB device. Some not-so-old mobo may do it if the "USB legacy support" is enabled in the Bios. The booting via the USB port is generic and does not restrict to the flash drive because it applies to any external USB hard disk as well. Once the USB device booting is supported and the Bios has been instructed to boot it first then it is only a matter to install a system or a boot loader in the USB device.

The simplest way to find out if the Bios supports the booting from a USB device is to plug one in and to boot up a Live CD that you can activate a Grub prompt and then issue the geometry statement, which lists out the partition details of the specified disk, repeatedly until all the disk devices have been exhausted
geometry (hd0)
geometry (hd1)
geometry (hd2) 
geometry (hd3) 
Grub counts from zero so (hd0) is the 1st disk, (hd1) is the 2nd disk and so on. Depending on how Grub has been installed not every Live CD can offer a Grub prompt. Here is a list of Live CD with which you can activate a Grub prompt.

(2) Know how the disks are ordered in the Bios

This may be the biggest hurdle for most Linux newbies. Basically when the Bios has been instructed to boot a USB flash drive first then it has to regard it as the 1st disk. The original internal hard disk will be automatically relegated in the Bios to the 2nd disk. If the USB flash drive is removed then the internal hard disk will revert back to the 1st boot disk.

Before the introduction of a bootable USB flash drive the existing operating system in the hard disk would be by default working as the 1st boot disk and most likely has been installed as such. The insertion of the USB flash drive will "rob" its 1st boot disk status. Many OSes, especially MS Windows, cannot cope with such setting change. To overcome this problem a user must do something in the boot loader instructions to "re-map" the disk order temporary when such systems are booted.

The same goes with a Linux.

As an example a MS Windows originally installed in the 1st partition of the 1st hard disk this will be known as (hd0,0) to Grub. Grub can fire up the MS system by the commands
title MS Windows in 1st partition of 1st hard disk or (hd0,0)
root (hd0,0)
chainloader +1
However if a USB is introduced then it becomes the 1st boot disk (hd0) and the same MS Windows is in the 2nd disk (hd1) and it can only be booted by commands
title MS Windows installed in 1st partition of 1st hard disk or (hd0,0) now booted as (hd1,0)
root (hd1,0)
map (hd0) (hd1)
map (hd1) (hd0)
chainloader +1
The two map statements temporarily swap the disk order at the moment Windows is booted but revert to the original order once Windows exits.

The above applies to a Linux which will equally need the (hd0) reference changed to (hd1) in the booting instruction.

(3) There are two types of booting queues in the Bios

The first is the device booting queue with which a user can impose in any booting order for the booting devices of floppy, CD, hard disk and network. The Bios will try each one in turn until it finds one that boots.

The second booting queue is which one of the internal hard disks, external hard eSata disks, external USB hard disks, USB flash/pen drives (treated as a hard disk in most BIOS), Firewire hard disks and SCSI disks will be booted first. This is the booting queue “inside” the hard disk section of the first device booting queue.

There is a small complication here and the best way to explain is a user must think like a Bios and to react as things are presented to you.

The complication is the hard disks are detected in a pre-determined fashion by the mobo. So it assigns the 1st , 2nd , 3rd and so on disk numbers according to hardware ports in a sequence shipped from the factory. As a rule internal disks are detected before external disks.

As an example a mobo may by default assign the 1st disk sda to an internal Pata disk, a 2nd disk sdb to an internal Sata disk and a 3rd disk sdc to a USB flash drive. To boot from the USB flash drive first one imposed in the second booting queue sdc as the 1st disk, thereby making sda the 2nd disk and sdb the 3rd disk. This order is only executed if the CD is the first bootable device but there is no CD in the drive.

If there is a CD in the drive then the seconding boor disk order is not executed by the Bios, as it does manage to read this point and so the original factory-shipped detection disk order applies, in other word the USB flsh drive is the 3rd disk if booting from a CD but changes to 1st disk if the CD is removed.

The above effectively means when a Linux user boots up a Linux CD he automatically installs the Linux in sdc or the 3rd disk, known as (hd2) to Grub’s. When he withdraws the CD and boots the USB flash drive as the 1st disk the installed Linux will not work. It will work immediately if the user alters the (hd2) reference to (hd0) in Grub’s configuration file menu.lst. There is nothing to it but a user must think like the Bios.

(4) There are two types of installation in a USB flash drive.

The first one is the normal installation just like a hard disk. This is recommended if you want to use the USB regularly. All you need is a fast USB flash drive larger than 5Gb. Just treat the USB device exactly like a hard disk and install Linux inside.

The second installation, also called the Frugal install, is most common and it runs the Linux in the USB flash drive just like a Live CD. This effectively copies the entire content in the CD onto the USB drive and replaces its isolinux with Grub. Isolinux is the standard boot loader for booting from a CD while Grub or syslinux must be used on a USB drive. In this form many installers like to take over the entire disk for the one Linux installation and some distros simply use directly the factory-ship FAT filing system with the USB flash drive.

The difference between the two is that the first installation is about 4 to 5 times larger in the storage requirement. If the iso image is 700 Mb the installed version may be 3Gb. If the distro is installed normally in a partition inside a USB drive then it will behave no different to it being in any hard disk, except slower.

For the Frugal install, working as a Live CD, the Linux is the same size as the CD. In operation the distro is expanded and stored in the ram. As a rule the settings are not stored and the original image is read-only and not changed but re-used repeatedly in every booting. That is why and how a Linux can be installed, booted and work normally from a FAT partition.

The main disadvantage of a full installation in a USB drive is that it is painfully slow, especially with a slow pen drive. Flash memory is not efficient for consecutive read and write and ext3 should be avoided because the journalling activities can slow down the speed as well as shorten the life of the device. A solid state memory flash drive is guaranteed a fixed number of read/write cycles.

(5) While Grub can be put inside a flash drive a Linux "may" not.

This means Grub can be booted up but not the Linux itself. Grub will find the flash drive as long the Bios has a record of it. Grub is therefore able to find the kernel and load it into memory. However when Grub pass the control to the kernel and ceases operation it is up to the kernel to find the USB device and its partitions. Some distros have been compiled with the USB support at boot time in the ramdisk file initrd but other do not. Thus booting a Linux distro from a USB flash drive is not universally possible. For example the Debian family distros like Debian, Knoppix, Ubuntu etc has no problem to boot from a USB device but the Suse family does not entertain the same thing.

To put Grub alone in a flash drive I have written this tutorial. AFAIK Grub can be put into any flash drive as long as the Bios reports the booting from it.

In conclusion I think booting Grub or a Linux isn't a mystery as long as we are aware of the limitations. Nearly all of them are unrelated to Grub.

Last edited by saikee; 04-07-2008 at 07:29 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cant install USB Flash Drive Kingston DTI/1 hemanth_ap Linux - Hardware 3 05-03-2006 03:01 PM
install lilo/grub on a USB flash drive? flystar06 Linux - General 3 06-14-2005 09:48 PM
install smoothwall in a usb flash drive SlipAway172 Linux - Distributions 0 04-21-2005 08:34 PM
Install MandrakeLinux with bootable USB Flash Drive lothario Mandriva 1 12-10-2004 10:54 AM
Cannot Install Bootloader, XP on hda, Linux on sdb (USB MASS STORAGE DRIVE) neo5064 Linux - Newbie 3 12-29-2003 05:57 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:32 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration