HowTo: Make a bootable USB stick version of the Ubuntu Hardy LiveCD

Discussion in 'Other Operating Systems' started by HyRax1, May 3, 2008.

  1. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,745
    Location:
    At a desk
    I created this HowTo in an attempt to get past some of the technical issues that sometimes arise out of other guides for newbies - this is a mix of the bits that work or are useful out of other existing guides with amendments, and has been kept reasonably simple, but at the same time is a bit long-winded with explanation to ensure that you can't possibly make a mistake.

    Purpose: To boot the Ubuntu Hardy LiveCD from a solid-state portable medium (in this case, USB flash) instead of an actual CD.

    Scenario: You have a PC that you want to install Ubuntu to or needs rescue and you don't have a LiveCD handy, or perhaps the PC doesn't have a working CD drive or even a CD drive at all!

    Solution: If the PC supports booting from USB devices, then why not have a USB-bootable version of the Ubuntu LiveCD? We can dub this "Ubuntu LiveUSB". :)

    Pros:
    • Simple and convenient - a USB stick fits more readily in your pocket than a LiveCD does.
    • Depending on the USB stick and the host USB connection, it can boot faster than a CD.
    • Great for use as a rescue boot medium or if you want to take Ubuntu with you to use on other PC's such as Internet Cafe machines.
    • Scratches don't bother a USB drive. :)

    Cons:
    • Needs a PC that supports booting from USB devices (eg: "USB-HDD" in the BIOS), so that rules out many older PC's before the mid-Pentium 4 generation.
    • You will need permission from the owner of another PC to boot their machine from your USB stick.
    • This guide makes use of the familiar LiveCD environment, not a regular Linux install. Any changes made to the environment will be lost upon reboot.

    Prerequisites:
    • Ubuntu 8.04 Hardy Heron LiveCD or ISO (up to you which architecture you want to setup - 32-bit is ideal for ensuring it works on most PC's you encounter).
    • Any garden-variety USB flash memory stick of at least 1GB in size (we're putting a 700MB CD onto it!). You should be able to boot from any cheap USB stick, however there are caveats with some models of USB stick and is also dependant on the host PC's BIOS. In any case, just get hold of a reasonably well known brand and you should be OK. NOTE: To try and test this, I deliberately went out and purchased an el-cheapo unknown brand generic 1GB USB flash memory stick to see if I could break my guide and, aside from a slow boot (I think it's only a USB 1.1 device!), it boots and works perfectly.
    • A PC to do this on!

    With some minor modifications, this guide should also apply to just about any Linux distro.

    1. Boot up your Ubuntu-based PC as normal.
    2. Plug in your USB flash memory stick.
    3. Open up a terminal window.
    4. Type in:
      Code:
      $ sudo fdisk -l
      
      ...and you will get something similar to the following for each physical storage device on your PC:
      Code:
      Disk /dev/sdb: 2063 MB, 2063335424 bytes
      255 heads, 63 sectors/track, 250 cylinders
      Units = cylinders of 16065 * 512 = 8225280 bytes
      Disk identifier: 0x000d4ddc
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/sdb1   *           1          96      771088+   6  FAT16
      /dev/sdb2              97         250     1237005    b  W95 FAT32
      $ 
      
      This is my 2GB USB flash drive that I've broken up into two partitions (see Partitioning Guide the bottom of this post). It is mounted as /dev/sdb and has two partitions: /dev/sdb1 and /dev/sdb2 too.

      You don't have to partition your stick - that was my choice just to separate them. NOTE: If you already have a hard-drive called SDB then your USB stick will appear with a different name, eg: SDC, SDD, etc etc. Make a note of it and substitute in this guide as necessary.
      .
    5. In the case of your fresh, unused USB stick, it will only have one partition, will be formatted to FAT16 or FAT32 and generally will not be bootable.
    6. We need to make the stick bootable, so first unmount it (but leave it plugged in) with:
      Code:
      $ sudo umount /dev/sdb1
      
      (Repeat the above command for every partition on your stick only - do not unmount your hard-drives! In my case, I'd also have to issue sudo umount /dev/sdb2 as well).
      .
    7. Now type in:
      Code:
      $ sudo fdisk /dev/sdb
      
      ...and you will be presented with the FDISK command prompt, to perform operations on your USB stick at /dev/sdb.
      .
    8. Press "P" and hit enter. Your partitions will be listed. You will note there is a "Boot" column which should be empty. If the first partition shows an asterisk "*" in this column, then your stick is already bootable and you can skip to Step 12.
    9. Press the letter "A" on your keyboard and hit enter to set the Bootable Flag.
    10. You will be prompted for a partition number. Enter "1" and hit enter.
    11. Now type in "P" and hit enter. This will re-list the partitions on your USB stick. You should now see that the first (or only) partition now has an asterisk "*" next to it in the "Boot" column. If it does NOT have the asterisk shown, then repeat the "A" command again because it acts as a toggle - your stick might have already been made bootable and you've just made it unbootable.
    12. Now type in "W" and hit enter to write your changes to the USB stick and exit FDISK. Your USB stick should be automatically re-mounted at this time. If not, just unplug it and re-insert it.
    13. Now we need some extra software to complete the basic setup of your USB stick:
      Code:
      $ sudo apt-get install syslinux mtools
      
    14. When installed, type in:
      Code:
      $ sudo syslinux -sf /dev/sdb1
      
      ...which will install the bootloader needed for your USB stick to boot from.
      .
    15. Now let's relabel the USB drive with something meaningful (Ubuntu usually only uses the name "disk") using mtools:
      Code:
      $ sudo mlabel -i /dev/sdb1 ::ubuntulive
       Volume label is ubuntulive
      
      ...will label my USB stick's partition at /dev/sdb1 "ubuntulive", but call it what you want. The "ubuntulive" name will appear as the icon name on the Ubuntu desktop and will be referred to as /media/ubuntulive at the terminal. NOTE: When you disconnect and reconnect the USB stick, the name will appear in capitals as per MS-DOS conventions, ie: "UBUNTULIVE". If you prefer it to stay lowercase, or to use a mix of upper and lowercase letters, refer to Step 21 in the Partitioning Guide at the bottom of this guide.

      NOTE: If you get an error instead of confirmation of the new label, type in
      Code:
      $ echo mtools_skip_check=1 >> ~/.mtoolsrc
      
      ...and then repeat the mlabel command in this step.

      .
    16. Now we are ready to start copying the LiveCD. If you use a burnt-on-disc version, insert it now, otherwise if you have the downloaded ISO, then mount it with the following commands:
      Code:
      $ mkdir /dev/shm/myiso
      $ cd /path/to/my/downloaded/iso
      $ sudo mount -o loop ubuntu-8.04-desktop-i386.iso /dev/shm/myiso
      
      ...the above commands will mount the ISO to your RAM disk in a directory called "myiso" (which will be removed upon reboot).
      .
    17. Change over to the content of the disc with:
      Code:
      $ cd /media/cdrom
      
      ...or for ISO users, switch to the mountpoint:
      Code:
      $ cd /dev/shm/myiso
      
    18. Now begin the actual copy process with:
      Code:
      $ sudo cp -rfv casper disctree dists install pics pool preseed .disk isolinux/* md5sum.txt README.diskdefines ubuntu.ico casper/vmlinuz casper/initrd.gz /media/ubuntulive/
      
      This copies everything off the disc/ISO except for the MS Windows related stuff to your USB stick. This may take a minute or two. IGNORE THE SYMLINK AND STAT ERRORS that are returned from the cp command.
      .
    19. We're nearly there! One last thing to do and that is to convert the startup from ISOLINUX (for CD's) to SYSLINUX (for storage devices like hard-drives and your USB stick):
      Code:
      $ cd /media/ubuntulive
      $ cp isolinux.cfg syslinux.cfg
      $ cp isolinux.txt syslinux.txt
      
    20. Your Ubuntu LiveUSB stick is ready! Restart your PC and change your PC's BIOS to boot from "USB-HDD" or similar. Additionally you may also need to setup the "Drive Boot Order" too - some BIOS' treat the USB-HDD as another actual HDD and categorise it along with your physical hard-drive, so you will need to change the hard-drive boot order and ensure the USB drive comes before your physical hard-drive and also before any "Bootable add-in cards" option or the like. Refer to your motherboard's manual.


    OPTIONAL: PARTITIONING YOUR USB STICK
    In Step 4 of this guide, you saw how I have partitioned my USB stick in order to separate the LiveCD boot and my general storage. If you would like to do this, then read on.

    NOTE: Re-partitioning your USB stick will PERMANENTLY erase any data already on the USB stick. Ensure that your data is backed up PRIOR to performing partitioning!

    Perform the following actions after Step 7 of the guide above. When you have finished partitioning, resume the above guide at Step 13. This partitioning guide was taken directly from PenDriveLinux.com and amended a bit.

    1. Type P and Enter to show the existing partition.
    2. Type D and Enter to delete it.
    3. Type P and Enter again to show any remaining partitions (if partitions exist, repeat the previous step).
    4. Type N and Enter to make a new partition.
    5. Type P and Enter for primary partition.
    6. Type 1 and Enter to make this the first partition.
    7. Hit Enter to use the default 1st cylinder shown.
    8. Type +750M and Enter to set the partition size.
    9. Type A and Enter to make this partition active.
    10. Type 1 and Enter to select partition 1.
    11. Type T and Enter to change the partition filesystem.
    12. Type 6 and Enter to select the FAT16 file system.
    13. Type N and Enter to make another new partition.
    14. Type P and Enter for primary partition.
    15. Type 2 and Enter to make this the second partition.
    16. Hit Enter to use the default cylinder shown.
    17. Hit Enter again to use the default last cylinder shown.
    18. Type T and Enter to change the partition filesystem.
    19. Type 83 and Enter to select the generic LINUX filesystem type (which is EXT2 or EXT3, etc. If you prefer FAT32 so a Windows PC can see this partition, then type in B instead and hit Enter).
    20. Type W to write the new partition table and exit FDISK to the terminal prompt.
    21. Format the first partition with:
      Code:
      $ sudo umount /dev/sdb1
      $ sudo mkfs.vfat -F 16 -n ubuntulive /dev/sdb1
      
      ...which will format the partition to FAT16 and label it "ubuntulive".
      .
    22. Format the second partition to EXT2 for general storage with:
      Code:
      $ sudo umount /dev/sdb2
      $ mkfs.ext2 -b 4096 -L mybigfatusbstick /dev/sdb2
      
      ...which will format to EXT2 and label it "mybigfatusbstick" OR if you prefer FAT32, you need to have chosen FAT32 as the partition type in FDISK (Step 19 above) and then issue the following command:
      Code:
      $ sudo mkfs.vfat -F 32 -n mybigfatusbstick /dev/sdb2
      
      .
    23. Unplug and re-insert your USB flash memory stick to remount your partitions, and then resume the Ubuntu LiveUSB guide at Step 13.
     
    Last edited: May 4, 2008
  2. OP
    OP
    HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,745
    Location:
    At a desk
    Before I forget, it should be pointed out that if you INSTALL Ubuntu to your hard-drive via the USB flash method, when you reboot you may find that your USB flash drive attempts to get mounted as a CD device. This is a known bug in the installer and is easily worked around by editing the /etc/fstab file in your post-freshly installed system as follows:
    Code:
    $ sudo nano /etc/fstab
    
    ...and deleting the lines that refer to your USB flash drive, eg: if it's /dev/sdb1 then delete the line starting with #/dev/sdb1 and the immediate line after it. Save, exit, reboot and you can now insert your flash drive and see it mounted as normal instead of a CD device. See example below:
    Code:
    # /etc/fstab: static file system information.
    #
    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    proc            /proc           proc    defaults        0       0
    # /dev/sda5
    UUID=7e0d07cd-a38e-4db7-ac40-06c9c8dd94fc /               ext3    relatime,errors=remount-ro,noatime,nodiratime 0       1
    # /dev/sda2
    UUID=faf0c5e0-460f-4987-a5fa-c58b6f10aa7e /boot           ext3    relatime,noatime,nodiratime        0       2
    # /dev/sda3
    UUID=b95d2e13-8abc-4fe9-aa1c-638af16acc10 none            swap    sw              0       0
    /dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec,utf8 0       0
    [color="red"]# /dev/sdb1
    /dev/sdb1 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0[/color]
    
    Everything in this example fstab file is correct except for the last two lines as it refers to /dev/sdb1 which is my flash drive, but tries to mount it as CD-ROM media instead, which of course will fail.

    You want to delete these two lines, save and reboot. If you find you are missing a CD-ROM drive now, you probably don't have an entry for it (see above example again, the line immediately before the red-coloured section - the real CD-ROM drive is at /dev/scd0 mounted as /media/cdrom0 - copy that out into your fstab file).
     
    Last edited: May 3, 2008
  3. Doomed

    Doomed Member

    Joined:
    Sep 9, 2003
    Messages:
    138
    Location:
    Lake Macquarie
    Nice guide, thanks. It's always great when people make guides like this, I find them really helpful.

    I've been playing around with usb installs over the past few days, except I'm after a persistent install, because my hard drive died on my old computer and I want to be able to add and remove programs as I please. I've tried steps similar to what you've done (ie here), except syslinux.cfg is edited so that a persistent mode is added to the boot menu and references to /cdrom/ on paths are removed (your method does need this?).
    Unfortunately from what I've read, it seems persistence in Hardy Heron is broken, so I haven't had much luck so far, but possibly that was because of that bug you mentioned. I think I'll try it again and see how I go.
    I've been messing with making my usb disto with uClibc and busybox but that might be a bit beyond me... :(

    I'll play a bit more and see how I go I guess.
     
  4. OP
    OP
    HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,745
    Location:
    At a desk
    Glad to help. I'll look at doing a persistent guide/modification later then. :)
     
  5. Cypher_FTW

    Cypher_FTW Member

    Joined:
    Dec 30, 2005
    Messages:
    159
    Location:
    Auz
    Wow, this is brilliant! Would doing this for other distro's LiveCDs work, like for say LinuxMint, Sabayon, etc.. Because I wouldnt mind getting a big USB stick and packing a couple of distros onto it.

    :thumbup: Great guide! Im getting a new USB stick just so I can try it out I reckon.
     
  6. OP
    OP
    HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,745
    Location:
    At a desk
    Yep - this guide is primarily copying the CD content onto your stick and running it from there - that's it. About the only thing you might have to change for another distro is what you actually copy off the CD. In this guide it is customised to not include any of the Windows related stuff such as Wubi, etc from the Ubuntu LiveCD but I didn't have to do that - I could have just rsync'ed the lot. Other than that, the only real difference is swapping ISOLINUX for SYSLINUX, which is common to all distros anyway.
    LOL :p
     
  7. OP
    OP
    HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,745
    Location:
    At a desk
    OK, I've been playing around with it myself and concur that Persistence in Hardy is broken. There is a bug report about it and a workaround fix for it here, however I have been unable to successfully implement the workaround to get a persistent boot going myself. I'll keep playing with it and will post up results when I have them. In the meantime, the official fix for persistence is expected to be included in the next point release of Ubuntu due in July.
     
  8. Leca

    Leca Member

    Joined:
    May 10, 2003
    Messages:
    311
    Location:
    Adelaide, SA
    Great guide Hyrax :thumbup:

    A few weeks ago I was trying to do the same thing, from a windows based PC.

    Considered making a new thread for this, but a central location is probably the best if people are trying to source some decent info :)

    Requirements for guide:
    * Windows based PC
    * Latest version of Syslinux
    * Ubuntu or Variant of choice
    * USB Flash drive/thumb stick with enough storage for files

    Step 1

    Formatting the USB flash drive

    Select My Computer, right-click on the USB flash drive and select click Format.

    [​IMG]

    Select FAT32 as the file system. Click start and wait for the format to complete.

    Step 2

    Making the USB flash drive bootable

    Open the command prompt and change the directory to the extracted Syslinux/win32 folder.

    Code:
        cd Desktop/syslinux/win32
    Once in the correct directory, enter the following to install the syslinux bootlader to the USB flash drive

    Note: h: is the letter of your USB flash drive

    Code:
        syslinux -ma h:
    [​IMG]

    Press enter.

    Step 3

    Extract the Ubuntu ISO

    Right click on the ISO file and extract the files with WinRAR/7zip to the Ubuntu folder.

    [​IMG]

    Step 4

    Compiling the files.

    The USB flash drive is now bootable, the Ubuntu files have been extracted.

    Copy the files you extracted from the ubuntu-8.04 folder onto the empty USB drive.

    Move the contents of the isolinux folder to the root of the drive. eg: from H:\isolinux\ into H:\

    Rename isolinux.cfg file to syslinux.cfg

    Finished!

    Eject the USB flash drive, that’s it!

    A sub 5 minute solution to a problem that causes a lot of headaches for many people when trying to install without a CD/DVD.
     
  9. OP
    OP
    HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,745
    Location:
    At a desk
    Nice one! :thumbup:

    I actually need to update my guide to include how to do Persistence which is fixed in 8.04.1, but I'll do that later. :)
     
  10. Blinky

    Blinky Member

    Joined:
    Jul 4, 2001
    Messages:
    2,530
    Location:
    South TAS.
    All your guides are great! <no crawling intended>

    Well formatted and detailed.
    Thank-you! for taking the time to write & share them. :thumbup::thumbup:

    All you need to do now is document the pros and cons to life with raid, raid installs with Ubuntu. If you do, have a look at raid 10 on only two drives for fun.
    mdadm -C /dev/md0 --chunk 512 -n 2 -l 10 -p f2 /dev/sda6 /dev/sdb6
    http://www.linuxmanpages.com/man8/mdadm.8.php details the switches. :)
     
  11. Naru

    Naru (Banned or Deleted)

    Joined:
    Jan 13, 2005
    Messages:
    784
    Location:
    Brissy
    wow this is awesome. I have a lappy with a stuffed dvd rom drive so getting an os onto it wasnt easy. It took me ages just to install XP. (can't remember what I did but this will enable to use ubuntu as well. thanks!
     

Share This Page