LiveUsbPendrivePersistent

Differences between revisions 68 and 117 (spanning 49 versions)
Revision 68 as of 2007-12-04 09:49:32
Size: 24939
Editor: c-9884e253
Comment:
Revision 117 as of 2017-04-30 18:13:47
Size: 27985
Editor: es20490446e
Comment: Portable Linux no longer available
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
||<tablestyle="float:right; font-size: 0.9em; width:30%; background:#F1F1ED; background-repeat: no-repeat; background-position: 98% 0.5ex; margin: 0 0 1em 1em; padding: 0.5em;">'''Contents'''[[BR]][[TableOfContents]]|| ||<tablestyle="float:right; font-size: 0.9em; width:30%; background:#F1F1ED; background-repeat: no-repeat; background-position: 98% 0.5ex; margin: 0 0 1em 1em; padding: 0.5em;"><<TableOfContents>>||

[[/Comments
]]
Line 5: Line 7:
It is possible to have Ubuntu or Kubuntu on a USB pendrive (AKA USB Stick or Thumb drive or Flash drive) or USB hard disk drive with persistent mode. This means that you can boot from a USB pendrive and keep customisations such as keyboard layout, numlock, preferences, additional packages saved on the pendrive.
This can be done using linux or windows. You will need a USB pendrive of 1 GB or more. This page is written after having tested the instructions on a Peak III 1 GB pendrive. The preparation of the pendrive is explained using 'fdisk' because I had errors with 'gparted' and i could not give the partitions a volume name. I used Ubuntu to make the pendrive. In Kubuntu it is more or less the same. Where you see 'ubuntu' replace it by 'kubuntu'. I will mark the other differences.

If you are looking for help in putting the 'alternate' cd on a pen drive, then try the instructions here: https://help.ubuntu.com/community/Installation/FromUSBStick . They're for feisty, but more or less work for gutsy too. Note that you may need to add "vesa vga=771" to the append= line in syslinux.cfg in order to get the installer to display properly.

= Installing Ubuntu on USB pendrive using Linux =

== Preparing the USB pendrive ==
It is possible to have Ubuntu or Kubuntu on a USB drive (AKA USB Stick or Thumb drive or Flash drive) or USB hard disk drive with persistent mode. This means that you can boot from a USB drive and keep customisations such as keyboard layout, numlock, preferences, additional packages saved on the drive. This can be done using linux or windows. You will need a USB drive of 1 GB or more. This page is written after having tested the instructions on a Peak III 1 GB drive. The preparation of the drive is explained using 'fdisk' because I had errors with 'gparted' and i could not give the partitions a volume name. I used Ubuntu to make the drive. In Kubuntu it is more or less the same. Where you see 'ubuntu' replace it by 'kubuntu'. I will mark the other differences.

If you are looking for help in putting the 'alternate' cd on a pen drive, then try the instructions here: https://help.ubuntu.com/community/Installation/FromUSBStick . They're for feisty, but more or less work for gutsy too. Note that you may need to add "vesa vga=771" to the append= line in syslinux.cfg in order to get the installer to display properly.

= Method 0: Automatically create Live USB system =

