How to create a bootable USB from a bootable ISO with the command line on Linux?

50

40

I have a CD that's created from an ISO file which I use to install a custom version of Ubuntu via plop linux.

The cd works fine but I'd like to use a bootable USB drive instead. I used the command dd to try and create the bootable USB:

dd if=filename.iso of=/dev/sdb1 bs=4k

Now this does copy the files and make the USB bootable but I get the error "Missing operating system"

Any ideas?

xsdf

Posted 2013-05-03T20:11:23.260

Reputation: 1 225

http://askubuntu.com/questions/116942/any-way-to-manually-make-a-bootable-usb-from-iso – Ciro Santilli 新疆改造中心法轮功六四事件 – 2015-09-14T14:26:47.167

@dashboard - The GUI tools never seem to work well for me, and this has consistently been true over many years. I'm happy to know the command line method. I find it easier and more reliable. It is a lot less frustrating! – MountainX – 2015-09-18T20:36:21.253

Do you only have access to the command line? There are interfaces like Unetbootin that work very well and run on linux.. – dashboard – 2013-05-03T21:38:25.017

3@dashboard I would prefer command line because it is available on every linux machine. – xsdf – 2013-05-06T12:40:07.030

Answers

58

Ok after some research I've figured out a solution, and I'll go through it step by step. Problem was two-fold.

  1. Plug in the USB flash drive and determine the device it's mounted on with the command:

    sudo fdisk -l
    

    This time around it was /dev/sdc1 for me, so I'll use that as my example.

  2. Umount the device

    umount /dev/sdc1
    
  3. Not sure if necessary but I formatted the drive in FAT32, just in case

    sudo mkdosfs -n 'USB-Drive-Name' -I /dev/sdc -F 32
    
  4. Now my ISO was using isolinux not syslinux. I knew it worked with CDs so I figured out that I needed to call the isohybrid command, which allows for an ISO to be recognized by the BIOS from a hard drive.

     isohybrid filename.iso
    

    You can find out more about this command here, but this was the cause of the message "Missing Operating System" The first problem was fixed, but now it said "isolinux.bin was missing or corrupt"

  5. The next step is to copy the iso. My second problem lay here, where I was copying to the partition, sdc1, not the device, sdc.

    sudo dd if=filename.iso of=/dev/sdc bs=4k
    

    This seems to work just fine, but the forum where I got the last fix, it was recommended to do the following before unplugging the device:

    sync
    sudo eject /dev/sdc
    

xsdf

Posted 2013-05-03T20:11:23.260

Reputation: 1 225

3Making an assumption here, I think the mkdosfs command may not be necessary, since the iso has a filesystem located on it already (probably including an MBR, not sure) that is copied over to the beginning of the block device. Man, isohybrid is a cool command, didn't know about it! – Ehtesh Choudhury – 2014-10-09T03:55:10.700

1

for windows 7 bootable install USB, also see http://superuser.com/questions/256869/what-are-the-nuisances-of-creating-a-bootable-windows-7-usb-drive-from-linux-wit?rq=1

– cwd – 2014-10-16T00:34:27.927

7Step #3 is unnecessary; the dd command in step #5 will obliterate the newly created filesystem with the contents of the ISO. – ewhac – 2015-02-18T23:53:28.207

I'm close to 12 hour looking for this same problem until I find your post here and I did follow and step and... it has worked! (the step 5 was my issue too, i'm not pro at linux yet, so thank you) – Ismael – 2016-09-05T01:05:52.413

3

Here's a way to check for dd's progress: http://unix.stackexchange.com/a/11264/13011.

– Nikos Alexandris – 2014-05-29T07:00:06.833

3

This is a common issue with SanDisk USB sticks, or sticks not formatted in FAT32.

If not either of those it is most certainly an issue with your stick partition order or the syslinux.cfg file.

Shouvik Sayef

Posted 2013-05-03T20:11:23.260

Reputation: 111

USB flash drive is from Verbatim. I reformatted in FAT32 just to be sure and still got same error. – xsdf – 2013-05-03T20:37:30.470

