Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a bootable USB image to install Ubuntu on a new computer.

I have done this before following the "create USB drive" instructions for Ubuntu desktop, but I don't have an Ubuntu desktop available.

How can I do the same using only the command line?

Things I've tried:

  • Create bootable USB on Mac OS X following the "create USB drive" instructions for Mac: Doesn't boot.
  • usb-creator: According to apt-cache search usb-creator and Wikipedia usb-creator only exists as a graphical tool.
  • "Create manually" instructions at None of the files and directories described (e.g. casper, filesystem.manifest, menu.lst) exist in the ISO image, and I don't know what has replaced them.
  • unetbootin scripting: Requires X server (graphics support) to run, even when fully scripted. (The command sudo unetbootin lang=en method=diskimage isofile=~/ubuntu-10.10-server-amd64.iso installtype=USB targetdrive=/dev/sdg1 autoinstall=yes gives an error message unetbootin: cannot connect to X server.)


Also tried GRUB fiddling: Merging information from

I was able to get halfway there - it booted from USB, displayed the grub menu and started the installation, but the installation did not complete.

For reference, this is the closest I got:

sudo su
  # mount USB pen
mount /dev/sd[X]1 /media/usb
  # install GRUB
grub-install --force --no-floppy --root-directory=/media/usb /dev/sd[X]
  # copy ISO image to USB
cp ~/ubuntu-10.10-server-amd64.iso /media/usb
  # mount ISO image, copy existing grub.cfg
mount ~/ubuntu-10.10-server-amd64.iso /media/iso/ -o loop
cp /media/iso/boot/grub/grub.cfg /media/usb/boot/grub/

I then edited /media/usb/boot/grub.cfg to add an .iso loopback, example grub entry:

