Create *ubuntu LIVE-USB from the command line

Thursday, 14. November 2013

You can hack usb-creator to do this.  (special thx to  Jay _silly_evarlast_ Wren who wrote about this at askubuntu.com)

You should already have a single vfat partition as partition 1 on the usb device and it should be marked bootable.

You could do this with a simple shellscript:

SDX="/dev/sdb"
sudo sfdisk -R $SDX
sudo sfdisk $SDX -D -uM << EOF
,4000
,2400
,;
EOF
sleep 4
sudo sfdisk $SDX -A 2
sudo sfdisk --id $SDX 2 b
sudo sfdisk -R $SDX
sudo mkfs.vfat -F 32 -n winshare ${SDX}1
sudo mkfs.vfat -F 32 -n system ${SDX}2
sudo mkfs.ext4 -L casper-rw ${SDX}3
sleep 1
sudo sfdisk -R $SDX

(this would create 3 partitions on sdb (winshare/system/casper-rw) casper-rw would come in place if you chose to add persistent to the syslinux.cfg file and store all the changes and  “system” would be the bootable installation target (sdb2) – winshare speaks for itself)

Next, we will get usb-creator python code to assist us. (we need bzr to get the sourcecode)

$ sudo apt-get install bzr

then…

$ bzr branch lp:usb-creator

create a file with this content and name it usb-creator-cli, place this file in the usb-creator directory (root of bzr branch)

#!/usr/bin/env python
from __future__ import print_function
from usbcreator.misc import sane_path, setup_gettext, setup_logging, text_type

from usbcreator.install import install

sane_path()
setup_logging()
setup_gettext()

#/dev/sdb1 should be mounted on /mnt
#iso should be mounted to /iso

dev = '/dev/sdb2' source = '/iso' target = '/mnt' ugh = install(source, target, False, device=dev) ugh.success = print ugh.failure = print ugh.progress = print ugh.progress_message = print ugh.progress_pulse = print ugh.progress_pulse_stop = print ugh.retry = print ugh.run()

Make it executeable

$ chmod +x usb-creator-cli

Now mount your iso to /iso and mount your usb device to /mnt

$ sudo mkdir /iso ; sudo mount ubuntu-server-12.10-amd64.iso /iso
$ sudo mount /dev/sdb1 /mnt

If you want very verbose messages at your console you can tail ~/.cache/usb-creator.log

$ tail -f ~/.cache/usb-creator.log &

Now run that usb-creator-cli script

$ sudo ./usb-creator-cli

And watch all the messages scroll by.

When you return to the prompt, don’t forget to unmount /mnt before you yank your usb storage device.

 

 

Comments are closed.