1

isohybrid may not always work. For example, I had an .iso with FreeDOS and isohybrid was not able to find some important files there (I don't know whether they should had been put there by syslinux, which I used too, or anything else). I propose several alternatives here.

1) Install another bootloader there such as GRUB. It is explained here:

"Assume your USB stick's first partition is FAT32 and its partition is /dev/sdy1" (I had grub2 on my Fedora Core, so I changed the commands a bit):

# mkdir -p /mnt/usb ; mount /dev/sdy1 /mnt/usb
# grub2-install --target=i386-pc --recheck --debug --boot-directory=/mnt/usb/boot /dev/sdy
# grub2-mkconfig -o /mnt/usb/boot/grub2/grub.cfg

# optional, backup config files of grub.cfg
# mkdir -p /mnt/usb/etc/default
# cp /etc/default/grub /mnt/usb/etc/default
# cp -a /etc/grub.d /mnt/usb/etc

# sync; umount /mnt/usb

2) FreeDOS wiki offers a compound method with GRUB and syslinux here (though I don't understand how they launched grub> - I couldn't boot from the usb up to that stage).

3) Here is a post which may be useful - it says 'As long as the command.com, kernel.sys, syslinux.cfg, ldlinux.sys and fat32lba.bss files are in the root of the drive and the MBR and boot sector are not rewritten the drive should remain bootable.'

4) Here it is explained how to generate a bootable .iso file with a syslinux bootloader. They don't even use isohybrid. Unfortunately that didn't help me (maybe because of syslinux).

5*) Use a windows program via wine. I tried rufus, however that didn't work, it couldn't find the device.

I warn you that unfortunately I couldn't solve this problem, my device was unbootable, but I hope that this may be useful for other people (also those who want to install not a linux on the usb). The usb image generated by chtaube though worked for me, so I think these methods are correct.

UPD: The 3rd method really works (with a correction for a custom installation file).

UPD2: (fixed links). The problem with isohybrid was probably because the versions of isolinux.bin on iso and my system were different. Recompiled the iso using genisoimage as suggested here:

genisoimage -l -r -J -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -c isolinux/boot.cat -o fd11new.iso fd11new

There were some problems too, they were solved by the method here before genisoimage:

cp /boot/extlinux/*.c32 fd11new/isolinux/
extlinux --install /boot/isolinux

== end UPD2 ==

Yaroslav Nikitenko

Posted 2013-05-03T20:11:23.260

Reputation: 148

1st link: https://wiki.archlinux.org/index.php/GRUB#Install_to_external_USB_stick

– Yaroslav Nikitenko – 2016-01-20T13:44:10.833

2nd: http://freedos.sourceforge.net/wiki/index.php/USB#Linux_2 You may add these links to the post if the system trusts you more than me. StackOverflow already knows me well, so why such a problem at superuser? Also I had problems posting this, it didn't show me that my answer was already posted.

– Yaroslav Nikitenko – 2016-01-20T13:46:12.237

It seems superuser counts links by their references, i.e. if I link twice to a same resource, it's counted. This seems to be a bug. A workaround in UPD came from http://www.spiderbird.com/tag/fat32lba-bss/

– Yaroslav Nikitenko – 2016-01-20T18:57:09.803

All links in the comments fixed. I leave them here to show how much problems this policy brings. – Yaroslav Nikitenko – 2016-02-11T22:04:41.500

0

You could use bootiso utility, which does exactly that, securely:

bootiso -d /dev/sdb filename.iso

bootiso will check that selected device /dev/sdb is connected through USB and fails if it doesn't, which is a big security plus. It will also autodetect USB device if there is exactly one USB drive connected to your system, see it in action:

If you want to install syslinux bootloader to circumvent issues mentioned by @xsdf, use -b option:

 bootiso -b -d /dev/sdb filename.iso

To install it:

curl -L https://rawgit.com/jsamr/bootiso/latest/bootiso -O
chmod +x bootiso

Jules Randolph

Posted 2013-05-03T20:11:23.260

Reputation: 347