Monday, January 15, 2007

Linux On A Stick: Part II

Two weeks back I did part 1 of Linux on a stick. In part 1, we spoke of how to get a Live CD onto your USB jump drive and the problems with it. Using the Live CD version on the jump drive alone allows you to boot to your jump drive into the distro of Linux that you have chosen. However, anything you change while in this live CD session will not be saved. Therefor, if you changed anything, such as download NEdit because you are sick of GEdit, you will have to do it all over again next time you decide to boot from your USB jump drive. With the Part 2 technique, that I am about to describe, you will be able to have such changes saved.

Ready to get to it now? Ok, first off, you need to know if your your computer can boot from the USB drive. Just do a restart and go into the bios set up (I have a completely separate menu on my computer that is called the boot menu that I can get to if I hold down F8, then I just select from the list of available items that I wish to boot from. You may just have to deal with the bios, however). From the bios, go into the boot area. Go down to where is says something along the lines of "1st boot item" and change it from your master hard drive to your USB jump drive. Your drive may have to be plugged in for you to be able to select it from the bios screen. If you do not have the option to boot to the USB jump drive than you can just stop reading here and keep using your live CD version or you can update your bios.

[More after the jump]

For those of your that are able to boot to your USB jump drive, hit up THIS site to take the Linux test to see which distribution of Linux is best for you. Like it says on the site, this is not an exact science, but rather just some basic questions to see what you like most about the different versions of Linux that are out there. I dig Ubuntu and knew that I was going to use Ubuntu for the install that I will soon describe. But my results also suggested that I would like Fedora as well. I haven't heard much about Fedora, and what I have heard wasn't good, but I am more willing to give it a try now. I will also give this tutorial a test using Fedora to see if the same procedures will work on multiple distro's of Linux. But that will be another post in the future, lets kick this pig into gear.

First up, I'm using Ubuntu and will be installing this on a 2 Gig PNY Attache USB 2.0 jump drive. So head on over to their site and get yourself a disc image. And I will also be installing Ubuntu on the drive, but there are different versions of Ubuntu. The ones I recommend getting is either the latest version of Ubuntu, which is code named Edgy, or the latest version of XUbuntu, code name Edgy Eft. Ubuntu is the full blown version of Ubuntu, while XUbuntu is much more scaled down. XUbuntu would be more ideal for you if you want a lighter version of an OS running on your computer or if you have an older computer that really can't handle the full version. The first step that needs to be done is to partition your USB jump drive. So go ahead and burn the image of your choice to a CD and boot to it.

Once your live CD is up and running, open up a terminal window and type in "sudo su", with out the quotes of course. You are now in root mode and will save yourself some extra typing during the upcoming commands that you will need. Now we need to delete the partition(s) that reside on your USB jump drive, but first we need to find out where it is and what it is called. If you didn't already, plug in your jump drive, it will automatically be mounted for you. Now type "fdisk -l". You should now see a list of drives that reside in your computer. One of them is your jump drive and is usually mounted to the folder /dev/sda. Now, thinking ahead a bit, I made 2 partitions: one for the files the OS needs and one for the OS itself. The first partition will be the bulk of the jump drive and will be accessible when you are in Windows, while the second partition is just for Ubuntu and you will not be able to see in Windows. I read one tutorial online that used a 1 Gig jump drive and made the first partition 700 Mb and then the rest of the drive for the second partition. So I just made that into a percentage and turned 70% of my 2 Gig jump drive into the first partition and used the rest for the OS partition. Now that you have the sizes in mind for your partitions, type in "umount /dev/sda1" then "fdisk /dev/sda". Now I will put the next commands in a tabular form for easy reading. Its just for creating the 2 partitions and then writing them to the jump dirve.

WARNING: This will erase everything that is on the jump drive. Do a back up if you want to keep something!

CodeResults
pShows partitions on the jump drive, they all need to be deleted
dReady to delete partition
1Delete partition 1 on /dev/sda
d, 2Delete partition 2 on /dev/sda, if there is one present
nCreate a new partition (partition number 1)
pMake that partition primary
1Call it partition number 1
ENTERAccept the starting cylinder number
+1700MEnding cylinder number (size of the first partition in Mb)
aMake this partition active
t, 1, 6Make this partition FAT format
nCreate a new partition (partition number 2)
pMake this partition primary
2Call this partition number 2
ENTERAccept the starting cylinder (this is the end cylinder from the first partition)
+300MUse up the last of the jump drive for this partition
wWrite the partitions to the drive


