Saturday 12 May 2007

Creating a LiveUSB PCLinuxOS

The objective is "simple" to have a 2Gb flash memory stick with a bootable PCLinuxOS that I can plug in almost any computer to have in a few seconds my "own" computer running on it!

Is like to have my own computer in a memory stick in my pocket! Nice!

Also, I will use it to test for some more time PCLinuxOS running on my PIV Dual Core 3000MHz 1Gb ram before I decide to remove Windows XP from it.

This tasks took me some time to figure out, but this is not something that normal user will do.
What normal users need is to get PCLinuxOS pre-installed in their computers (dual boot with PCLinuxOS beeing the default!?). Apparently Dell has arrived to an agreement to pre-install Ubuntu on their machines, I don't know the extent of that agreement but definitely that is the way how Linux will really get to the mass public.

Doing some googleing I found that there are two ways to prepare the LiveUSB. One from within Windows and the other from withing PCLinuxOS. As I had disconnected the monitor from my Windows box to see the PCLinuxOS box, I'll prepare it from withing PCLinuxOS. Also this is probably the way that most people do it. Load PCLinuxOS from the LiveCD and prepare the LiveUSB.

The link for the instructions on how to prepare the LiveUSB for PCLinuxOS are:

Create from Windows a Live-USB on a Flash Memory Stick
Create from PCLinuxOS a Live-USB on a Flash Memory Stick

In any case, in the end I didn't follow the instructions exactly as they are on those webpages. Those instructions have a weak point, they create only one partition on the flash and I learnt that to have a proper LiveUSB is necessary two have at least two (so you can keep all your configuration, changes, documents, etc on the memory stick).

These are the stepts that I followed:

  1. I have already the PCLinuxOS LiveCD physically in my CDROM and loaded as my OS.

  2. I logged as root.
    So we have full privileges to do what we need.

  3. Inserted the 2Gb USB flash memory stick.
    It can be done probably in just 1Gb, and if you have a bigger memory you can created a bigger second partition (will see it later).

  4. Open a terminal and type "fdisk -l" (without the quotes obviously)
    We do this to know which devices the PCLinuxOS is detecting. One of the will be your USB memory and it will be called something like /dev/sdx1 where x is the letter assigned by PCLinuxOS, usually a, b, c, etc... depending on how many USB devices you have connected.

  5. Type "umount /dev/sdx1" (replacing x with your flash drive letter)
    This will unmount your flash drive in case that it was already mounted. In Linux drives need to be mounted to a mounting point (like a logical directory) before the can be accessed, but that is not a problem for us now).

  6. Type "fdisk /dev/sdx" (replacing x with your flash drive letter).
    It will appear a menu where you will type:

  1. "p" to show the current partitions on the usb drive. Then type "d" + enter + the number of the partition to delete them all

  2. "n" to make a new partition.

  3. "p" to make the partition primary

  4. "1" to make this partition one

  5. hit enter to use the default first cylinder

  6. "+800M" to reserve 800Mb for this first partition. This is enough to fit the LiveCD info and a bit more just in case we need more space later.

  7. "a" to make this partition active

  8. “1” to select partition 1

  9. “t” to change it’s file system

  10. “6” to select the fat16 file system

  11. "n" to make a new partition.

  12. "p" to make the partition primary

  13. "2" to make this partition two

  14. hit enter to use the default first cylinder

  15. hit enter to use the default last cylinder, it will take the rest of the space available

  16. "a" to make this partition active

  17. “2” to select partition 2

  18. “t” to change it’s file system

  19. “83” to select the Linux file system

  20. type w to write the new partition table

  1. type umount /dev/sdx1 (replacing x with your device) to unmount the partition

  2. type umount /dev/sdx2 (replacing x with your device) to unmount the partition

  3. Now we are going to give format to the partitions. For that we need to do

    1. type mkfs.vfat -F 16 -n usb /dev/sdx1 to format the first partition as fat (replace x with your flash drive)

    2. type mkfs.ext3 /dev/sdx2 to format the second partition as Linux native (replace x with your flash drive). We need this file system to be able to save all our configuration and documents to the USB.

