Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Version 3.0
Browse files Browse the repository at this point in the history
fixes #13
fixes #12
fixes #11
fixes #8
fixes #14
  • Loading branch information
jsamr committed Jul 10, 2018
1 parent 06b073c commit ca1fc77
Show file tree
Hide file tree
Showing 9 changed files with 1,417 additions and 978 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8

[bootiso]

indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
2,195 changes: 1,284 additions & 911 deletions bootiso

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
# v2.6.0
# v3.0.0

- `[install-auto]` default mode: bootiso chooses the most appropriate copy mode after inspecting ISO file
- `--dd` option now overrides `[install-auto]` in lieu of `[install-mount-rsync]` and force image-copy (`[install-dd]` mode)
- added `-m`, `--mrsync` option to override `[install-auto]` and force mounting+rsync (`[install-mount-rsync]` mode)
- securely handle unmounting of target device before altering data, exit when failing
- added `-f`, `--format` option to format USB device and quit
- added `-L`, `--label` option to chose a label
- added `-t`, `--type` option to chose a FS type amongst vfat, exfat, ext2, ext3, ext4, f2fs
- added `-t`, `--type` option to chose a FS type amongst vfat, exfat, ntfs, ext2, ext3, ext4 and f2fs
- added `-M` alias to `--no-mime-check`
- removed `-b`, `--bootloader` option since its installation is now automatic
- added `-i`, `--inspect` and `-p`, `--probe` action flags to inspect ISO file boot capabilities.
- fixed bug preventing label to be set with `--no-mime-check` option
- set FAT32-LBA by default instead of FAT32
- forbid -t option with "-b" option when fstype is not VFAT
- add '--noconfirm' option to pacman install
- removed "noconfirm" or "yes" options to pakage managers install commands
- print bootiso name in log messages to comply with UNIX customs
- refactoring with options map
- exhaustive flags combination tests
- better faulty command line argument option assignments handling
- better user feedback and error reports in many corner cases
- added short device selection with omission of full path prefix (`/dev/`)
- check the existence of `mkfs.<type>` before formating
- removed `-s` strict mime check option
- create temporary folders in `/var/tmp` instead of `/tmp` (some systems mount `/tmp` in RAM, which can be problematic with large ISO files)

# v2.5.2

Expand Down
Binary file added images/bootiso-ay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bootiso-d-no-usb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bootiso-p.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/bootiso.png
Binary file not shown.
166 changes: 103 additions & 63 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,46 @@ Don't want to messup the system with `dd` command? Create a bootable USB from an
### Synopsis

bootiso [<options>...] <file.iso>
bootiso --dd [<options>...] <file.iso>
bootiso <other-action> [<options>...]
bootiso <action> [<options>...] <file.iso>
bootiso <action> [<options>...]