Now that we have created the partitions, we need to format them:
mkfs.vfat -F 32 -n (SOME NAME) /dev/sda1
mkfs.ext2 -b 4096 -L casper-rw /dev/sda2
You can name the first partition whatever you want to, but the second partition MUST be named casper-rw. Now remount the partitions by unplugging the jump drive and plugging it back in, they should mount automatically. And then we are now ready to install Ubuntu to your jump drive. Shutdown your computer and reboot to your normal operating system. Once there, open up your file explorer and navigate to your Ubuntu CD that you burned and just booted to and copy the following files to your (SOME NAME) partition. You should actually see the name that you named it in the file explorer window. Also, make sure that you have the ability to see hidden files if you do not already (in the file explorer in Windows, Tools menu -> Folder Option then the View tab and check "Show hidden files and folders"). Now start copying:

From the CD to the root of your (SOME NAME) partition, copy the following:
Folders : 'casper', 'disctree', 'dists', 'install', 'pics', 'pool', 'preseed', '.disk'
Files : all files from the folder 'isolinux', 'md5sum.txt', 'README.diskdefines', 'ubuntu.ico', 'casper/vmlinuz', 'casper/initrd.gz', 'install/mt86plus'
If you decided to use XUbuntu, you will not see some of these files or filders. Don't worry about that and just copy over what you do have that is on that list, it will still work. In the root of your jump drive, rename the file 'isolinux.cfg' to 'syslinux.cfg' then open it with notepad and erase everything in it. Now copy the following into the file:

DEFAULT custom
GFXBOOT bootlogo
APPEND preseed/file=preseed/ltsp.seed boot=casper initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL custom
menu label ^Start Ubuntu in persistent mode
kernel vmlinuz
append preseed/file=preseed/ltsp.seed boot=casper persistent initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL live
menu label ^Start or install Ubuntu
kernel vmlinuz
append preseed/file=preseed/ltsp.seed boot=casper initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL xforcevesa
menu label Start Ubuntu in safe ^graphics mode
kernel vmlinuz
append preseed/file=preseed/ltsp.seed boot=casper xforcevesa initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL check
menu label ^Check CD for defects
kernel vmlinuz
append boot=casper integrity-check initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL memtest
menu label ^Memory test
kernel mt86plus
append -
LABEL hd
menu label ^Boot from first hard disk
localboot 0x80
append -
DISPLAY isolinux.txt
TIMEOUT 300
PROMPT 1
F1 f1.txt
F2 f2.txt
F3 f3.txt
F4 f4.txt
F5 f5.txt
F6 f6.txt
F7 f7.txt
F8 f8.txt
F9 f9.txt
F0 f10.txt

Now, save and close the file and you are all set to boot to your "new" jump drive that is now a full blown operating system.

Some side notes:
The tutorial that I borrowed some info from also installed the grub boot loader. I, however, could not get grub to install to my jump drive using that part of the tutorial from the other site. If anyone out there knows a way to install grub, please let me know and I would be happy to update this post with that info as well as credit you for it.

Other than that, everything works great. I just go into my boot menu and boot to my jump drive and then take it from there. Some things you might want to do is mount your hard drive(s) that are in your computer:
From a terminal window,
sudo su
fdisk -l
cd /media
mkdir windows
mount /dev/hdd2 /media/windows

That hdd2 might be different for you. Just look at the results from the fdisk command to see which is the ntfs partition of your windows hard drive and then enjoy! Any feedback, positive or negative, or any additions on something I missed would be well appreciated in the comments below.

Update:
If anyone out there has some storage space that has a ton of bandwidth, I would be more than happy to make a couple of zip files that contain the files and folders that are copied from the Live CD to your jump drive. Just give me a heads up in the comments below if you can supply a spot on the net for the zip file.

Image source: Linux Forum
Original Tutorial: Ubuntu Site

[Read part 1]

27 comments:

dwizzle said...

Nice tutorial. I'll have to try it, I've been interested in it and haven't found a cheap usb drive, but now I have, lol.

Anonymous said...

I have an older Thinkpad laptop that can boot from USB, but it's only got a USB version 1, not 2.0. Can I still run the normal Ubuntu with this slow USB?
Thanks.

Ryan said...

Jan,
Yes, you can. That is just the usb jump drive that I have. It should work from any 1.0/2.0 drive. And I believe that usb 2.0 items are capable of downgrading to 1.0, because I use my 2.0 jump drive at work and a popup comes up saying something along the line of this 2.0 device can run faster if you plug it into a 2.0 usb port. So you should be fine with whatever you have. Good luck and thanks for the comment!

Anonymous said...

Hi, why do we make the fat partition active, and not the ext2 partition active? Thanks.

Jan said...

Hi,
I'm trying this with a USB connected laptop hard drive, of about 20 gb size. When I tried to make the sda1 partition larger than your example (15000MB) it only created a partition that ended at 1939. Is this because it's a FAT partition and not a FAT32 partition? How do I get the most out of my laptop hard drive? I'm very new to linux, but want to give it a go on this external USB drive... Thanks. -Jan