menuentry "Install Ubuntu Server" {
  set gfxpayload=keep
  loopback loop /ubuntu-10.10-server-amd64.iso  
  linux (loop)/install/vmlinuz  file=(loop)/preseed/ubuntu-server.seed iso-scan/filename=/ubuntu-10.10-server-amd64.iso quiet --
  initrd (loop)/install/initrd.gz

When booting from USB, this would give me the Grub boot menu and start the installer, but the installer gave up after a couple of screens complaining that it couldn't find the CD-ROM drive. (Naturally, as the box I'm installing on doesn't have an optical drive.)

I resolved this particular issue by giving up and doing the "create USB drive" routine using the Ubuntu Live desktop CD (on a computer that does have an optical drive), then the USB install works.

But I expect that there is some way to do this from the command line of an Ubuntu system without X server and without an optical drive, so the question still stands.

Does anyone know how?

share|improve this question
try unetbootin. – RolandiXor Jan 13 '11 at 1:33
@Roland unetbootin: cannot connect to X server - seems to require X even when fully scripted (unetbootin lang=en method=diskimage isofile=/srv/share/ubuntu-10.10-server-amd64.iso installtype=USB targetdrive=/dev/sdg1 autoinstall=yes), and I'd prefer to remain headless. Thanks for the tip, though; I may install X if I run out of other options. – j-g-faustus Jan 13 '11 at 2:02
These look promising: and… Needs some tweaking, but will try it out. – j-g-faustus Jan 13 '11 at 4:06
@j-g-faustus : If things were so complicated, i would've abondoned linux, maybe. use dd. Its a gem. cant say enough. And every linux distro has dd; so you have a universal solution, with nothing to script/write/configure. just one beautiful line. – Mahesh May 26 '12 at 18:50
That grub.cfg entry needs to say file=/cdrom/preseed/ubuntu-server.seed on the linux line (and not file=(loop)/preseed/ubuntu-server.seed), to avoid a fatal 'Failed to retrieve the preconfiguration file' error once the CD image has successfully been detected. – Paul Whittaker Apr 30 '14 at 14:49
up vote 9 down vote accepted

When booting from USB, this would give me the Grub boot menu and start the installer, but the installer gave up after a couple of screens complaining that it couldn't find the CD-ROM drive.

This is a known bug with ubuntu server iso (desktop iso works just fine), but there is a fix to get the packages from the iso on the usb drive: once on the installer, Ctrl+Alt+f2 to open a tty and in the terminal:

mount -t vfat /dev/sdX1 /mnt
ln -sf /mnt/ubuntu-server.iso /dev/sr0

Then switch back to installer and retry to scan cd for packages. It should work.

share|improve this answer
I don't have a system to try it out on at the moment, but yeah - it sounds like it should work :) Thanks! – j-g-faustus Mar 26 '11 at 16:33
I found that the "Detect and mount CD-ROM" menu option would revert /dev/sr0, undoing the ln and returning it to its original (broken) state. However, if I waited at the "Retry mounting the CD-ROM?" prompt, did the ln in tty2, and then returned to press "Yes", it did work. (That "Retry?" dialog would only appear once the mount command had been given, though.) – Paul Whittaker Apr 30 '14 at 14:46

Have you tried with # dd if=path/to/image.iso of=/dev/sd# ?

share|improve this answer
This one is a gem. The best one. works on any linux distro. but you need to be extra careful. adding bs=20M or any other suitable value speeds things up. for details, refer man dd – Mahesh May 26 '12 at 18:47
@Mahesh No, some linux distro do not work even with this command, One of them is OpenSUSE – Anwar Shah Oct 8 '12 at 17:56
or MeeGo and derivates those images are called hybrid ones – rzr Nov 17 '13 at 17:31

Let us assume you have nothing but a prompt before you. If you have a GUI, you can open a terminal and do everything described here. Or you may use a tty.

To avoid potential damage, follow the instructions very very carefully.

  • Switch to a root prompt by typing sudo su

    Detect what device the usb is.

  • tail -f /var/log/syslog

You are now having a live view at syslog. Plug in your usb drive. You should see some messages on screen. Something like this.

May 27 00:35:07 Mahesh kernel: [ 5054.646585] usb 2-1.1: new high-speed USB device number 5 using ehci_hcd
May 27 00:35:07 Mahesh kernel: [ 5054.741437] scsi8 : usb-storage 2-1.1:1.0
May 27 00:35:07 Mahesh mtp-probe: checking bus 2, device 5: "/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1"
May 27 00:35:07 Mahesh mtp-probe: bus: 2, device: 5 was not an MTP device
May 27 00:35:08 Mahesh kernel: [ 5055.739177] scsi 8:0:0:0: Direct-Access     JetFlash TS2GJFV30        8.07 PQ: 0 ANSI: 2
May 27 00:35:08 Mahesh kernel: [ 5055.740198] sd 8:0:0:0: Attached scsi generic sg3 type 0
May 27 00:35:08 Mahesh kernel: [ 5055.741593] sd 8:0:0:0: [sdc] 4005888 512-byte logical blocks: (2.05 GB/1.91 GiB)
May 27 00:35:08 Mahesh kernel: [ 5055.742214] sd 8:0:0:0: [sdc] Write Protect is off
May 27 00:35:08 Mahesh kernel: [ 5055.742218] sd 8:0:0:0: [sdc] Mode Sense: 03 00 00 00
May 27 00:35:08 Mahesh kernel: [ 5055.742712] sd 8:0:0:0: [sdc] No Caching mode page present
May 27 00:35:08 Mahesh kernel: [ 5055.742715] sd 8:0:0:0: [sdc] Assuming drive cache: write through
May 27 00:35:08 Mahesh kernel: [ 5055.745326] sd 8:0:0:0: [sdc] No Caching mode page present
May 27 00:35:08 Mahesh kernel: [ 5055.745329] sd 8:0:0:0: [sdc] Assuming drive cache: write through
May 27 00:35:08 Mahesh kernel: [ 5055.781564]  sdc: sdc1
May 27 00:35:08 Mahesh kernel: [ 5055.784191] sd 8:0:0:0: [sdc] No Caching mode page present
May 27 00:35:08 Mahesh kernel: [ 5055.784196] sd 8:0:0:0: [sdc] Assuming drive cache: write through
May 27 00:35:08 Mahesh kernel: [ 5055.784200] sd 8:0:0:0: [sdc] Attached SCSI removable disk

look at it, and find one thing in square brackets repeating? sdc in this case. Note it down on a piece of paper. Type Ctrl+C to get to the prompt.

Locate the iso file to burn onto usb.

If the iso file is at /path/to/iso/somecd.iso ; note this path on a piece of paper.

Write onto USB


This will erase the entire USB disk. Backup before proceed.

  • dd if=/path/to/iso/somecd.iso of=/dev/sdc ibs=20M obs=20M

Replace /path/to/iso/somecd.iso with the actual path to your iso file.

Replace /dev/sdc with whatever you noted down earlier. If the repeating part is sdb ; use /dev/sdb and so on.


Typing a drive letter wrong will result in permanent data loss on a different drive. Pay extra attention while issuing dd command.

share|improve this answer
In order to avoid data loss by selecting wrong disk it is advised to use /dev/disk/by-label/LABEL instead of /dev/sdc – totti Feb 1 '13 at 8:22
Sensible suggestion. But when you are not sure of the label, or you have a ton of 'New volume' s, it becomes a pain. I always prefer the sdX one, but that is a personal choice. – Mahesh Feb 1 '13 at 8:28
Best answer. One suggested improvement is to use pv on the input stream to dd, so the user gets progress feedback (i.e. pv reads the iso, streams it to dd, and displays progress on stderr). – Stabledog Mar 23 '14 at 15:36

Creating a bootable Ubuntu USB flash drive from terminal

  • Mount the ubuntu.iso file.For this run the below commands in terminal,

    sudo mkdir /media/iso
    sudo mount -o loop /path/to/ubuntu.iso /media/iso
  • Then copy all the files from /media/iso to your mounted usb flash drive folder in /media.

    Insert your usb flash drive.

    It will automatically mounted,whenever you insert it.Your usb partition must be mounted inside /media.Let us assume your usb drive mounted inside /media/xxxx folder.Then run the below command,

    cp -a /media/iso/. /media/xxx

    Run lsblk command to know the usb device partition.

  • Then paste the ldlinux.sys file inside your USB flash drive partition(In my case /dev/sdd1) to make the usb bootable .For this run the below commands,

    sudo apt-get install syslinux mtools
    syslinux -s /dev/sdd1
  • Go into the /media/xxx folder and rename the isolinux directory to syslinux.Then go into the renamed syslinux folder and rename the file isolinux.cfg to syslinux.cfg.

       mv /media/xxx/isolinux /media/xxx/syslinux
       mv /media/xxx/syslinux/isolinux.cfg /media/xxx/syslinux/syslinux.cfg
  • Reboot your pc and change the boot-order in bios to USB.Now your ubuntu usb flash drive will booted up and you can install it.

This method will works for any linux distributions,not only ubuntu.

share|improve this answer

I solved this particular problem by using the Ubuntu Live desktop CD.

By booting the Live CD on a computer with an optical drive, I could use the Ubuntu desktop instructions to create the USB pen installer without touching the existing installation.

share|improve this answer

You can hack usb-creator to do this.

You should already have a single vfat partition as partition 1 on the usb device (the erase disk step of usb-creator-gtk does this) and it should be marked bootable.

Next, we will get usb-creator python code to assist us.

$ sudo apt-get install usb-creator


$ bzr branch lp:usb-creator

create a file with this content and name it usb-creator-cli, if you use bzr in the last step, 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


#/dev/sdb1 should be mounted on /mnt
#iso should be mounted to /iso
dev = '/dev/sdb1'
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

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.

share|improve this answer

A command-line method to make a live USB for UEFI systems

Please note: this deletes all data on the target device.

Install prerequisite:

sudo apt-get install p7zip-full

Assuming the target USB is at /dev/sdb

(please check first with gnome-disks or sudo fdisk -l or lsblk and be sure you know what you are formatting)

Destroy existing partition table:

sudo sgdisk --zap-all /dev/sdb

Create new GPT:

sudo sgdisk --new=1:0:0 --typecode=1:ef00 /dev/sdb

Format as FAT32:

sudo mkfs.vfat -F32 /dev/sdb1

Check it:

sudo fdisk -l /dev/sdb

Should output something like:

Device     Start      End  Sectors  Size Type
/dev/sdb1   2048 15663070 15661023  7.5G EFI System

Mount the drive and extract iso onto it, replacing 'name-of-iso' with the actual filename of the iso you downloaded earlier

sudo mount -t vfat /dev/sdb1 /mnt
sudo 7z x name-of-iso -o/mnt/


sudo umount /mnt

Reboot & enjoy Ubuntu ^_^

(Here's where I originally learned to do this.)

I am re-posting this answer from here because that question is about a specific bug, so may be hard to find, while the answer is applicable here.

share|improve this answer

You can install a command line (CLI) Ubuntu using the Alternate Install or Mini iso (which should fit on your 512mb stick)

Then install Crunchbang using the alternate method:

You could also try the Lite version of CrunchBang, which is less than 512mb.

You could use Unetbootin to prepare the USB stick.

share|improve this answer
crunchbang? haha? – RolandiXor Jan 13 '11 at 3:16
I don't have a problem fitting the ISO on the stick (it's 16GB), it's more a question of how I can create a USB stick that boots into the ISO in the first place, and creating it using nothing but the CLI. – j-g-faustus Jan 13 '11 at 3:48
And unetbootin doesn't work, unfortunately - it seems to require graphics support even when you run it from the command line. – j-g-faustus Jan 13 '11 at 4:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.