A Bash Script to Create a Bootable USB from ISO in Linux

Bootiso is a powerful Bash script to easily and securely create a bootable USB device from one ISO file. It helps you create a bootable USB from an ISO with a single command from the terminal. It is a well tailored script that carefully organized and validated using shellcheck.

It has to be run with root authority, and if external programs it requires are not available on your system, it will ask you to install them and exits. Bootiso checks that the selected ISO has the correct mime-type, otherwise it exits. To prevent system damages, it ensures that the selected device is connected only via USB.

Read Also: 3 Ways to Extract and Copy Files from ISO Image in Linux

Before formating and partitioning your USB device, it prompts you to accept execution of the actions to prevent any data loss. Importantly, it manages any failure from an internal command appropriately exits. In addition, it performs a cleanup of any temporary files on exit by employing the trap utility.

Install Bootiso Script in Linux

The easy way to install bootiso from sources is to clone the git repository and set execute permission as shown.

$ git clone https://github.com/jsamr/bootiso.git
$ cd bootiso/
$ chmod +x bootiso

Next, move the script to a bin path (for example ~/bin/ or /usr/local/bin/) to run it like any other Linux commands on your system.

$ mv bootiso ~/bin/

Once installed, the syntax for running bootiso is to provide the ISO as first argument.

$ bootiso myfile.iso

To create a bootable USB device from ISO file, first you need to list all available USB drives attached to your system using the -l flag as shown.

$ bootiso -l

Listing USB drives available in your system:
NAME    HOTPLUG   SIZE STATE   TYPE
sdb           1   14.9G running disk

Next, to make the device (/dev/sdb) as a bootable device, simply provide the ISO as the first argument. Note that if there is only one USB device attached to the system (as in the case above), the script will automatically select it, otherwise, it will ask you to select from an auto-generated list of all attached USB drives.

$ sudo bootiso ~/Templates/eXternOS.iso 
Create Bootable USB in Linux Terminal
Create Bootable USB in Linux Terminal

You may also use the -a flag to enable autoselecting USB drives in conjunction with -y (disables prompting user before formating USB drive) option as shown.

$ sudo bootiso -a -y ~/Templates/eXternOS.iso

If you have multiple USB devices connected to the system, you can use the -d flag to explicitly specify the USB device you want to make bootable from the command line as shown.

$ sudo bootiso -d /dev/sdb ~/Templates/eXternOS.iso  

By default, bootiso uses mount + rsync to employ dd command instead, add the --dd flag as shown.

$ sudo bootiso --dd -d ~/Templates/eXternOS.iso      

In addition, for non-hybrid ISOs, you can install a bootloader with syslinux with the -b option, as follows. This option however does not support the dd command.

$ sudo bootiso -b /ptah/to/non-hybrid/file.iso
OR
$ sudo bootiso -bd /usb/device /ptah/to/non-hybrid/file.iso

For more information on other bootiso capabilities and options, see the help message.

$ bootiso -h  

Bootiso Github repository: https://github.com/jsamr/bootiso

That’s It! Bootiso is a powerful Bash script to easily and securely create a bootable USB device from one ISO file, with a single command on the terminal. Use the comment form below to share your thoughts about it or ask questions.

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

19 thoughts on “A Bash Script to Create a Bootable USB from ISO in Linux”

  1. bootiso: Found non-hybrid ISO; inspecting ISO for boot capabilities…
    bootiso: Could not find an SYSLINUX bios folder containing c32 bios module files on this system.
    Exiting…

    Reply
  2. You never mention numerous dependencies that bootiso in fact requires and which are the pain in the neck to provide. It would be nice to check for them on the user side and point to where they can be obtained ( and installed !)

    Reply
  3. Can I make the script format the usb to ntfs while installing the iso?

    I’ve tried:

    bootiso [-f -t ntfs] isofile.iso — still does fat32
    bootiso [-f] [-t] [ntfs] isofile.iso — still does fat32
    bootiso -f [-t ntfs] isofile.iso — fail saying format action doesn’t require any arguments
    bootiso -f -t ntfs — formats to iso but doesn’t install iso
    bootiso isofile.iso — formats fat32 –if you can direct me to where it defaults to the fat32 so i can change the default to ntfs instead of fat32 that would also work for me
    bootiso [-t] [ntfs] isofile.iso — fail: bash: -f: No such file or directory

    Can’t seem to get the script to create an ntfs formatted bootable usb drive.

    Reply
  4. Version 3 is out [with many improvements :-) https://github.com/jsamr/bootiso/releases/tag/v3.0.0

    Notably, it now inspects ISO file to check if it’s hybrid. When it’s not, it looks for UEFI and SYSLINUX boot capabilities. After which, it chooses the best install mode (dd or mount+rsync) and eventually installs SYSLINUX.

    So you basically don’t need to care anymore about rsync or dd mode, just run `bootiso myfile.iso’ and it will work, even with rescue CDs such as UltimateBootCD.

    Reply
  5. Why not to use dd?

    # dd if=/dev/sdb of=yourimage.iso bs=1m
    

    You don’t need install and setting any other app, dd is out of box.

    Reply
    • @Herald

      The main aim of this script is to provide a secure way of creating bootable devices, which you can not achieve by running this dd command only. Using this dd command, you can accidentally provide your root partition or any other important partition output device, which can lead to data loss; in simple terms the dd command only, can not check that your output device is a USB or not.

      Secondly, using dd command, you will not be prompted before formating of the output device, which may also lead to data loss in case you have not backed up data on that device. This script is a much better option because it securely prepares your USB device before moving files on it, and any internal errors are reported.

      Reply
    • As a side note, dd only works for hybrid ISO’s. bootiso works with any ISO, given the “-b” option to install a syslinux bootloader.

      Reply
      • @Jules

        This actually sheds more light on why bootiso is far much better a option than using dd only for making a bootable USB from the command-line. Thanks for the addition.

        Reply

Leave a Reply to Herald Cancel reply

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.