Ryan said...

Jan,
in your case, I would just boot from the live cd and do a normal install. In the install process, you are able to pick and choose where you want Ubuntu installed. Just pick your external usb hard drive and you should be good to go.

This will, however, install grub into the master boot record. To get around this, you might want to try FAT32. Keep me posted!

Anonymous said...

I really like your idea of an active OS on a usb drive. I tried to set it up, per your instructions, on my 4gb usb drive using Ubuntu, but with no luck.

I made three partitions, the two you specified and an extra for general storage (Fat32). The rest I tried to do as you said but it wouldn't boot from the USB. Thoughts?

Ryan said...

@Paul
The first partition is for Ubuntu's use and the second partition is Fat32 already. So there really is no need for a third partition. I'm not really even sure if the OS partition would like that.

What I did was just make folders in that second partition. Since it is fat already, both xp and ubuntu can use it. Just slap some folders in there and use the folders instead of making a third partition.

Just out of curiosity, what size did you make all of your partitions?

Anonymous said...

I used the following partitions:
OS fat32 - 700mb
Os ext2 - 300mb
storage fat32 - 3gb

Windows didn't even read the 3gb partition. So back to the drawing board. My thought was to have them all nicely sectioned off so I didn't accidentally mess up something on the OS fat32 partition. Either way, I got it bootable using http://pendrivelinux.com/, but it doesn't retain changes, as you said.

Which distribution has the best wireless lan driver support? I have a 1450 mini PCI out of Dell and linux, even with ndiswrapper give me garbage.

Thanks Ryan...I'll give the dual partition another try to see if I can get it bootable.

Ryan said...

It might be that ext2 partition messing things up. I used the latest version of Ubuntu, so that should have all of the bells and wistles you need for you wireless stuff, since it is so new. If it doesn't have what you need, I would just hit up the Ubuntu forums if I were you.

Yeah, try the 2 partition as a primer just to see if it works. Keep me posted!

Anonymous said...

Hmm...I've never been this bad at linux in the past...still can't get it working. I went back to the 2 partition scheme, but the boot just doesn't read the usb as bootable. First time, I got a blank screen (even though I made sure the 700mb partition was active). The second time around, I got "volume is not bootable" or some such message.

How important is the spacing and such in the syslinux.cfg file? The "splash --" line gets messed up when I copy it. Could I just keep it the isolinux.cfg file to see if that's the problem?

Thoughts?

Paul

Ryan said...

I'm afraid I'm a bit stumped. If you were able to get your jump drive to work with the pen linux hack then it should work fine with this one as well.

The only thing that I can think of to do next would be for you to go directly to where I got the initial setup from the Ubuntu forums. It's in the "via" at the bottom of the page. Perhaps I missed something from there(?)

Anonymous said...

Funny, I've been looking into this on my own for the past few days and apparently a lot of people are playing with this.

take a look at these:

home.graffiti.net/jaclaz:graffiti.net/Projects/USB/USBstick.html
www.msfn.org/board/index.php?showtopic=69211
www.knoppix.net/forum/viewtopic.php?p=98279#98279
www.knoppix.net/forum/viewtopic.php?t=11796
www.knoppix.net/forum/viewtopic.php?t=11796&postdays=0&postorder=asc&start=30
advancemame.sourceforge.net/doc-makebootfat.html
www.irongeek.com/i.php?page=security/dual-boot-slax-linux-bartpe-windows-usb
www.howudune.com/knoppix2.php
www.weethet.nl/english/hardware_bootfromusbstick.php
www.911cd.net/forums//index.php?showtopic=14181&hl=

Unknown said...

This is nice... I used part of it to correct issues I got when I tried similar docs from another web page. My issue turned out that;
a), I was running from one USB (Slax) and trying to update another USB (for Mint-Ubuntu), and when I did the Grub (?), I think that it got confused w/ the "sdb1", "sdc1", "sdc2" thing.
b) I think that when I initially did the master boot record, I mis-specified.

As a noob-aside, let me confess that I was NOT paying really CLOSE attention ALL the way through the steps (remember, these were taken from multiple web pages)... I used Copy/Paste for many of the steps, and accidently did mkfs.ext3 on sdA2 --- MY MAIN LAPTOP __HARD-DRIVE__. Argh. So, by my best guess, I have over-written my WinXP MBR w/ 1700M of Linux ext3 inodes (whatever those are).

Anybody out there know if I can resurrect the remaining files from the disk? (very unhappy).

So, the results do far:
1) New, cheap 2G drives. 3 w/ Slax (Kill Bill, customized using MySlax Creator), 1 w/ MintLinux (Ubuntu variant), couple w/ Puppy and DSL.
2) New attempt of installing a stable, well respected, PERSISTANT distro - i.e. Ubuntu. A little success, but I'm working through the issues step by step - haven't actually gotten the blasted think to complete a boot yet, much less do something Linux-y for me.

