Main »

Computers-software-os-US Bpersistence Boot

Main > Computers > software > os > USBpersistenceBoot

install ubuntu to usb drive with persistence

taken/gotten from many places on the internet, thank you all.

16G usb flash

  • fdisk -l ... get dev for usb, mine was sdb
  • fdisk /dev/sdb
  • 8G /dev/sdb1 first primary partition as 'c' fat32 boot and backtrack5 3G
  • 730M /dev/sdb2 second primary partition '83' linux cd iso
  • 7G /dev/sdb3 fifth partition, ie rest '83' linux persistence and file storage.

mark the first partition "boot"

  • unplug replug the usb if sdb1 is not mounted.

format drive partitions

  • sudo mkfs.msdos -I -F 32 /dev/sdb1

no formating of sdb2 as we'll dd to it.

  • sudo mkfs -t ext4 /dev/sdb3

put a label on it

  • mlabel -i /dev/sdb1 ::

I chose

  • UBUNTU-1204
  • sudo e2label /dev/sdb5 ubuntu-stor
  • umount /dev/sdb1

remove, reinsert usb to have label recognized and mounted with those names.

verify you are using grub2

  • grub --version ... 0.97 and below is old grub, grub 1.99 is grub2


  • grub-install --version ... 1.99 for grub2

if not like I was not on my 12.04 laptop, it was using the old grub.
make sure the usb is mounted, ie unplug re plug if not.
it's important that the usb is mounted or the qemu will not be able to use it. find out the manf:product code of the usb

  • lsusb

my case: Bus 001 Device 004: ID 0781:5571 SanDisk Corp.
start a qemu up using the 12.04 install iso

  • qemu-system-i386 -usb -usbdevice host:0781:5571 /home/me/temp/web-dnloads/ubuntu-12.04.1-desktop-i386.iso

if the ubuntu 12.04 kvm doesn't see the usb

  • ctrl-alt-2 in the vm ctrl-alt-1 gets you back to the gui

gives gemu prompt

  • info usb

if not shown, add it

  • usb_add host:0781:5571

other handy qemu cmds: info usbhost, usb_del 0.3 (the 0.3 came from info usbhost)
then check that the qemu 12.04 can see the usb in the vm via

  • fdisk -l

so from the qemu or from your system where you have 12.04/grub2:
install grub on usb

  • grub-install --no-floppy --root-directory=/media/UBUNTU-1204 /dev/sdb
  • vi /media/UBUNTU-1204/boot/grub/

needs to look like:

  • (hd0) /dev/sdb

then re run

  • grub-install --no-floppy --root-directory=/media/UBUNTU-1204 /dev/sdb

remove it from the qemu if used. umount, ctrl-alt-2, info usb, usb_del 0.x
at this stage I mounted the usb on my laptop if it didn't automount being removed from the qemu to check that grub was installed and boot, see "test" below to do this via qemu.

  • shows grub> prompt and version installed on usb, 1.9x looks good.

via the laptop, put casper files on usb

  • mkdir /media/iso
  • mount -o loop /home/me/temp/web-dnloads/ubuntu-12.04.1-desktop-i386.iso /media/iso
  • cp /media/iso/casper/vmlinuz /media/UBUNTU-1204/boot/
  • cp /media/iso/casper/initrd.lz /media/UBUNTU-1204/boot/
  • umount /media/iso

install ubuntu boot cd to 2nd partition, ie 730M, dd_rescue shows us stats.

  • dd_rescue -v /home/me/temp/web-dnloads/ubuntu-12.04.1-desktop-i386.iso /dev/sdb2
  • mkdir /media/UBUNTU-1204/boot/bt5
  • mount -o loop /home/me/temp/web-dnloads/BT5R3-GNOME-32.iso /media/iso
  • cp -Rv /media/iso/* /media/UBUNTU-1204/boot/bt5
  • umount /media/iso

set up persistence, this should be all remaining space on the first partition

  • df -h /dev/sdb1

for me it had 5G free so I set count below to: 4300 fat32 has a file limit of 4.3GB

  • dd if=/dev/zero of=/media/UBUNTU-1204/casper-rw bs=1M count=4300
  • mkfs.ext4 -F /media/UBUNTU-1204/casper-rw

setup grub and grub.cfg

  • vi /media/UBUNTU-1204/boot/grub/grub.cfg
    set default=0
    set timeout=5
    menuentry "Ubuntu Persistent 12.04" {
    search --set -f /boot/vmlinuz
    linux /boot/vmlinuz boot=casper file=/preseed/distro.seed quiet splash noprompt -- persistent
    initrd /boot/initrd.lz
    menuentry "BackTrack 5" {
    set gfxpayload=1024x768x16
    linux /boot/BT5/casper/vmlinuz boot=casper live-media-path=/boot/BT5/casper/ text splash
    initrd /boot/BT5/casper/initrd.gz

done, test it by booting a computer from your new usb or via the vm test below.

test your usb boot via qemu virtual machine

before this works you have to install qemu.
/dev/sdb is my usb

  • qemu-system-i386 /dev/sdb


  • to use the persistence create a new user.
    • system settings, user accounts, +, administrator, set passwd now, logout, login as new user.
  • change the background, theme, add chromium, reboot and see if it stays.
    • cd Pictures; scp*.png .
  • install avast! antivirus so we can scan windows boxes off their boot disk.
    • sites)
    • registration code: C23686155H1200A0512-Z3E8KMWK
    • after updating the sig db, you'll get an error 'invalid argument'
      • sudo vi /etc/rc.local
      • sudo sysctl -w kernel.shmmax=67108864

top level subjects:

Page last modified on August 29, 2012