Default bootiso action is to install a live image with `rsync`, given an ISO file (first synopsis).
Alternative actions can be provided to perform other tasks, such as formating USB stick.
[`<options>` and `<actions>` are listed in the bellow section](#flags).
The default action `[install-auto]` as per first synopsis is to install an ISO file to a USB device in
automatic mode. In such mode, bootiso will analyse the ISO file and select the best course of
actions to maximize the odds your USB stick is proven bootable (see [automatic mode behavior](#auto)).
Other [`<options>` and `<actions>` are listed in the bellow section](#flags).

### Examples

Provide the ISO as first argument and you'll be prompted to select from available USB drives amongst a list extracted from `lsblk`. If there is only one USB device connected, `bootiso` will automatically select it:
To have a quick feedback, `[probe]` around to check bootiso capabilities with given ISO file and list USB drives candidates:

bootiso myfile.iso
bootiso -p myfile.iso

Or provide explicitly the USB device. Command fails and exit if the provided device is not USB, such as sata:
With the default action `[install-auto]` ([read its behavior here](#auto)), give the ISO as first argument and you'll be prompted to select from available USB drives amongst a list extracted from `lsblk`. If there is only one USB device connected, `bootiso` will automatically select it:

bootiso -d /dev/sde myfile.iso
bootiso myfile.iso

Add a [syslinux bootloader](https://en.wikipedia.org/wiki/SYSLINUX) for [non-hybrid ISOs](https://superuser.com/questions/683210/how-do-i-determine-if-an-iso-is-a-hybrid) such as Windows':
Or provide explicitly the USB device with `-d` flag. Command fails and exit if the provided device is not USB, such as sata:

bootiso -bd /dev/sde myfile.iso
bootiso -d sde myfile.iso

Use `dd` instead of mount + `rsync`:
Avoid being promtped before writting to USB drive and autoselect device when there is exactly one:

bootiso --dd -d /dev/sde myfile.iso
bootiso -ay myfile.iso

List available USB drives and exit:

bootiso -l
bootiso -l

`[inspect]` the given ISO file and exit:

bootiso -i myfile.iso

Quick-`[format]` the USB drive to NTFS and label it 'SAMUEL_SONY':

bootiso -f -t ntfs -L 'SAMUEL_SONY'


Go to the [flags](#flags) section to see a detailed list of actions and options.

### Quick install

Expand All @@ -51,7 +62,7 @@ Optionally, move the script to a bin path

mv bootiso <bin-path>

Where `bin-path` is any folder in the `$PATH` environment such as `/usr/sbin/`.
Where `bin-path` is any folder in the `$PATH` environment, preferably for superuser utilities such as `/usr/local/sbin/`.


### Help the community
Expand All @@ -63,13 +74,17 @@ If you like `bootiso`, feel free to help the community find it by **staring the

### See it in action

#### Using `--assume-yes` + `--autoselect`
#### Probing

[![](images/bootiso-p.png)](https://webmshare.com/JZrVW)

[![](images/bootiso.png)](https://webmshare.com/RRnY6)
#### Using `--assume-yes` + `--autoselect` (shorten `-ay`)

[![](images/bootiso-ay.png)](https://webmshare.com/mw7Q4)

#### The selected device is not connected through USB

[![](images/bootiso.png)](https://webmshare.com/ra8Ge)
[![](images/bootiso-d-no-usb.png)](https://webmshare.com/36rRn)

<a name="flags"/>

Expand All @@ -90,37 +105,55 @@ Note that **short POSIX flags can be stacked** as of **v2.4.0**, like so: `booti
<tr>
<td></td>
<td></td>
<td>Default action is to install given ISO with <code>rsync</code>.</td>
<td><code>[install-auto]</code>: Default action. Install ISO file in <a href="#auto">automatic mode</a>.</td>
<td>yes</td>
</tr>
<tr>
<td><code>-h</code></td>
<td><code>--help</code></td>
<td>Display a help message and exit.</td>
<td><code>[help]</code>: Display a help message and exit.</td>
<td>no</td>
</tr>
<tr>
<td><code>-v</code></td>
<td><code>--version</code></td>
<td>Display version and exit.</td>
<td><code>[version]</code>: Display version and exit.</td>
<td>no</td>
</tr>
<tr>
<td><code>-l</code></td>
<td><code>--list-usb-drives</code></td>
<td>List available USB drives.</td>
<td><code>[list-usb-drives]</code>: List available USB drives.</td>
<td>no</td>
</tr>
<tr>
<td><code>-i</code></td>
<td><code>--inspect</code></td>
<td><code>[inspect]</code>: Inspect ISO file boot capabilities and how <code>bootiso</code> can handle it, then exit.</td>
<td>yes</td>
</tr>
<tr>
<td><code>-p</code></td>
<td><code>--probe</code></td>
<td><code>[probe]</code>: Equivalent of <code>[inspect]</code> and <code>[list-usb-drives]</code> actions.</td>
<td>yes</td>
</tr>
<tr>
<td><code>-f</code></td>
<td><code>--format</code></td>
<td>Format USB drive.</td>
<td><code>[format]: </code>Format USB drive.</td>
<td>yes</td>
</tr>
<tr>
<td></td>
<td><code>--dd</code></td>
<td>Install with <code>dd</code> utility instead of mounting + <code>rsync</code>. Does not allow bootloader installation with syslinux.</td>
<td><code>[install-dd]</code>: Overrides "automatic" mode and install ISO in image-copy mode with <code>dd</code> utility. It is recommended to run [inspect] action first.</td>
<td>yes</td>
</tr>
<tr>
<td></td>
<td><code>--mrsync</code></td>
<td><code>[install-mount-rsync]</code>: Overrides "automatic" mode and install ISO in mount-rsync mode with <code>rsync</code> utility. It is recommended to run [inspect] action first.</td>
<td>yes</td>
</tr>
</table>
Expand All @@ -133,63 +166,76 @@ Note that **short POSIX flags can be stacked** as of **v2.4.0**, like so: `booti
<th>Option<br/>(POSIX&nbsp;short)&nbsp;<br/></th>
<th><br/>Option<br/>(GNU,&nbsp;long)<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
<th>Description</th>
<th>Compatible actions</th>
<th>Applicable actions<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
</tr>
<tr>
<td><code>-d &lt;device&gt;</code></td>
<td><code>--device &lt;device&gt;</code></td>
<td>Select <code>&lt;device&gt;</code> block file as USB device. If <code>&lt;device&gt;</code> is not connected through a USB bus, bootiso will fail and exit. Device block files are usually situated in <code>/dev/sXX</code> or <code>/dev/hXX</code>. You will be prompted to select a device if you don&#39;t use this option.</td>
<td>install, format</td>
</tr>
<tr>
<td><code>-b</code></td>
<td><code>--bootloader</code></td>
<td>Install a <a href="https://en.wikipedia.org/wiki/SYSLINUX">syslinux bootloader</a> (safe mode) for non-hybrid ISOs. Does not work with <code>--dd</code> action.</td>
<td>install (<code>rsync</code>)</td>
<td>Select <code>&lt;device&gt;</code> block file as USB device. If <code>&lt;device&gt;</code> is not connected through a USB bus, bootiso will fail and exit. Device block files are usually situated in <code>/dev/sXX</code> or <code>/dev/hXX</code>. You will be prompted to select a device if you don&#39;t use this option. You can omit `/dev/` prefix.</td>
<td>install-*, format</td>
</tr>
<tr>
<td><code>-y</code></td>
<td><code>--assume-yes</code></td>
<td>bootiso won&#39;t prompt the user for confirmation before erasing and partitioning USB device. Use at your own risks.</td>
<td>install, format</td>
<td>install-*,<br/>format</td>
</tr>
<tr>
<td><code>-a</code></td>
<td><code>--autoselect</code></td>
<td>Enable autoselecting USB devices in conjunction with <code>-y</code> option. Autoselect will automatically select a USB drive device if there is exactly one connected to the system. Enabled by default when neither <code>-d</code> nor <code>--no-usb-check</code> options are given.</td>
<td>install, format</td>
<td>install-*,<br/>format</td>
</tr>
<tr>
<td><code>-J</code></td>
<td><code>--no-eject</code></td>
<td>Do not eject device after unmounting.</td>
<td>install</td>
<td>install-*</td>
</tr>
<tr>
<td><code>-M</code></td>
<td><code>--no-mime-check</code></td>
<td>bootiso won&#39;t assert that selected ISO file has the right mime-type.</td>
<td>install</td>
<td>install-*</td>
</tr>
<tr>
<td><code>-t &lt;type&gt;</code></td>
<td><code>--type &lt;type&gt;</code></td>
<td>Format to <code>&lt;type&gt;</code> instead of standard FAT32 (vfat). Supported types: vfat exfat ntfs ext2 ext3 ext4 f2fs.
</td>
<td>install-mount-rsync,<br/>format</td>
</tr>
<tr>
<td><code>-s</code></td>
<td><code>--strict-mime-check</code></td>
<td>Disallow loose <code>application/octet-stream</code> mime type in ISO file.</td>
<td>install</td>
<td><code>-L &lt;label&gt;</code></td>
<td><code>--label &lt;label&gt;</code></td>
<td>Set partition label as <code>&lt;type&gt;</code> instead of automatically inferred.
<code>bootiso</code> will cut labels which are too long regarding the selected filesystem limitations.
</td>
<td>install-mount-rsync,<br/>format</td>
</tr>
<tr>
<td></td>
<td><code>--</code></td>
<td>POSIX end of options.</td>
<td></td>
<td>install-*<br/>inspect</td>
</tr>

<tr>
<td></td>
<td><code>--no-usb-check</code></td>
<td>bootiso won&#39;t assert that selected device is a USB (connected through USB bus). Use at your own risks.</td>
<td>install, format</td>
<td>install-*,<br/>format</td>
</tr>
<tr>
<td></td>
<td><code>--local-bootloader</code></td>
<td>Prevent download of remote bootloader and force local (SYSLINUX) during installation.</td>
<td>install-auto,<br/>install-mount-rsync</td>
</tr>
<tr>
<td><code><s>-b</s></code></td>
<td><code><s>--bootloader</s></code></td>
<td>Removed in v3.0.0. SYSLINUX installation is now automated.</td>
</tr>
</table>

<a name="security" />
Expand All @@ -198,32 +244,26 @@ Note that **short POSIX flags can be stacked** as of **v2.4.0**, like so: `booti

✔ bootiso asserts that selected ISO has the correct mime-type and exit if it doesn't (with [file](https://askubuntu.com/a/3397/276357) utility).
✔ bootiso asserts that selected device is connected through USB preventing system damages and exit if it doesn't (with [udevadm](https://askubuntu.com/a/168654/276357) utility).
✔ bootiso asserts that selected item is not a partition and exit if it doesn't (with `lsblk`).
✔ bootiso asserts that selected item is not a partition and exit if it doesn't (with `lsblk`).
✔ bootiso prompts the user for confirmation before erasing and paritioning USB device.
✔ bootiso will handle any failure from a command properly and exit.
✔ bootiso will call a cleanup routine on exit with `trap`.
✔ bootiso is being carefully linted and validated with [shellcheck](https://www.shellcheck.net/) (see [code quality status from codacy](https://app.codacy.com/app/jsamr/bootiso/dashboard)).

This script will also check for dependencies and prompt user for installation (works with `apt-get`, `yum`, `dnf`, `pacman`, `zypper`, `emerge`).

### What it does

With install-rsync action, the script walks through the following steps:

1. Request sudo.
2. Check dependencies and prompt user to install any missing.
3. If not given the `-M`, `--no-mime-check` option, assert that provided ISO exists and has the expected `application/x-iso9660-image` mime-type via `file` utiltiy. If the assertion fails, exit with error status.
4. If given the `-d`, `--device` option, check that the selected device exists and is not a partition. Otherwise, prompt the user to select a device and perform the above-mentioned controls.
5. If not given the `--no-usb-check` option, assert that the given device is connected through USB via `udevadm` utility. If the assertion fails, exit with error status.
6. If not given the `-y`, `--assume-yes` option, prompt the user for confirmation that data might be lost for selected device if he goes to next step.
7. Unmount the USB if mounted, blank it and delete existing partitions.
8. Create a FAT32 partition on the USB device.
9. Create a temporary dir to mount the ISO file and mount it.
10. Create a temporary dir to mount the USB device and mount it.
11. Copy files from ISO to USB device.
12. If option `-b`, `--bootloader` is selected, install a bootloader with syslinux in slow mode.
13. Unmount devices and remove temporary folders.
14. Eject USB device if `-J`, `--no-eject` is not selected
<a name="auto" />

### Automatic mode behavior

With `[install-auto]` action, `bootiso` will inspect the ISO file and chose the best strategy to end up with a bootable USB stick.

The main decision is to chose between image-copy and mount+rsync modes.
In image-copy `dd` mode (enforcable with `[install-dd]` action, `--dd` flag), `bootiso` uses `dd` utility to make a block-by-block copy of the ISO.
This is perfectly appropriate when the ISO file is aimed both at disk drives and flat disks. Those ISO are called [hybrids](https://superuser.com/questions/683210/how-do-i-determine-if-an-iso-is-a-hybrid).

In mount+rsync mode (enforcable with `[install-mount-rsync]` action, `--mrsync` flag), `bootiso` creates one partition with MBR table in the USB drive and copy files from mounted ISO.
It will also install SYSLINUX bootlaoder if configuration files are found which will allow legacy BIOS boot. When local version doesn't match ISO version, it will attempt to download the closest version available in [kernel.org](https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/Testing) if `--local-bootloader` flag is not set.

### Credits

Expand Down

0 comments on commit ca1fc77

Please sign in to comment.