Corrected "active partition", Installed isolinux to the correct partition, re-insstalled the MBR --- and it gets to boot.... or so close. It tanks in BusyBox (to play for a while, I guess). I understand none of this, but back to the web repository for more info.

I think I can get past this hurdle and I can then go on to two tests == challenges, if you will.

Local discounter has 1 and 2 G USBMemory sticks. Speed tests show a difference between them as about 5M and 16M. Somebody at work saw my cutesy stacked slax, She was interested in getting into
my slax, so to speak.

I hope to get a working Linux Ubuntu USB on her high-speed drive, and then "verse" it against my existing Mint Install. Then, a second test between the two sticks when they have the same distro on them. With my slow USB distro, it takes me about 1 minute to boot Slax (Kill Bill). It takes me just about the same time to boot mint, but it's a little unstable.
The boot times w/ CD are pretty slow, so we beat LiveCD pretty much all the time... Boot up 12x faster to load a full OS, networking, etc, that fits on a key ring? Pretty cool!

Russtang said...

I've followed these instructions to the T a couple times and keep having the same issue.

Everything looks good in fdisk and the partitions seem to format fine.

After the final step of editing the syslinux.cfg file and rebooting from the USB, my laptop gives me the "Missing operating system" error message.

Any ideas?

Thanks,
Russ

Anonymous said...

I had the same problem, "Missing Operating System"

Follow these instructions instead...

http://www.althack.com/2006/03/10/how-to-run-linux-on-a-usb-drive/

Ryan said...

Different jump drives will work differenly for this. So I suggest giving this a try. If it does not work then do a search for "linux on a stick" along with the type of jump drive you have and see if anyone else is having the same problem you are having. Your type of jump drive just might not be able to do this.

Russtang said...

Thanks anonymous and Ryan. I was able to get my thumbdrive to boot DSL, so the next step is Ubuntu.

Russ

Anonymous said...

I followed the tutorial several times and could not get it to work. I did some searching on the web and tried a few things out and finally got it to work.

For all those who are getting something like "Missing operating system" when you try to boot from the USB flash drive try the following.

-Install everything in this tuturial.
- Go to http://www.althack.com/2006/03/10/how-to-run-linux-on-a-usb-drive/
- use the link to download syslinux
- and only follow the part of the tutorial that pertains to syslinux.

Done. Hopefully you can boot from the Flash drive now.

Good Luck,
mpphilli

Anonymous said...

Hey, just wondering, would it be possible to dual-boot two distros on one flash drive?
Like maybe Ubuntu, and DSL? DSL is only like 51Mb. This project is something that i would like to try, just getting the info is hard, haha!

Anonymous said...

Hey, i have another question, sorry, I was wondering, I always hear about corrupt files on USB Drives, and I'm thinking, "Ok, corrupt files not good for OS..." have you had any trouble with files becoming corrupt? I just wanna make sure this thing is feasable before i try it. thanks!

Anonymous said...

Hi,

Nice instructions. My USB key boots great. I select Persistent mode, but the changes (configuration and others) doesn't seem to be saved on my USB key, from one time to the other.

Email: marc.lafontaine@servicecanada.gc.ca

Please Help !

Anonymous said...

I have followed the instructions 3 or 4 times now and it says Missing Operating System on boot. Any idea if there is somewhere I can download the exact files to put on the usb stick that have allready been tried?

Cheers Guys

Anonymous said...

Anonymous,

I had the same trouble with with a missing operating system. Go back to the previous post that references the althack.com instructions. I followed their instructions to format the jump drive with the HP Utility. Skip the formatting and partition instructions listed here.
Then finish with Ryan's directions to:
2) Copy the files and folders as described on this blog
3) Go back to althack.com and run the syslinux utility as described.
4) THen Change the isolinux.cfg file to syslinux.cfg with the text included in this blog.
And it finally worked. BTW - I installed UNBUNTU 7.04 on a PNY 2GB drive using the live CD image

Only issue is my system does not retain changes either. Anyone know if it's related to file permissions from copying off a CD -- or perhaps because I do not have a separate partition on my flash drive?

Robert

Anonymous said...

Marc,

I may have found the issue on persistence (at least for me) Ubuntu "Feisty" has a persistence bug -- it doesn't work.

see: https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
for more details.

Robert

Anonymous said...

Thanks for the nice tutorial!

Anonymous said...

Hi, well I am a newbie in the Linux world. Did everything the tutorial said and it worked fine, but when I try to boot from my USB jump drive now, my Toshiba Laptop says "This is not a bootable disk. Please insert a bootable floppy . . .
Any suggestions what I could do?
Thanks, Chris