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

Posted on

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 
A Bash Script to Create a Bootable USB from ISO in Linux

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.

Source: tecmint.com

Leave a Reply

Your email address will not be published. Required fields are marked *