Jaunty (9.04) onwards provide USB Startup Disk Creator system tool. It uses the [[https://wiki.ubuntu.com/usb-creator|usb-creator]] to create USB bootable startup disk on USB drive. You may also start the application from the terminal with :
{{{
gksudo usb-creator-gtk
}}}

Then choose the desired ubuntu .iso image, the usb device you want to use, erase the disk and set the degree of persistence (the slider) you need. Note that the maximum space that can be allocated for persistence is limited to 4GB (maximum file size on a FAT32 filesystem is 4GB). This limit can be overcome and is explained later on. If you do want a larger degree of persistence, set persistence to 128mb for now and continue. Hit Make Startup Disk and wait till it finishes. You are now in possession of a USB drive that can be used to run/install ubuntu on most computers. Persistence gives you the freedom to save changes, in the form of settings or files etc, during the live session and the changes are available the next time you boot via the usb drive.

To make the persistence larger (> 4GB), while still on your normal Ubuntu Installation, mount the pendrive if it is not mounted already. View the files in the FAT32 partition of the pendrive. You will now be able to see a file called casper-rw. It will be the same size as the value set on the slider. Delete this file. Open gparted :
{{{
gksudo gparted
}}}
select the live usb.

There will be a single partition only. Resize it so that you can have two partitions. You only need the current partition to be as large as it is already. You can safely move the resizing slider all the way to the left until there is just enough breathing space between the slider and the end of the first partition (coloured block). Make the newly created free space an ext4 or ext3 or ext2 partition and label it "casper-rw" without the double quotes. Hit apply changes. So now you have two partitions, the fat32 partition and the ext4 partition called casper-rw. This partition can be of any size and will be responsible for saving your data between boots. You can now boot using the usb drive and any changes you make will remain.


== Live USB creator (GUI-based) ==
WARNING: Does NOT create persistent installs on Hardy (8.04 LTS) or earlier; works only with Intrepid 8.10.

Live USB creator automates the process of creating a bootable Live USB system from a running Ubuntu Live CD. Simply run the Live CD, install the tool and start the Live USB installation from the System administration menu.

https://launchpad.net/liveusb -- probono

(A better link: https://launchpad.net/liveusb/+announcements which explains that you run the livecd and the you click on the link: http://ppa.launchpad.net/probono/ubuntu/pool/main/l/liveusb/)

{{{{http://klik.atekon.de/liveusb/screenshot.png}}}}

If you can't start the Live USB system from a running Ubuntu Live CD (perhaps you lack a functioning CD burner), you can actually just install liveusb to your normal system with the Ubuntu Live CD just ''mounted''. Mount the image using the command

{{{sudo mount -o loop /path/to/cd-image /media/cdrom0}}}

After running the {{{liveusb}}} command and installing to your USB key, unmount the image with

{{{sudo umount /media/cdrom0}}}

= Method 1: Installing Ubuntu directly to USB drive from installer CD =

You can directly install Ubuntu 8.04 Hardy Heron to a USB drive using the Live CD. Simply select the USB drive as the installation target instead of the local hard disk.

'''Note:''' ''This will use the USB drive for /tmp, which will cause extra wear on the flash memory. If you're booting from a system with enough RAM, it would be more desirable to use a tmpfs in RAM for /tmp, in which case you'd want to copy the ISO CD image to the USB drive and add a persistent partition (see next section). On the other hand, if you're not concerned with your USB drive wearing out (lifetime warranty, wear leveling, etc), continue in this section.''

'''Ensure''' in the "Installation Summary" screen that you '''choose to install GRUB to the USB key stick, and not the computer's hard disk''' (click the Advanced button to do so). Choose to install GRUB to the first USB partition (i.e. /dev/sdb1, rather than simply /dev/sdb). ''Failure to do this will cause the GRUB on your hard disk to be changed and render the system unbootable from the hard disk, requiring you to boot from a CD and reinstall GRUB to the hard disk (possibly requiring a chroot to the hard disk filesystem first).''

You will also need to manually edit the menu.lst file of the new USB installation to change the boot references to /dev/sda, rather than /dev/sdb (or /dev/sdc etc.). This can be done by booting to the live distro mode of the Ubuntu install CD and editing the /boot/grub/menu.lst file on the USB stick. You can mount the USB stick using the Places menu -- once mounted, it can be found at /media/disk. ''Note: This step may not always be necessary.''

''Note:'' There is a bug with the Ubuntu 8.04 install CD that means USB key stick installs are screwed -- the desktop won't appear when you login. To get around this, you must do the following when you boot for the first time (before logging in at GDM):

1) switch to a virtual console (Ctrl+Alt+F2)

2) kill the X-server (sudo killall gdm)

3) empty the /tmp folder (sudo rm -rf /tmp/*)

4) Type startx, and perform a system update when the desktop appears (if you don't want to install a lot of software, just update the gnome-keyring package(s) -- that's the one that causes the problem)
 
Note that this should be fixed in the Ubuntu 8.04.1 install CD.

= Method 2: hiding the ISO image in a partition in the USB drive =

If you'd like to understand how the process works, the page [[http://rudd-o.com/en/linux-and-free-software/a-better-way-to-create-a-customized-ubuntu-live-usb-drive|A better way to create a customized Ubuntu Live USB drive]] has instructions to build a bootable, persistent USB drive with Linux.

These instructions have been tested to work correctly with Ubuntu Intrepid Ibex (8.10), and should work correctly with any distribution that uses Casper and supports persistency.

= Method 3: Copying the ISO CD image to the USB drive =

== Preparing the USB drive ==

'''8.04 Hardy:''' Unfortunately, there is a [[https://bugs.launchpad.net/ubuntu/+source/casper/+bug/219192|bug]] in the versions of casper in Hardy that cause the persistent partition to not be mounted on boot. There is a [[https://bugs.launchpad.net/ubuntu/+source/casper/+bug/219192/comments/3|workaround]] available, and you can download a [[http://launchpadlibrarian.net/15990491/initrd.gz.8.04.1.casper.fixed|replacement initrd.gz]] for 8.04.1 (place in casper directory on first partition of USB key).

'''Good news! It IS possible to make Feisty persistent!''' These instructions are needed but not sufficient. Check this[[http://www.pendrivelinux.com/2007/09/20/how-to-make-ubuntu-704-casper-persistent/]]. Essentially, you need to decompress initr.gz (with gzip and cpio); edit the ''init'' file adding a case called 'persistent' (see details at the link) and recreate initr.gz. I guess that without this case, the 'persistent' passed in the syslinux.cfg is simply ignored. I got persistence at the first attempt. ''Elfantin''
Line 16: Line 86:
The preparation of the pendrive is explained using 'fdisk'. You could use 'gparted' or 'qtparted' as well. However I had errors with 'gparted' and I could not give the partitions a volume name. I tested 'qtparted' as well and it worked fine. You can install 'qtparted' under Ubuntu through synaptic although it is native to Kubuntu.
Another issue in my case was that 'fdisk' recognised a fat32 filesystem as linux. So I checked it with gparted and it was OK.

Plug in the pendrive and check its device name:
'''Caution''': Be careful using any disk utility to partition or format dives as a small error could damage your operating system or overwrite a whole partition of files. Remove any external drives, cameras or other storage devices connected to your computer (except for the USB drive you wish to repartition). Get familiar with the difference between ''1 KB'', ''1 MB'' and ''1 GB''; as well as the difference between a drive (e.g. ''/dev/sda'') and a partition (e.g. ''/dev/sda2''). Get familiar with the drives and partitions on your computer: What are the sizes? Which is root, '/'? Which is the USB device?

Use 'disk utility' or 'gparted' to ''unmount'' the USB device, and then to delete any existing partition(s). Create a 750 MB FAT partition named 'ubuntu' (or whatever); then an ext2 partition named 'casper-rw' (exactly) on the remaining space. Select the 750 MB ubuntu partition, click "edit partition" and check "bootable". If you were successful, skip down to [[#Installing Ubuntu on the USB drive]]. If you prefer to work with 'fdisk' on the command line, keep reading below.

The preparation of the drive is explained below using 'fdisk'. You could use 'gparted' or 'disk utility' as well.

  ''However I had errors with 'gparted' and I could not give the partitions a volume name. I tested 'qtparted' as well and it worked fine.''

  ''Another issue in my case was that 'fdisk' recognised a fat32 filesystem as linux. So I checked it with gparted and it was OK.''

Plug in the drive and check its device name:
Line 25: Line 101:
Assuming you have your Ubuntu set up to automatically mount your USB stick, this should show you what {{{/media/pendrive}}} or whatever it's called corresponds to on the device level. Assuming you have your Ubuntu set up to automatically mount your USB stick, this should show you what {{{/media/drive}}} or whatever it's called corresponds to on the device level.
Line 28: Line 104:
Line 35: Line 110:
We are going to suppose that its name is /dev/sdX where X is the disk device such as  /dev/sda or /dev/sdc. Please be sure to use the correct number for X which matches the name you find for your pen drive. '''Double check it!''' [Note: on newer computers, which use serial ATA disks, /dev/sda is typically the main hard drive; do not overwrite this!]

Note: on some usb-sticks fdisk says "Note: sector size is 2048 (not 512)", in which case you may very well be out of luck trying to boot from it, see mailing list thread: [http://syslinux.zytor.com/archives/2007-March/008284.html Problem with 2GB USB Pendrive]

Now we are going to create 2 partitions: 1 partition of 750 MB with a fat32 filesystem and 1 partition with the rest of the pendrive space with volume name "casper-rw" and ext2 filesystem. The first partition will be made active.

Go in terminal and unmount the drive:
We are going to suppose that its name is /dev/sdX where X is the disk device such as /dev/sda or /dev/sdc. Please be sure to substitute the correct letter for X which matches the device name you find for your pen drive. '''Double check it!''' [Note: on newer computers, which use serial ATA disks, /dev/sda is typically the main hard drive; do not overwrite this!]

Note: on some usb-sticks fdisk says "Note: sector size is 2048 (not 512)", in which case you may very well be out of luck trying to boot from it, see mailing list thread: [[http://syslinux.zytor.com/archives/2007-March/008284.html|Problem with 2GB USB Pendrive]]

Now we are going to create 2 partitions: 1 partition of 750 MB with a fat32 filesystem and 1 partition with the rest of the drive space with volume name "casper-rw" and ext2 filesystem. The first partition will be made active.

Open 'terminal' and unmount the USB drive (replace 'sdX1' with the appropriate partition name):
Line 47: Line 121:
Fire up fdisk for the pendrive:
Fire up 'fdisk' for the drive:
Line 53: Line 126:
This will give you the fdisk prompt.
Look to what you have on the pendrive. Check if you have to backup the data you have on it. 'p' will print the content of /dev/sdX. If you have partitions on it remove them ('d', 'partition number').
Make partition 1: 'n' for new partition, 'p' to make it a primary partition, '1' to call it partition number 1, then just press enter to accept the proposed starting cylinder, '+750M' to make its size 750 MB. Then 'a' to make it the active partition. Set the file system of partition 1 to FAT: 't', then '1', then '6'. ''( I already had partition 1 selected so for me it was just 't' then '6' -Jordan_U)''
Make partition 2:  'n' for new partition, 'p' to make it a primary partition, '2' to call it partition 2, then just press enter to accept the proposed starting cylinder, then press enter to accept the proposed ending cylinder.
Save and quit fdisk with 'w' to write the new settings.

  ''I had an issue with this that every time I saved my partition setup using 'w', I'd get an
:''

  ''
WARNING: Re-reading the partition table failed with error22: Invalid argument.''
  ''
The kernel still uses old table.''
  ''
The new table will be available at the next reboot. ''

  ''
If this happens, and then checking with 'sudo fdisk -l' doesn't show the new partitions - here's a fix if you have a Windows OS, though I don't know why it works:''

  '' Do nothing else with the pendrive. Insert into Windows (mine was XP) and format with Disk Management and use FAT32. Now, 'sudo fdisk -l' should see the two partitions under the pendrive. -neverard''

    '' I had the same error, using gparted instead of fdisk worked for me -Jordan_U''
This will give you the fdisk prompt.  Look to what you have on the drive.  Check if you have to backup the data you have on it. 'p' will print the content of /dev/sdX. If you have partitions on it remove them ('d', 'partition number').

=====
Make partition 1: =====

1. 'n' for new partition

2.
'p' to make it a primary partition

3.
'1' to call it partition number 1

4. T
hen just press enter to accept the proposed starting cylinder

5.
'+750M' to make its size 750 MB

6.
Then 'a' to make it the active partition

=====
Set the file system of partition 1 to FAT:  =====

1. 't'

2. then '1'

3.
then '6'

 
''(I already had partition 1 selected so for me it was just 't' then '6' -Jordan_U)''

  ''there seems to be an incongruity: when you change the filesystem to FAT using option "t" the filesystem option "6" is FAT16. w95/fat32 is option "b". Which file system needs to be used? -rebelcat1''

=====
Make partition 2: =====

1. 'n' for new partition

2. 'p' to make it a primary partition

3. '2' to call it partition 2

4. then just press enter to accept the proposed starting cylinder

5. then press enter to accept the proposed ending cylinder

6. Save and quit fdisk with 'w' to write the new settings.

  ''I had an issue with this that every time I saved my partition setup using 'w'
, I'd get:''
  {{{
  
WARNING: Re-reading the partition table failed with error22: Invalid argument.
  
The kernel still uses old table.
  
The new table will be available at the next reboot.
  }}}

    ''
If this happens, and then checking with 'sudo fdisk -l' doesn't show the new partitions - here's a fix if you have a Windows OS, though I don't know why it works:''

    ''Do nothing else with the drive. Insert into Windows (mine was XP) and format with Disk Management and use FAT32. Now, 'sudo fdisk -l' should see the two partitions under the drive. -neverard''

      ''I had the same error, using gparted instead of fdisk worked for me -Jordan_U''
Line 73: Line 183:
sudo fdisk -l  sudo fdisk -l
Line 78: Line 188:
Line 82: Line 191:
}}}'' }}}
Line 85: Line 194:
Line 87: Line 197:
  ''there seems to be an incongruity: when you change the filesystem to FAT using option "t" the filesystem option "6" is FAT16. w95/fat32 is option "b". Which file system needs to be used? -rebelcat1''
Line 96: Line 204:
Partition 1 : FAT32, full size of stick minus 750M  Partition 1 : FAT32, full size of stick minus 750M
Line 100: Line 208:
Follow the instructions, but use /dev/sdx2 instead of /dev/sdx1, and make sure you make /dev/sdx2 bootable in fdisk.

For persistence, follow the instructions to create a loopback file at LiveCDPersistence. This feature works fine from a loopback file inside a FAT32 filesystem, just as long as the file contains a supported unionfs filesystem like ext2.
Follow the instructions, but use /dev/sdX2 instead of /dev/sdX1, and make sure you make /dev/sdX2 bootable in fdisk.

For persistence, follow the instructions to create a loopback file at [[LiveCDPersistence]]. This feature works fine from a loopback file inside a FAT32 filesystem, just as long as the file contains a supported unionfs filesystem like ext2.
Line 111: Line 219:
If the persistent boot automatically mounted the root of the FAT32 filesystem as well as the casper-rw file, it would be ideal. If the persistent boot automatically mounted the root of the FAT32 filesystem as well as the casper-rw filesystem, it would be ideal.
Line 116: Line 224:
Line 122: Line 229:
Mount the partitions on the pendrive. Take out the pendrive and put it back. Ubuntu Dapper or Edgy will mount the pendrive automatically if you have checked this option under System -->Preferences--> Removable media. Otherwise use 'mount':
Mount the partitions on the drive. Take out the drive and put it back. Ubuntu Dapper or Edgy will mount the drive automatically if you have checked this option under System -->Preferences--> Removable media. Otherwise use 'mount':
Line 131: Line 237:
== Installing Ubuntu on the USB pendrive ==

Download the Ubuntu image (for example, {{{ubuntu-7.10-desktop-i386.iso}}}) or put in the install CD if you have it.
If you use the downloaded image you can access it as follows (supposing that the image is in the cuurent directory):
== Installing Ubuntu on the USB drive ==

Download the Ubuntu image (for example, {{{ubuntu-11.04-desktop-i386.iso}}}) or put in an Ubuntu install CD if you have it.

If you use the downloaded image you can mount it to make it accessible as follows, using 'terminal' (supposing that the iso image is in the current directory):
Line 138: Line 244:
sudo mount ubuntu-7.10-desktop-i386.iso ubuntuCD -o loop
}}}

You should now see the CD's icon on your desktop.

Open the CD's top-level folder and make sure that you see the hidden files too. (verify if View-->Show Hidden Files is checked).

Copy the following folders and files to the 1st partition of your USB pendrive:

F
olders: 'casper', 'disctree', 'dists', 'install', 'pics', 'pool', 'preseed', '.disk'

Files: all files from the folder 'isolinux', 'md5sum.txt',
'README.diskdefines', 'ubuntu.ico'

So you do not copy the folder 'isolinux' to the pendrive but only its contents directly to the root of the first partition of the pendrive.

Copy 'casper
/vmlinuz', 'casper/initrd.gz', 'install/mt86plus'. So you will have these files double on the pendrive: once in the root '/' of the partition and once in the folder 'casper' or 'install'.

Rename the file 'isolinux.cfg' to 'syslinux.cfg' either by right clicking on it and selecting 'rename'.

You can also run the following commands in the terminal
. If you copy/paste, take care to make your browser window large enough to not have accidental line breaks inserted. And remember to replace {{{/media/ubuntu}}} with {{{/media/whatmountpointyouhave1}}} if you used a different name for the mount point.
sudo mount ubuntu-11.04-desktop-i386.iso ubuntuCD -o loop
}}}

You can now access the files via the 'ubuntuCD' folder.

Open the CD's top-level folder and make sure that you see the hidden files too. (verify that View-->Show Hidden Files is checked).

Copy the following folders and files to the 750 MB partition of your USB drive:
 * Copy folders: '.disk', 'casper', 'dists', 'install', 'pics', 'pool' and 'preseed' (skip the 'boot' folder);
 * Copy the folder 'isolinux' to the drive and rename it to 'syslinux';
 * Copy the file
'README.diskdefines', and optionally, the 'usb-creator.exe' and 'wubi.exe' files (skip the 'autorun.inf' and 'md5sum.txt' files);
 * Rename the file 'syslinux/isolinux.cfg' to 'syslinux/syslinux.cfg' on the U
SB drive by right clicking on it and selecting 'rename';
 * Rename the file 'syslinux
/isolinux.bin' to 'syslinux/syslinux.bin'.

Alternately
, you can run the following commands in 'terminal'. If you copy/paste, take care to make your browser window large enough to not have accidental line breaks inserted. And remember to replace {{{/media/ubuntu}}} with {{{/media/whatmountpointyouhave1}}} if you used a different name for the mount point.
Line 160: Line 261:
Line 163: Line 263:
cp -rf casper disctree dists install pics pool preseed .disk /media/ubuntu
cp isolinux/* md5sum.txt README.diskdefines ubuntu.ico /media/ubuntu
cp ca
sper/vmlinuz casper/initrd.gz install/mt86plus /media/ubuntu
cd /media/ubuntu
cp -rf casper dists install pics pool preseed .disk /media/ubuntu
cp -rf isolinux /media/ubuntu/syslinux
cd /media/ubuntu/syslinux
Line 168: Line 267:
mv isolinux.bin syslinux.bin
Line 172: Line 272:
== Making the pendrive bootable ==

We are going to install the linux bootloader 'syslinux'. This bootloader needs a configuration file which is 'syslinux.cfg'. This is the file we just made by renaming 'isolinux.cfg' from the installCD. However we have to modify this file.
Open the file 'syslinux.cfg' from the pendrive with your favorite texteditor. For instance:

{{{
gedit syslinux.cfg
Unmount the iso image that you mounted above, using 'terminal'.
{{{
sudo umount ubuntuCD
}}}

== Making the drive bootable ==

We are going to install the linux bootloader 'syslinux'. This bootloader gets its menu from 'syslinux/txt.cfg'. We will modify this file. Open 'syslinux/txt.cfg' from the USB drive with your favorite text editor. For instance:
{{{
cd /media/ubuntu/syslinux
gedit txt.cfg
Line 182: Line 286:

  * Search and replace {{{/casper/}}} with nothing
  * Search and replace {{{/cdrom/}}} with nothing
  * Search and replace {{{/install/}}} with nothing
  * Change the {{{DEFAULT}}} to something unique. Here, we use {{{persistent}}}, but it could be anything.
  * Copy the first {{{LABEL}}} section, paste it in after itself, and make the following edits to the original:
    * The {{{LABEL}}} argument should be changed to what you put in {{{DEFAULT}}} above
    * The {{{menu label}}} should be changed to describe the option; {{{Start Ubuntu in ^persistent mode}}} would seem suitable, with a caret before the "p" to make it a shortcut key for this option
    * The word {{{persistent}}} should be added into the {{{append}}} line (this is the crucial point!)

The following is an example of what you might end up with, and should be current as of Gutsy.

{{{
DEFAULT persistent
GFXBOOT bootlogo
GFXBOOT-BACKGROUND 0xB6875A
APPEND file=preseed/ubuntu.seed boot=casper initrd=initrd.gz quiet splash --
LABEL persistent
  menu label Start Ubuntu 7.10 in ^persistent mode
  kernel vmlinuz
  append file=preseed/ubuntu.seed boot=casper persistent initrd=initrd.gz quiet splash --
LABEL live
  menu label ^Start or install Ubuntu
  kernel vmlinuz
  append file=preseed/ubuntu.seed boot=casper initrd=initrd.gz quiet splash --
LABEL xforcevesa
  menu label Start Ubuntu in safe ^graphics mode
  kernel vmlinuz
  append file=preseed/ubuntu.seed boot=casper xforcevesa initrd=initrd.gz quiet splash --
LABEL driverupdates
  menu label Install with driver ^update CD
  kernel vmlinuz
  append file=preseed/ubuntu.seed boot=casper debian-installer/driver-update=true initrd=initrd.gz quiet splash --
LABEL oem
  menu label ^OEM install (for manufacturers)
  kernel vmlinuz
  append file=preseed/ubuntu.seed boot=casper oem-config/enable=true initrd=initrd.gz quiet splash --
LABEL check
  menu label ^Check CD for defects
  kernel vmlinuz
  append boot=casper integrity-check initrd=initrd.gz quiet splash --
LABEL memtest
  menu label ^Memory test
  kernel mt86plus
  append -
LABEL hd
 * Search and replace '/cdrom' with nothing;
 * Copy the first 'label' section, paste it in before itself, and make the following edits to this new section:
   * The 'label' argument should be changed to something unique, here we use 'persistent';
   * The 'menu label' should be changed to describe the option; '^Use Ubuntu in persistent mode' would seem suitable, with a caret before the "U" to make it a shortcut key for this option;
   * The word 'persistent' should be added into the 'append' line (this is the crucial point!);
 * Optionally, change the 'default' to the label name used above (e.g. 'persistent').

The following is an example of what you might end up with:
{{{
default persistent
label persistent
  menu label ^Use Ubuntu in persistent mode
  kernel /casper/vmlinuz
  append file=/preseed/ubuntu.seed boot=casper persistent initrd=/casper/initrd.lz quiet splash --
label live
  menu label ^Try Ubuntu without installing
  kernel /casper/vmlinuz
  append file=/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash --
label live-install
  menu label ^Install Ubuntu
  kernel /casper/vmlinuz
  append file=/preseed/ubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd.lz quiet splash --
label check
  menu label ^Check disc for defects
  kernel /casper/vmlinuz
  append boot=casper integrity-check initrd=/casper/initrd.lz quiet splash --
label memtest
  menu label Test ^memory
  kernel /install/mt86plus
label hd
Line 230: Line 318:
  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
}}}

The menu choice called 'Persistent' was made the default so that when booting up you can just hit Enter to start your customized session.

You can also copy and paste this text as making a new file 'syslinux.cfg'.

  * Kubuntu difference: text editor 'kwrite' instead of 'gedit'.
  * Kubuntu difference: replace 'preseed/ltsp.seed' by 'preseed/kubuntu.seed'.
  * Edgy difference: replace {{{file=preseed/ubuntu.seed}}} with {{{preseed/file=preseed/ubuntu.seed}}}
  * Dapper difference: replace {{{file=preseed/ubuntu.seed}}} with {{{preseed/file=preseed.lstp.seed}}}

The last thing to do is installing the bootloader.
Make sure you have the 'syslinux' and 'mtools' packages installed.
The following command should be harmless if they are already installed.
}}}

The menu choice called 'persistent' was made the default so that when booting up you can just hit 'Enter' to start your customized session.

=== Install bootloader ===

The last thing to do is install the bootloader. Make sure you have the 'syslinux' and 'mtools' packages installed. If not, open 'synaptic' and select them from the package list to mark them to be installed, then "apply" the changes.

Or use 'aptitude' or 'apt-get' from the command line. For example, the following command should be harmless if they are already installed.
Line 263: Line 331:
(Or 'sudo synaptic' and select from the package list, or use 'apt-get').

First you need to unmount your usb stick:
First you need to unmount your usb stick using 'disk utility', or use 'terminal' to enter the following commands (replacing 'sdX1' with the appropriate partition name for the 750 MB ubuntu partition on your USB device):
Line 271: Line 337:
This command will install the bootloader on your pendrive: This command will install the bootloader on your drive:
Line 276: Line 342:
  ''don't know why, but i had to use the -f switch (syslinux -f /dev/sda1) - bernstein''
    '' same here - I had to use the -f switch - krishnan ''
  ''don't know why, but i had to use the -f switch, ({{{syslinux -f /dev/sdc1}}}) - bernstein''

''same here - I had to use the -f switch - krishnan ''
Line 281: Line 348:
  ''According to this page[http://www.damnsmalllinux.org/wiki/index.php/Installing_to_a_USB_Flash_Drive 1] syslinux 3.35 should be used to get support for fat32, maybe that is the problem since edgy ships with 3.11. According to the changelog 3.35 only seems to introduce support for subdirectories.''   ''According to this page[[http://www.damnsmalllinux.org/wiki/index.php/Installing_to_a_USB_Flash_Drive|1]] syslinux 3.35 should be used to get support for fat32, edgy ships with 3.11. According to the changelog 3.35 only seems to introduce support for subdirectories.''
Line 284: Line 351:
Line 289: Line 355:

then you will need to install the mtools package.

Eject the pendrive:
then you will need to install the 'mtools' package.

Eject the drive:
Line 298: Line 362:
Reboot on the pendrive, change some settings, reboot again and check if the changes are kept (persistence check).

So that is it.

Do not forget to check if the computer you are going to use the pendrive on boots USB devices first (look in BIOS settings).
Enjoy (k)ubuntu whereever you go.


= Installing Ubuntu on USB pendrive using Windows =
Boot on the USB drive, change some settings, reboot again and check if the changes are kept (persistence check).

Do not forget to check if the computer you are going to use, boots USB devices first (look in BIOS settings).

So that is it. Enjoy (k)ubuntu where ever you go.

  ''If you boot the drive and persistency works but when you log in to gnome you get a message saying that it couldn't write to .ICEauthority, then a simple fix is deleting .ICEauthority. You can automate that by doing this:''
  {{{
  echo >> .bashrc
  echo "# This makes GNOME work" >> .bashrc
  echo "rm .ICEauthority 1>/dev/null 2>/dev/null" >> .bashrc
  }}}

Those using Lucid (10.04) to make a pen drive to boot Precise (12.04) that is to say, using the previous LTS release to go to the next one, will need to be aware of this incompatibility between the syslinux versions involved:

https://bugs.launchpad.net/ubuntu/+source/syslinux/+bug/608382

there are a couple of work-arounds (eg, typing 'help' at the prompt and then hitting 'enter') but the bug has been triaged and labeled WONTFIX since Maverick and as late as March 2012.

 

= Installing Ubuntu on USB drive using Windows =

=== UNetbootin (GUI-based, runs from either Windows or Linux) ===

[[http://unetbootin.sourceforge.net/|UNetbootin]] automates this task by providing a GUI to create a bootable Ubuntu Live USB drive from an ISO file, and can be run from both an installed Windows or Linux system, or from a liveCD.

{{http://sourceforge.net/dbimage.php?id=294729}}

== Preparing the USB drive ==
Line 310: Line 395:
== Preparing the USB pendrive ==

Download a copy of the [http://h18000.www1.hp.com/support/files/serveroptions/us/download/23839.html HP format utility] for USB drives, this utility makes it as easy to format USB pen drives as it is to format floppies.
Download a copy of the [[http://h20000.www2.hp.com/bizsupport/TechSupport/SoftwareDescription.jsp?lang=en&cc=us&mode=3&taskId=135&swItem=MTX-UNITY-I23839|HP format utility]] for USB drives, this utility makes it as easy to format USB pen drives as it is to format floppies.

''Don't bother wasting your time with this HP utility - it is rather useless. You can format the entire drive as FAT32 using the built in windows format (right click on the drive and select format, make sure to select FAT32 as the FS type). I found no way to partition the drive in windows, not even with PowerQuest's Partition Magic (which usually does everything you could want). Either boot off an ubuntu CD/DVD and follow the linux instructions, or if you can't do that, simply follow these instructions but use the whole flash drive for the live CD, then once you have booted from it, you can repartition and make the ext2 volume from within ubuntu itself. I simply pulled the flash drive out and re-inserted it - this ensures ubuntu is no longer using it. Not sure what the risks are - I didn't have any troubles, but perhaps you should do this at your own risk (or maybe somebody knows a safer way). If somebody knows a free utility which can partition a flash drive in winxp, please put it here!!! - mrwolf''
Line 318: Line 403:
== Installing Dapper or Edgy on the USB pendrive == == Installing Dapper or Edgy on the USB drive ==
Line 321: Line 406:
The way to do this is to mount the iso image file and copy the files that way. You can do this with NERO or [http://download.microsoft.com/download/7/b/6/7b6abd84-7841-4978-96f5-bd58df02efa2/winxpvirtualcdcontrolpanel_21.exe Windows VirtualCD]. You might want to do it this way if you don't want to burn a CD.

== Making the pendrive bootable ==
The way to do this is to mount the iso image file and copy the files that way. You can do this with NERO or [[http://download.microsoft.com/download/7/b/6/7b6abd84-7841-4978-96f5-bd58df02efa2/winxpvirtualcdcontrolpanel_21.exe|Windows VirtualCD]]. You might want to do it this way if you don't want to burn a CD.

== Making the drive bootable ==
Line 327: Line 412:
Open WordPad and edit the file syslinux.cfg as described in the Linux section. 

Open a command prompt and change directory to the location of the syslinux folder. For example, if you placed the folder on your desktop then: cd C:\Documents and Settings\(your user name)\Desktop\syslinux-3.11\win32 (by the way you DO know that command prompt has command completion just like in Linux (start entering characters and then press the TAB key to complete the entry)). 
Open WordPad and edit the file syslinux.cfg as described in the Linux section.

Open a command prompt and change directory to the location of the syslinux folder. For example, if you placed the folder on your desktop then: cd C:\Documents and Settings\(your user name)\Desktop\syslinux-3.11\win32 (by the way you DO know that command prompt has command completion just like in Linux (start entering characters and then press the TAB key to complete the entry)).
Line 332: Line 417:
syslinux -f X:
--> where X: is replaced by the drive letter of your USB key. Be careful to pick the correct drive letter!

= Comments =

 * http://www.pendrivelinux.com/2007/09/28/usb-ubuntu-710-gutsy-gibbon-install/ has instructions which look very similar to this page, albeit perhaps simpler and more condensed. (They have a page for Feisty, too.) However, they require you to install a somewhat mysterious {{{initrd}}} from a tar file they provide on that site, without any explanation. Does anybody know anything more about that site?
   * The tar in the gutsy link that was posted above really only has a pre-modified syslinux.cfg file. It should work for ubuntu, but it won't work for kubuntu/xubuntu liveUSB persistence installs. - WaXHeLL
 * '''Feisty will not be persistent''' on a USB pendrive due to a version mismatch between Unionfs and the kernel. [https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591 Here's the launchpad entry] and [http://ubuntuforums.org/showthread.php?p=2687688#post2687688 a forum thread] describing the problem. Apparently there should be a [http://www.mail-archive.com/ubuntu-bugs@lists.ubuntu.com/msg327694.html workaround involving a Feisty/Herd3 hybrid installation]. You could probably also download the source to a new Unionfs, compile it and merge to the pendrive, but I have no idea how - HelgeDK

 * Some links in this page are broken (the long URLs are broken with ellipses).

 * If you want to install the test releases of Edgy Eft, you might want to look at CustomizedInitrd.

 * As syslinux does not support the "GFXBOOT" command the boot menu will lack some features, e.g. you cannot change the language before booting. You can specify a language and keyboard layout via kernel parameters, though. To boot into a German LiveCD environment, you would add the following to your "APPEND" lines in syslinux.cfg: {{{
locale=de_DE bootkbd=de console-setup/layoutcode=de console-setup/variantcode=nodeadkeys
}}}

 * Some USB keys don't have a master boot record. In these cases, the problem can usually be fixed by running {{{
lilo -M /dev/sdX}}} '' I had to do this to get it to boot - Krishnan ''

 * Alternatively, if you haven't got lilo installed, use the 'install-mbr' command from the 'mbr' package: {{{
sudo apt-get install mbr
sudo install-mbr /dev/sdX}}} -JohnMccreesh '' I could not get mbr to install, but lilo worked - krishnan'' ''This broke my partition so I had to reformat - HelgeDK''

 * This may be my fault, but I created a Persistent pen drive from Ubuntu using these instructions and it worked perfectly, but I had installed an Edgy Beta, when I decided to update it to the final only a windows machine was available, follwing the windows instructions ( minus partitioning as that was still there from the previous install ) I do not get the normall Ubuntu prompt with a "custom" option at the top like before, instead I get a prompt with "Boot:" and I have to enter vmlinuz to boot, if I just hit return Ubuntu boots but something fails and it drops into a recovery console. Could somebody confirm that the windows directions are correct ( my suspicion is that it is because in Ubuntu you are using Ubuntu's custom version of syslinux while in windows you are using the "vanilla" version ) Also, the direction on where to find syslinux could be clearer, I found them at http://www.kernel.org/pub/linux/utils/boot/syslinux/ with no indication that the .zip file was indeed for windows, I tried the newest version at that time: http://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-3.31.zip and the exact version mentioned in the instructions http://www.kernel.org/pub/linux/utils/boot/syslinux/Old/syslinux-3.11.zip both gave the same result -Jordan U
  * I successfully installed Edgy (final) to an USB drive, following the linux instructions but using syslinux-3.20 for Windows. Afterwards I installed GRUB in the MBR which also works fine. -JanSchlüter
   I ran syslinux from Ubuntu on the same drive changing nothing else and it worked, I honestly don't know what went wrong with the windows version. Can you confirm that when you installed from windows it not only booted but correctly showed the menu with the preconfigured options, "custom" "live" "memtest" etc? - Jordan U.
    In my installation I can still use GRUB to load syslinux. Syslinux displays the ubuntu logo and a command prompt. I can enter {{{memtest}}} to boot Memtest86+ or press return to boot the ubuntu live environment. I didn't use the windows version of syslinux only, though - I tried ubuntu's version first which failed to create LDLINUX.SYS, then I tried the windows version. ''Maybe'' it only works in combination... -JanSchlüter
I (successfully) made a USB boot drive using these instruction and later saved the working partitions because I needed the drive for another purpose - on restoring the partitions and running syslinux again I couldn't get my drive to boot - after many hours of head-scratching and re-installing I found that the boot flag wasn't set! Just be aware that sometimes simple things can trip you up.. David C.

  * Someone known as mjcpa has made a patched version of Feisty that supports persistence. You can find it at http://88.191.31.14/ubuntuFeistyPatched/

  * Just a thanks to all that contributed - Krishnan

  * Some problems have been reported with Feisty and early Gutsy releases. This is just to confirm that I could successfully make a liveUSB with Gutsy tribe 5. More details here[http://reachbeyondgrasp.blogspot.com/2007/09/carry-gibbon-in-your-pocket-how-to-make.html]

  * I've installed a liveUSB persistence for Gutsy release, however I get segfaults on shutdown (turn off quiet and splash in the boot options). This leads to some invalid/unwritten files. Reference https://bugs.launchpad.net/bugs/147117 and https://bugs.launchpad.net/ubuntu/+source/upstart/+bug/125702 for possible details. No ideas on fixes yet. This may be related to the .ICEauthority bug and others. Ext3 may help the data corruption (but I still get the segfaults), but probably decreases the life of the flash drive. - WaXHeLL

  * On the matter of "wearing out" your flash memory, is it possible to solve the (perceived) problem with aggressive write caching and a diffident choice of filesystem? I had the thought that XFS might be suitable because it's very aggressive about write caching, but of course, it's a journalled filesystem so it will have a constant chatter of metadata to the disk, although this is a small volume of data. Of course, I've never even heard anecdotal evidence of a modern flash drive wearing out, under any kind of load, so until we start hearing such things it's just premature optimization - and I'd be willing to bet that the next generation of high performance portable storage will be around by then. At the very least, flash drives double the size will be half the price :-)

**WINDOWS** my pen drive did not immediately boot: using "syslinux -sma <drive>" fixed this. i didn't test, but i suspect the option i needed was "a", setting the partition to active.
{{{
syslinux -maf X:
}}}
 * where X: is replaced by the drive letter of your USB key. Be careful to pick the correct drive letter!
 * This will write the Master Boot Record (MBR), as well as mark the partition active.

= See also =

 * http://www.pendrivelinux.com
 * http://www.debuntu.org/how-to-install-ubuntu-linux-on-usb-bar
 * https://help.ubuntu.com/community/Installation/FromUSBStick
Line 376: Line 431:
CategoryLive CategoryUsb CategoryBootAndPartition CategoryBootAndPartition

/Comments

Introduction

It is possible to have Ubuntu or Kubuntu on a USB drive (AKA USB Stick or Thumb drive or Flash drive) or USB hard disk drive with persistent mode. This means that you can boot from a USB drive and keep customisations such as keyboard layout, numlock, preferences, additional packages saved on the drive. This can be done using linux or windows. You will need a USB drive of 1 GB or more. This page is written after having tested the instructions on a Peak III 1 GB drive. The preparation of the drive is explained using 'fdisk' because I had errors with 'gparted' and i could not give the partitions a volume name. I used Ubuntu to make the drive. In Kubuntu it is more or less the same. Where you see 'ubuntu' replace it by 'kubuntu'. I will mark the other differences.

If you are looking for help in putting the 'alternate' cd on a pen drive, then try the instructions here: https://help.ubuntu.com/community/Installation/FromUSBStick . They're for feisty, but more or less work for gutsy too. Note that you may need to add "vesa vga=771" to the append= line in syslinux.cfg in order to get the installer to display properly.

Method 0: Automatically create Live USB system

Jaunty (9.04) onwards provide USB Startup Disk Creator system tool. It uses the usb-creator to create USB bootable startup disk on USB drive. You may also start the application from the terminal with :

gksudo usb-creator-gtk

Then choose the desired ubuntu .iso image, the usb device you want to use, erase the disk and set the degree of persistence (the slider) you need. Note that the maximum space that can be allocated for persistence is limited to 4GB (maximum file size on a FAT32 filesystem is 4GB). This limit can be overcome and is explained later on. If you do want a larger degree of persistence, set persistence to 128mb for now and continue. Hit Make Startup Disk and wait till it finishes. You are now in possession of a USB drive that can be used to run/install ubuntu on most computers. Persistence gives you the freedom to save changes, in the form of settings or files etc, during the live session and the changes are available the next time you boot via the usb drive.

To make the persistence larger (> 4GB), while still on your normal Ubuntu Installation, mount the pendrive if it is not mounted already. View the files in the FAT32 partition of the pendrive. You will now be able to see a file called casper-rw. It will be the same size as the value set on the slider. Delete this file. Open gparted :

gksudo gparted

select the live usb.

There will be a single partition only. Resize it so that you can have two partitions. You only need the current partition to be as large as it is already. You can safely move the resizing slider all the way to the left until there is just enough breathing space between the slider and the end of the first partition (coloured block). Make the newly created free space an ext4 or ext3 or ext2 partition and label it "casper-rw" without the double quotes. Hit apply changes. So now you have two partitions, the fat32 partition and the ext4 partition called casper-rw. This partition can be of any size and will be responsible for saving your data between boots. You can now boot using the usb drive and any changes you make will remain.

Live USB creator (GUI-based)

WARNING: Does NOT create persistent installs on Hardy (8.04 LTS) or earlier; works only with Intrepid 8.10.

Live USB creator automates the process of creating a bootable Live USB system from a running Ubuntu Live CD. Simply run the Live CD, install the tool and start the Live USB installation from the System administration menu.

https://launchpad.net/liveusb -- probono

(A better link: https://launchpad.net/liveusb/+announcements which explains that you run the livecd and the you click on the link: http://ppa.launchpad.net/probono/ubuntu/pool/main/l/liveusb/)

{http://klik.atekon.de/liveusb/screenshot.png}

If you can't start the Live USB system from a running Ubuntu Live CD (perhaps you lack a functioning CD burner), you can actually just install liveusb to your normal system with the Ubuntu Live CD just mounted. Mount the image using the command

sudo mount -o loop /path/to/cd-image /media/cdrom0

After running the liveusb command and installing to your USB key, unmount the image with

sudo umount /media/cdrom0

Method 1: Installing Ubuntu directly to USB drive from installer CD

You can directly install Ubuntu 8.04 Hardy Heron to a USB drive using the Live CD. Simply select the USB drive as the installation target instead of the local hard disk.

Note: This will use the USB drive for /tmp, which will cause extra wear on the flash memory. If you're booting from a system with enough RAM, it would be more desirable to use a tmpfs in RAM for /tmp, in which case you'd want to copy the ISO CD image to the USB drive and add a persistent partition (see next section). On the other hand, if you're not concerned with your USB drive wearing out (lifetime warranty, wear leveling, etc), continue in this section.

Ensure in the "Installation Summary" screen that you choose to install GRUB to the USB key stick, and not the computer's hard disk (click the Advanced button to do so). Choose to install GRUB to the first USB partition (i.e. /dev/sdb1, rather than simply /dev/sdb). Failure to do this will cause the GRUB on your hard disk to be changed and render the system unbootable from the hard disk, requiring you to boot from a CD and reinstall GRUB to the hard disk (possibly requiring a chroot to the hard disk filesystem first).

You will also need to manually edit the menu.lst file of the new USB installation to change the boot references to /dev/sda, rather than /dev/sdb (or /dev/sdc etc.). This can be done by booting to the live distro mode of the Ubuntu install CD and editing the /boot/grub/menu.lst file on the USB stick. You can mount the USB stick using the Places menu -- once mounted, it can be found at /media/disk. Note: This step may not always be necessary.

Note: There is a bug with the Ubuntu 8.04 install CD that means USB key stick installs are screwed -- the desktop won't appear when you login. To get around this, you must do the following when you boot for the first time (before logging in at GDM):

1) switch to a virtual console (Ctrl+Alt+F2)

2) kill the X-server (sudo killall gdm)

3) empty the /tmp folder (sudo rm -rf /tmp/*)

4) Type startx, and perform a system update when the desktop appears (if you don't want to install a lot of software, just update the gnome-keyring package(s) -- that's the one that causes the problem)

Note that this should be fixed in the Ubuntu 8.04.1 install CD.

Method 2: hiding the ISO image in a partition in the USB drive

If you'd like to understand how the process works, the page A better way to create a customized Ubuntu Live USB drive has instructions to build a bootable, persistent USB drive with Linux.

These instructions have been tested to work correctly with Ubuntu Intrepid Ibex (8.10), and should work correctly with any distribution that uses Casper and supports persistency.

Method 3: Copying the ISO CD image to the USB drive

Preparing the USB drive

8.04 Hardy: Unfortunately, there is a bug in the versions of casper in Hardy that cause the persistent partition to not be mounted on boot. There is a workaround available, and you can download a replacement initrd.gz for 8.04.1 (place in casper directory on first partition of USB key).

Good news! It IS possible to make Feisty persistent! These instructions are needed but not sufficient. Check thishttp://www.pendrivelinux.com/2007/09/20/how-to-make-ubuntu-704-casper-persistent/. Essentially, you need to decompress initr.gz (with gzip and cpio); edit the init file adding a case called 'persistent' (see details at the link) and recreate initr.gz. I guess that without this case, the 'persistent' passed in the syslinux.cfg is simply ignored. I got persistence at the first attempt. Elfantin

Making partitions

Caution: Be careful using any disk utility to partition or format dives as a small error could damage your operating system or overwrite a whole partition of files. Remove any external drives, cameras or other storage devices connected to your computer (except for the USB drive you wish to repartition). Get familiar with the difference between 1 KB, 1 MB and 1 GB; as well as the difference between a drive (e.g. /dev/sda) and a partition (e.g. /dev/sda2). Get familiar with the drives and partitions on your computer: What are the sizes? Which is root, '/'? Which is the USB device?

Use 'disk utility' or 'gparted' to unmount the USB device, and then to delete any existing partition(s). Create a 750 MB FAT partition named 'ubuntu' (or whatever); then an ext2 partition named 'casper-rw' (exactly) on the remaining space. Select the 750 MB ubuntu partition, click "edit partition" and check "bootable". If you were successful, skip down to #Installing Ubuntu on the USB drive. If you prefer to work with 'fdisk' on the command line, keep reading below.

The preparation of the drive is explained below using 'fdisk'. You could use 'gparted' or 'disk utility' as well.

  • However I had errors with 'gparted' and I could not give the partitions a volume name. I tested 'qtparted' as well and it worked fine.

    Another issue in my case was that 'fdisk' recognised a fat32 filesystem as linux. So I checked it with gparted and it was OK.

Plug in the drive and check its device name:

mount

Assuming you have your Ubuntu set up to automatically mount your USB stick, this should show you what /media/drive or whatever it's called corresponds to on the device level.

Alternatively, you could run

sudo fdisk -l

but if you have multiple devices on your system, it will print a fair amount of fairly technical information.

We are going to suppose that its name is /dev/sdX where X is the disk device such as /dev/sda or /dev/sdc. Please be sure to substitute the correct letter for X which matches the device name you find for your pen drive. Double check it! [Note: on newer computers, which use serial ATA disks, /dev/sda is typically the main hard drive; do not overwrite this!]

Note: on some usb-sticks fdisk says "Note: sector size is 2048 (not 512)", in which case you may very well be out of luck trying to boot from it, see mailing list thread: Problem with 2GB USB Pendrive

Now we are going to create 2 partitions: 1 partition of 750 MB with a fat32 filesystem and 1 partition with the rest of the drive space with volume name "casper-rw" and ext2 filesystem. The first partition will be made active.

Open 'terminal' and unmount the USB drive (replace 'sdX1' with the appropriate partition name):

sudo umount /dev/sdX1

Fire up 'fdisk' for the drive:

sudo fdisk /dev/sdX

This will give you the fdisk prompt. Look to what you have on the drive. Check if you have to backup the data you have on it. 'p' will print the content of /dev/sdX. If you have partitions on it remove them ('d', 'partition number').

Make partition 1:

1. 'n' for new partition

2. 'p' to make it a primary partition

3. '1' to call it partition number 1

4. Then just press enter to accept the proposed starting cylinder

5. '+750M' to make its size 750 MB

6. Then 'a' to make it the active partition

Set the file system of partition 1 to FAT:

1. 't'

2. then '1'

3. then '6'

  • (I already had partition 1 selected so for me it was just 't' then '6' -Jordan_U)

    there seems to be an incongruity: when you change the filesystem to FAT using option "t" the filesystem option "6" is FAT16. w95/fat32 is option "b". Which file system needs to be used? -rebelcat1

Make partition 2:

1. 'n' for new partition

2. 'p' to make it a primary partition

3. '2' to call it partition 2

4. then just press enter to accept the proposed starting cylinder

5. then press enter to accept the proposed ending cylinder

6. Save and quit fdisk with 'w' to write the new settings.

  • I had an issue with this that every time I saved my partition setup using 'w', I'd get:

      WARNING: Re-reading the partition table failed with error22: Invalid argument.
      The kernel still uses old table.
      The new table will be available at the next reboot.
    • If this happens, and then checking with 'sudo fdisk -l' doesn't show the new partitions - here's a fix if you have a Windows OS, though I don't know why it works:

      Do nothing else with the drive. Insert into Windows (mine was XP) and format with Disk Management and use FAT32. Now, 'sudo fdisk -l' should see the two partitions under the drive. -neverard

      • I had the same error, using gparted instead of fdisk worked for me -Jordan_U

Check the result:

sudo fdisk -l

You should see the 2 partitions with the first marked with a * because it is active.

If ubuntu mounted the partitions again you should unmount them:

sudo umount /dev/sdX1
sudo umount /dev/sdX2
  • make sure (via fdisk -l) you created a w95/fat and not a linux partition, otherwise i was unable to boot from it!! (i had to use gparted to achieve this) - bernstein

    • fdisk worked for me however - booted off CD - krishnan

Alternate partition layout

Please note that Windows will only mount the first partition of any removable media - which includes USB flash drives. While you can get around this, it requires some highly kludgy driver procedures, which you are unlikely to be able to pull off on any machine where you are not an admin.

In short, having the Ubuntu Live as your first partition reduces the utility of your USB stick for what is statistically it's most likely task - transferring files to and from Windows machines.

Partition 1 : FAT32, full size of stick minus 750M
Partition 2 : FAT16, 750M  (FAT16 because older versions of syslinux don't like FAT32)

Follow the instructions, but use /dev/sdX2 instead of /dev/sdX1, and make sure you make /dev/sdX2 bootable in fdisk.

For persistence, follow the instructions to create a loopback file at LiveCDPersistence. This feature works fine from a loopback file inside a FAT32 filesystem, just as long as the file contains a supported unionfs filesystem like ext2.

Now you have (mostly) the best of both worlds.

  • You can transfer files between Windows machines on the FAT32 partition
  • You have a persistent Ubuntu thumb
  • You can mount the FAT32 partition from a persistent Ubuntu boot (manually)
  • You can enlarge or shrink your casper-rw partition without having to repartition your thumb, just make a new loopback filesystem, mount them both, and copy the files across.

If the persistent boot automatically mounted the root of the FAT32 filesystem as well as the casper-rw filesystem, it would be ideal.

Formatting the partitions

We will now format the partitions by putting a filesystem on and giving them the name 'ubuntu' (or any other name you want) and 'casper-rw' (this name is MANDATORY, do not change other names and do not use capital letters):

sudo mkfs.vfat -F 32 -n ubuntu /dev/sdX1
sudo mkfs.ext2 -b 4096 -L casper-rw /dev/sdX2

Mount the partitions on the drive. Take out the drive and put it back. Ubuntu Dapper or Edgy will mount the drive automatically if you have checked this option under System -->Preferences--> Removable media. Otherwise use 'mount':

sudo mount /dev/sdX1 /media/mountpointyouhave1
sudo mount /dev/sdX2 /media/mountpointyouhave2

On recent Ubuntu versions, the USB stick's partitions should simply appear under /media/ubuntu and /media/casper-rw if you have followed the proposed naming convention.

Installing Ubuntu on the USB drive

Download the Ubuntu image (for example, ubuntu-11.04-desktop-i386.iso) or put in an Ubuntu install CD if you have it.

If you use the downloaded image you can mount it to make it accessible as follows, using 'terminal' (supposing that the iso image is in the current directory):

mkdir ubuntuCD
sudo mount ubuntu-11.04-desktop-i386.iso ubuntuCD -o loop

You can now access the files via the 'ubuntuCD' folder.

Open the CD's top-level folder and make sure that you see the hidden files too. (verify that View-->Show Hidden Files is checked).

Copy the following folders and files to the 750 MB partition of your USB drive:

  • Copy folders: '.disk', 'casper', 'dists', 'install', 'pics', 'pool' and 'preseed' (skip the 'boot' folder);
  • Copy the folder 'isolinux' to the drive and rename it to 'syslinux';
  • Copy the file 'README.diskdefines', and optionally, the 'usb-creator.exe' and 'wubi.exe' files (skip the 'autorun.inf' and 'md5sum.txt' files);
  • Rename the file 'syslinux/isolinux.cfg' to 'syslinux/syslinux.cfg' on the USB drive by right clicking on it and selecting 'rename';
  • Rename the file 'syslinux/isolinux.bin' to 'syslinux/syslinux.bin'.

Alternately, you can run the following commands in 'terminal'. If you copy/paste, take care to make your browser window large enough to not have accidental line breaks inserted. And remember to replace /media/ubuntu with /media/whatmountpointyouhave1 if you used a different name for the mount point.

Add the -v option to cp to get some progress indication. The casper/filesystem.squashfs file in particular is large, and takes a long time to copy.

cd ubuntuCD
cp -rf casper dists install pics pool preseed .disk /media/ubuntu
cp -rf isolinux /media/ubuntu/syslinux
cd /media/ubuntu/syslinux
mv isolinux.cfg syslinux.cfg
mv isolinux.bin syslinux.bin

The FAT32 file system will not allow symbolic links to be copied over. You will get a warning about this, but it is harmless.

Unmount the iso image that you mounted above, using 'terminal'.

sudo umount ubuntuCD

Making the drive bootable

We are going to install the linux bootloader 'syslinux'. This bootloader gets its menu from 'syslinux/txt.cfg'. We will modify this file. Open 'syslinux/txt.cfg' from the USB drive with your favorite text editor. For instance:

cd /media/ubuntu/syslinux
gedit txt.cfg

The following edits need to be made:

  • Search and replace '/cdrom' with nothing;
  • Copy the first 'label' section, paste it in before itself, and make the following edits to this new section:
    • The 'label' argument should be changed to something unique, here we use 'persistent';
    • The 'menu label' should be changed to describe the option; '^Use Ubuntu in persistent mode' would seem suitable, with a caret before the "U" to make it a shortcut key for this option;
    • The word 'persistent' should be added into the 'append' line (this is the crucial point!);
  • Optionally, change the 'default' to the label name used above (e.g. 'persistent').

The following is an example of what you might end up with:

default persistent
label persistent
  menu label ^Use Ubuntu in persistent mode
  kernel /casper/vmlinuz
  append  file=/preseed/ubuntu.seed boot=casper persistent initrd=/casper/initrd.lz quiet splash --
label live
  menu label ^Try Ubuntu without installing
  kernel /casper/vmlinuz
  append  file=/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash --
label live-install
  menu label ^Install Ubuntu
  kernel /casper/vmlinuz
  append  file=/preseed/ubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd.lz quiet splash --
label check
  menu label ^Check disc for defects
  kernel /casper/vmlinuz
  append  boot=casper integrity-check initrd=/casper/initrd.lz quiet splash --
label memtest
  menu label Test ^memory
  kernel /install/mt86plus
label hd
  menu label ^Boot from first hard disk
  localboot 0x80

The menu choice called 'persistent' was made the default so that when booting up you can just hit 'Enter' to start your customized session.

Install bootloader

The last thing to do is install the bootloader. Make sure you have the 'syslinux' and 'mtools' packages installed. If not, open 'synaptic' and select them from the package list to mark them to be installed, then "apply" the changes.

Or use 'aptitude' or 'apt-get' from the command line. For example, the following command should be harmless if they are already installed.

sudo aptitude install syslinux mtools

First you need to unmount your usb stick using 'disk utility', or use 'terminal' to enter the following commands (replacing 'sdX1' with the appropriate partition name for the 750 MB ubuntu partition on your USB device):

cd ~
sudo umount /dev/sdX1

This command will install the bootloader on your drive:

syslinux /dev/sdX1
  • don't know why, but i had to use the -f switch, (syslinux -f /dev/sdc1) - bernstein

    • same here - I had to use the -f switch - krishnan

    syslinux complained it couldn't create LDLINUX.SYS, but it worked in the Windows version (see below) - JanSchlüter

    According to this page1 syslinux 3.35 should be used to get support for fat32, edgy ships with 3.11. According to the changelog 3.35 only seems to introduce support for subdirectories.

If you get the error:

sh: mcopy: command not found
syslinux: failed to create ldlinux.sys

then you will need to install the 'mtools' package.

Eject the drive:

eject /dev/sdX

Boot on the USB drive, change some settings, reboot again and check if the changes are kept (persistence check).

Do not forget to check if the computer you are going to use, boots USB devices first (look in BIOS settings).

So that is it. Enjoy (k)ubuntu where ever you go.

  • If you boot the drive and persistency works but when you log in to gnome you get a message saying that it couldn't write to .ICEauthority, then a simple fix is deleting .ICEauthority. You can automate that by doing this:

      echo >> .bashrc
      echo "# This makes GNOME work" >> .bashrc
      echo "rm .ICEauthority 1>/dev/null 2>/dev/null" >> .bashrc

Those using Lucid (10.04) to make a pen drive to boot Precise (12.04) that is to say, using the previous LTS release to go to the next one, will need to be aware of this incompatibility between the syslinux versions involved:

https://bugs.launchpad.net/ubuntu/+source/syslinux/+bug/608382

there are a couple of work-arounds (eg, typing 'help' at the prompt and then hitting 'enter') but the bug has been triaged and labeled WONTFIX since Maverick and as late as March 2012.

Installing Ubuntu on USB drive using Windows

UNetbootin (GUI-based, runs from either Windows or Linux)

UNetbootin automates this task by providing a GUI to create a bootable Ubuntu Live USB drive from an ISO file, and can be run from both an installed Windows or Linux system, or from a liveCD.

http://sourceforge.net/dbimage.php?id=294729

Preparing the USB drive

TODO This is not updated for Gutsy

Download a copy of the HP format utility for USB drives, this utility makes it as easy to format USB pen drives as it is to format floppies.

Don't bother wasting your time with this HP utility - it is rather useless. You can format the entire drive as FAT32 using the built in windows format (right click on the drive and select format, make sure to select FAT32 as the FS type). I found no way to partition the drive in windows, not even with PowerQuest's Partition Magic (which usually does everything you could want). Either boot off an ubuntu CD/DVD and follow the linux instructions, or if you can't do that, simply follow these instructions but use the whole flash drive for the live CD, then once you have booted from it, you can repartition and make the ext2 volume from within ubuntu itself. I simply pulled the flash drive out and re-inserted it - this ensures ubuntu is no longer using it. Not sure what the risks are - I didn't have any troubles, but perhaps you should do this at your own risk (or maybe somebody knows a safer way). If somebody knows a free utility which can partition a flash drive in winxp, please put it here!!! - mrwolf

Plug in your USB pen drive and use the HP format utility to format it with a FAT32 filesystem.

Using a partitioning tool, create two partitions. The first is formatted with a FAT32 filesystem and needs to be 750 MB. The second should occupy the remaining free space and should be formatted with the ext2 filesystem and is given the name "casper-rw". Note! Most DOS partitioning tools will create the partition name in uppercase (CASPER-RW). Since Linux is case-sensitive you need to do the formatting of the second partition in Linux. The persistent feature will not work if the partition name is in uppercase. See the Wiki for details. https://help.ubuntu.com/community/LiveCDPersistence

Installing Dapper or Edgy on the USB drive

This is the same as described in the Linux section except for accessing the downloaded image. The way to do this is to mount the iso image file and copy the files that way. You can do this with NERO or Windows VirtualCD. You might want to do it this way if you don't want to burn a CD.

Making the drive bootable

Go to http://syslinux.zytor.com/iso.php and download a copy of syslinux-3.11.zip for Windows. Extract the zip file contents and move the extracted folder to your favorite location on your hard drive.

Open WordPad and edit the file syslinux.cfg as described in the Linux section.

Open a command prompt and change directory to the location of the syslinux folder. For example, if you placed the folder on your desktop then: cd C:\Documents and Settings\(your user name)\Desktop\syslinux-3.11\win32 (by the way you DO know that command prompt has command completion just like in Linux (start entering characters and then press the TAB key to complete the entry)).

Next write the bootsectors to the flash drive by entering the following command:

syslinux -maf X:
  • where X: is replaced by the drive letter of your USB key. Be careful to pick the correct drive letter!
  • This will write the Master Boot Record (MBR), as well as mark the partition active.

See also


CategoryCleanup CategoryLive CategoryUsb CategoryBootAndPartition CategoryBootAndPartition

LiveUsbPendrivePersistent (last edited 2017-04-30 18:13:47 by es20490446e)