The above could probably be done also from the “Administration Center->Mount Points->Create, delete and resize hard disk partitions” but I tried and didn't get good results, may be my fault so I decided to do it manually.

  1. Now in theory it is enough to remove and reinsert the USB memory, but I found that not to work well in my system, that is why I recommed to reboot your computer with they USB key removed and insert it when loaded up.

  2. Log in again as root, open a terminal

  3. Type mkdir /tmp/usb

  4. Type mount /dev/sdx1 /tmp/usb (replace x with your USB drive)

  5. Type mount /mnt/cdrom (or cdrom2 if you have more than one)

  6. Type cd /mnt/cdrom (or cdrom2)

  7. Type cp -rf livecd.sqfs isolinux/* /tmp/usb
    This is going to take some time as it has to copy the whole CD

  8. Type cd /tmp/usb

  9. Type mv isolinux.cfg syslinux.cfg

  10. We are going to add now a new menu option when loading PCLinuxOS. To do this type:
    vi syslinux.cfg
    (or use your favorite editor)
    Just below "gfxboot bootlogo" insert the following lines:

    label LiveUSB_SDA
    kernel vmlinuz
    append livecd=livecd initrd=initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=en lang=en splash=silent fstab=rw,noauto changes=/dev/sda2

    If you happen to have more USB drives connected (as it happens to me) it will be useful to add a similar section just below but replacing "sda" by "sdb" (both in label and in changes). It depends on what drive letter your system assigns to the USB memory stick. In any case, you should always leave he sda option for when you plug your usb memory in a computer different than yours, for example in an Internet Cafe, where chances are that your USB drive will be the only available.

  11. Type cd

  12. Type umount /tmp/usb

  13. Type syslinux -sf /dev/sdx1 (replacing x with your USB device)

  14. Reboot your computer and set your system BIOS to boot from USB-HDD. Also set the boot priority to boot the USB device first if this option is available. Some BIOS have the option to select each boot from which device we want to boot. For example, in mine pressing F11 while booting displays a menu with all the devices from which I could boot, including the USB key.

  15. Now the computer can complaying saying that there is no boot sector or something similar. Mine did. In that case you need to:

    1. Reboot again wih the LiveCD,

    2. log in as root

    3. open a terminal

    4. type “lilo -M /dev/sdx” (replacing x with your USB device)

    5. reboot your computer and make the bios to boot from the usb device (if you have not done it already).

      Now it should work, if it doesn't I would recommend repeating from step 19, at lest that happened to me the first time and the second one worked.

10 comments:

Anonymous said...

Hey, this is a great guide, and I'm almost there, but I have a problem :(

In step 22, after I run the command, it returns "sh: mcopy: command not found"

What should I do about this?

Anonymous said...

OK, I found a solution :)

So if anyone else has my problem with step 22, just search for the "mtools" package in Synaptic and install it. Then you'll be able to complete the installation :)

Unknown said...

Great guide, thanks a lot.

Only one problem: My Notebook simply can't boot from USB.

Is it possible to boot from the LiveCD intially and then redriect the boot to the USB-key for PCLinuxOS, just like the case in MCNLive using "livecd fromusb persist" or similar options? :-)

Unknown said...

Kjetil, I haven't tried this myself but I believe it should work.

Download and create a boot disk from SuperGrub. Boot using the bootdisk and choose to load from your usb device.

Anonymous said...

Note that if you get problems booting from the USB drive you could try skipping the part of activating partition 2.

Activating partition 2 is like telling the system that we want to be able to boot from that partition too, but we only want to boot from partition 1.

daytribe said...

I followed the steps and got it working just fine. I did have to de-activate partition 2 though. It works great on my laptop but on my desktop PC I can't see any of my "persistence". Is this something to do with step 19 where you edit syslinux.cfg? My flash drive shows as sdb and I have edited the text that you insert to reflect this. How can I get a persistent OS on both my laptop and my PC?

Anonymous said...

Very good tutorial. However, for my Dell D610 Latitude, it was necessary to omit steps 16 and 17 - do not make the second partition active. When the second partition is active, the computer would not boot. -JC

Anonymous said...

Actually, you dont need two partitions at all. Try this tutorial: PCLOS Minime 2008 USB install

Condur said...

skyp step 16 ( "a" to make this partition active )

alibabah1 said...

hi, i noted that for my P3 system, it was required for the line "default livecd" inside syslinux.cfg to be changed to CAPS as "default LiveCD" inorder for it to boot properly.

it wasn't able to point properly when it was "default livecd" (smallcaps) and showed Error: Could not find kernel image
do note guys!