Saturday 7 July 2007

How to create an Ubuntu UsbLive with persistence

First step is downloading Ubuntu Dapper iso file:

NOTE: Newer versions(Feisty and Gutsy), by now, july 2007, have a bug that prevents to use persistence feature.

You can navigate to Ubuntu download page and select Ubuntu 6.06 LTS Desktop edition (alias Dapper),

or simply enter at console command line:
$wget http://releases.ubuntu.com/dapper/ubuntu-6.06.1-desktop-i386.iso


I recommend a usb pendrive with a capacity higher than 1 Gigabyte, because you will need at least 700 megabytes to copy dapper iso file on it.
In my case I use a 2G pendrive.


Connect the usb pendrive so it be detected.

$dmesg command will show something like:

[ 2697.454838] usb-storage: device found at 4
...
[ 2704.387453] SCSI device sdh: 4029440 512-byte hdwr sectors (2063 MB)


$fdisk -l also shows the new device.

If you still dont find it, you can seek for it at $cat /proc/bus/usb/devices output.


On my system the new device appears as /dev/sdh, in this tutorial, to be more general, I will write it as /dev/sdX.


Next step will be partitionating our usb pendrive: (choose the program you prefer: fdisk, cfdisk, gparted ...)

#fdisk /dev/sdX

(for help on this step read $man fdisk)


I partitionate the device into two partitions sdX1 and sdX2, both sized one gigabyte, and make bootable the first one, showing this result with fdisk:

DeviceActiveBeginningEndBlocksIdSystem
/dev/sdX1*1493978081bW95 FAT32
/dev/sdX24941015103564883Linux





Umount both partitions if they are mounted and then format them with:

#mkfs.vfat -F 32 -n usb /dev/sdX1
#mkfs.ext3 -L casper-rw -b 4096 /dev/sdX2

NOTE: casper-rw label is important, do not change it.


Mount dapper iso file in your harddisk:
#mkdir dapper_directory
#mount -o loop ubuntu-6.06.1-desktop-i386.iso dapper_directory



Copy iso files to first usb pendrive partition:
#mount /dev/sdX1 /media/foo
#cd dapper_directory
#cp -dpR . /media/foo



Installing grub bootloader:

#grub-install --root-directory=/media/foo /dev/sdX

this does not install menu.lst file so we will create it manually:
$sudo gedit /media/foo/boot/grub/menu.lst


Howto change isolinux.cfg entries (/media/foo/isolinux/isolinux.cfg) into menu.lst format:

E.g: isolinux.cfg entry

LABEL live
menu label ^Start or install Ubuntu
kernel /casper/vmlinuz
append boot=casper initrd=/casper/initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --


changes into: (menu.lst entry)

title Start or install Ubuntu
root (hd0,0)
<---------------- this is necessary to identify usb device at boot. kernel /casper/vmlinuz boot=casper initrd=/casper/initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash
initrd /casper/initrd.gz
boot


NOTE: If you have problems creating menu.lst file, copy the one that appears at the end of this article.

Now you have written a correct menu.lst file at /media/foo/boot/grub directory exec again:
#grub-install --root-directory=/media/foo /dev/sdX

NOTE: If grub gives this error message "/dev/sdX does not have any corresponding BIOS drive"
execute this command:
#grub-install --root-directory=/media/foo --recheck /dev/sdX


NOTE: to be able to run your usb pendrive from qemu you have to trick the emulator giving a usb dapper iso as a cdrom device e.g:
#qemu -hda /dev/sdX -cdrom ubuntu-6.06.1-desktop-i386.iso -boot c


If you want to restart your computer to probe your creation, run:
#eject /dev/sdX

NOTE: eject /dev/sdX umounts sdX partitions and deletes /dev/sdX, /dev/sdX1,... devices

Restart and boot from your usb pendrive.


Have fun!!


APPENDIX: Example of menu.lst file

NOTE: persistent tag at first kernel line enables persistence mode in our usb pendrive.

timeout         10

color cyan/blue white/blue


title           Start Ubuntu in Persistent mode
root            (hd0,0)
kernel          /casper/vmlinuz boot=casper initrd=/casper/initrd.gz ramdisk_size=1048576 root=/dev/ram rw persistent
initrd          /casper/initrd.gz
boot

title           Live - Start or install Ubuntu
root            (hd0,0)
kernel          /casper/vmlinuz boot=casper initrd=/casper/initrd.gz ramdisk_size=1048576 root=/dev/ram rw
initrd          /casper/initrd.gz
boot

title           Start Ubuntu in safe graphics mode
root            (hd0,0)
kernel          /casper/vmlinuz boot=casper xforcevesa initrd=/casper/initrd.gz ramdisk_size=1048576 root=/dev/ram rw
initrd          /casper/initrd.gz
boot

title           Check CD for defects
root            (hd0,0)
kernel          /casper/vmlinuz boot=casper integrity-check initrd=/casper/initrd.gz ramdisk_size=1048576 root=/dev/ram rw
initrd          /casper/initrd.gz
boot

title           Memory test
root            (hd0,0)
kernel          /install/mt86plus
boot



This article is based on this excelent spanish one extracted from Daniel Perella's Blog.

1 comentarios:

Anonymous said...

Great how-to!!!

thanks!