grml2usb(8)
==========

Name
----
grml2usb - install grml ISO(s) on usb device for booting

Synopsis
--------
grml2usb [ options ] <ISO[s]> <device>

*******************************************************************************
Important! The grml team does not take responsibility for loss of any data!
*******************************************************************************

[[introduction]]
Introduction
------------

grml2usb installs grml on a given partition of your usb device and makes it
bootable. It provides multi-iso support, meaning you can specify several grml
ISOs on the command line at once and select the grml flavour you would like to
boot on the bootprompt then. Note that the *first* ISO specified on the grml2usb
command line will become the default one (that's the one that will boot when
just pressing enter on the bootprompt or wait until the boot timeout matches).

[IMPORTANT]
By default a compatible master boot record (MBR) is installed on the device
(being for example /dev/sdX when executing 'grml2usb grml.iso /dev/sdX1') and
syslinux is being used as default bootloader. Avoid installation of the default
MBR using the '--skip-mbr' option or if you encounter any problems with the
default MBR consider using '--syslinux-mbr' instead.

[[options]]
Options
-------

The ISO[s] should be the path to one or multiple grml-ISOs and/or the path to
the currently running live-system (being /lib/live/mount/medium).

The device either might be a device name like /dev/sdX1 or a directory. When
specifying a device name the device is mounted automatically. When specifying a
directory grml2usb is assuming that you did set up a bootloader on your own (or
don't need one) and a bootloader won't be installed automatically.

The following options are supported:

  *\--bootoptions=...*::

Use specified bootoptions as default. To use flavour name as a argument for a
boot parameter use %flavour which will be expanded to the flavour name. To add
multiple bootoptions you can specify the option multiple time.

  *\--bootloader-only*::

Do *not* copy files but instead just install a bootloader.  Note that the boot
addons are copied to /boot/addons at this stage as well.  If you want to skip
copying the boot addons consider using the --skip-addons option.

  *\--copy-only*::

Copy files only but do *not* install a bootloader.

  *\--dry-run*::

Avoid executing commands, instead show what would be executed.
Warning: please notice that the ISO has to be mounted anyway, otherwise
identifying the grml flavour would not be possible.

  *\--fat16*::

Format specified partition with FAT16.
**Important:** this will destroy any existing data on the specified partition!

  *\--force*::

Force any (possible dangerous) actions requiring manual interaction (like --fat16).

  *\--grub*::

Install grub bootloader instead of (default) syslinux.

  *\--grub-mbr*::

Install grub into MBR (Master Boot Record) instead of PBR (Partition Boot
Record). Check out <<mbr-vs-pbr,the 'mbr-vs-pbr' section in the FAQ of this
document>> for further details.

  *\--help*::

Display usage information and exit.

//////////////////////////////////////////////////////////////////////////
  *\--initrd=...*::

Install specified initrd instead of the default. You might want to specify
option *--kernel* as well. (Be aware when using multiboot setup.)
[Notice: not implemented yet.]
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
  *\--kernel=...*::

Install specified kernel instead of the default. You might want to specify
option *--initrd* as well. (Be aware when using multiboot setup.)
[Notice: not implemented yet.]
//////////////////////////////////////////////////////////////////////////

  *\--mbr-menu*::

Install master boot record (MBR) with integrated boot menu: interactively choose
the partition to boot from, with a timeout to load the default partition, or
boot from floppy. When NOT using the --mbr-menu option a MBR with LBA and large
disc support but without an integrated boot menu is installed (so it's not
visible at all but instead directly jumps to the bootloader - being grub or
syslinux). Note: This options is available only when using the default MBR and
won't have any effect if you're using the '--syslinux-mbr' option.

  *\--quiet*::

Do not output anything but just errors on console.

  *\--skip-addons*::

Do not install /boot/addons/ files (like dos, grub, memdisk,...).

  *\--remove-bootoption=...*::

Remove specified bootoption (could be a regex) from existing boot options. Use
multiple entries for removing different bootoptions at once.

  *\--skip-grub-config*::

Skip generation of grub configuration files. By default the configuration
files for syslinux *and* grub will be written so you've a working configuration
file no matter whether you're using grub or syslinux as bootloader.

  *\--skip-mbr*::

Do not touch/install the master boot record (MBR).

  *\--skip-syslinux-config*::

Skip generation of syslinux configuration files. By default the configuration
files for syslinux *and* grub will be written so you've a working configuration
file no matter whether you're using grub or syslinux as bootloader.

  *\--syslinux*::

This option is deprecated and is being left only for backwards compatibility
reasons. Syslinux is the default bootloader of grml2usb and therefore the
'--syslinux' option doesn't have any effects. If you do not want to use syslinux
as bootloader consider using the '--grub' option.

  *\--syslinux-mbr*::

Install syslinux' master boot record (MBR, which is booting from the partition
with the "active" flag set) instead of the default one.  If you encounter any
problems with the default MBR you can try using the syslinux MBR instead. If
that works for you please <<author,let us know>> so we can adjust our default
MBR accordingly.

//////////////////////////////////////////////////////////////////////////
  *\--squashfs=*::

Install specified squashfs file instead of the default.
[Notice: not implemented yet.]
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
  *\--uninstall*::

Uninstall grml ISO files.
[Notice: not implemented yet.]
//////////////////////////////////////////////////////////////////////////

  *-v*, *\--version*::

Return version and exit.

  *\--verbose*::

Enable verbose mode.

Developers Corner
-----------------

[[directory-layout]]
Directory layout on usb device
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  boot/ ->
    |-- addons/
    |   |-- allinone.img     [grub - all in one image]
    |   |-- bsd4grml/        [MirBSD]
    |   |-- balder10.imz     [FreeDOS]
    |   |-- memdisk          [chainloading helper]
    |   |-- memtest          [memtest86+]
    |-- release/
    |   |-- grml/
    |   |   |-- linux26      [Kernel]
    |   |   |-- initrd.gz    [initramfs]
    |   |-- grml64
    |   |   |-- linux26      [Kernel]
    |   |   |-- initrd.gz    [initramfs]
    |   |-- grml-medium
    |   |   |-- linux26      [...]
    |   |   |-- initrd.gz
    |   |-- grml64-medium
    |   |   |-- linux26
    |   |   |-- initrd.gz
    |   |-- grml-small
    |   |   |-- linux26
    |   |   |-- initrd.gz
    |   `-- grml64-small
    |       |-- linux26
    |       |-- initrd.gz
    |-- grub/
    |   |-- grml.png         [graphical bootsplash background image for grub2]
    |   |-- grub.cfg         [configuration file for grub2]
    |   |-- menu.lst         [configuration file for grub1]
    |   |-- splash.xpm.gz    [splash screen for grub1]
    `-- syslinux/
        |-- grml.png         [graphical bootsplash background image for syslinux]
        |-- syslinux.cfg     [main configuration file for syslinux]
        `-- [....]           [several further config files for syslinux]

  grml/
    |-- grml2usb.txt         [not yet implemented]
    |-- grml-cheatcodes.txt  [list of bootoptions for grml]
    |-- grml-version.txt     [file containing information about grml-version]
    |-- LICENSE.txt          [license information]
    |-- md5sums              [md5sums of original ISO]
    |-- README.txt           [informational text]
    `-- web/                 [browser related files]
        |-- index.html
        |-- style.css
        `-- images/
            |-- button.png
            |-- favicon.png
            |-- linux.jpg
            `-- logo.png

  live/
    |-- grml/
    |   |-- filesystem.module    [module specifying which squashfs should be used for grml]
    |   `-- grml.squashfs        [squashfs file for grml]
    |-- grml-medium/
    |   |-- filesystem.module    [module specifying which squashfs should be used for grml-medium]
    |   `-- grml-medium.squashfs [squashfs file for grml-medium]
    |-- grml-small/
    |   |-- filesystem.module    [module specifying which squashfs should be used for grml-medium]
    |   `-- grml-small.squashfs  [squashfs file for grml-small]
    `-- ...

[[source]]
Grabbing the source
~~~~~~~~~~~~~~~~~~~

  % git clone git://git.grml.org/grml2usb.git

[[debugging]]
Developers Debugging Hints
~~~~~~~~~~~~~~~~~~~~~~~~~~

To play with grml2usb you can avoid using a real device via a loopback file
setup, like:

  # dd if=/dev/zero of=~/loopback bs=1M count=100 # adjust size to your needs
  # losetup /dev/loop1 ~/loopback

Then create according partitions either running for example:

  # echo -en "n\np\n1\n\n\nt\n6\na\n1\n w\n" | fdisk /dev/loop1

or:

  # parted /dev/loop1 -s "mkpart primary fat16 0 -1s mkfs 1 fat16"

Finally create a filesystem and execute grml2usb as needed:

  # mkfs.vfat /dev/loop1
  # grml2usb --bootloader-only /grml/isos/grml-small_2013.01.iso /dev/loop1

[[performance-tracing]]
Performance tracing
~~~~~~~~~~~~~~~~~~~

  # blktrace -d /dev/sdX -o - | blkparse -i -
  # grml2usb grml_2013.01.iso /dev/sdX1

[[troubleshooting]]
Troubleshooting and Pitfalls when booting
-----------------------------------------

Here is a list of common error messages from BIOS/bootloader when trying to boot
from USB.

///////////////////////////////////////////////////////////
TODO: better list type for the error message / reason part?
See http://www.methods.co.nz/asciidoc/userguide.html
///////////////////////////////////////////////////////////

[horizontal]
*Error message*:: ran out of input data. System halted

*Reason*:: Everything OK, except for the filesystem used on your usb device. So
instead of fat16 you are using for example fat32. Fix: use the appropriate
filesystem (fat16 for usb pens usually). The Bootsplash might be displayed, the
kernel loads but you very soon get the error message.

*Error message*:: Invalid operating system

*Reason*:: the partition layout is not ok. Very probably there's no primary
  partition (/dev/sdX{1..4}) or none has the flag 'bootable' set.

*Error message*:: Boot error.

*Reason*:: Some BIOSses offer different modes for USB booting. The proper mode
to boot a USB stick is USB-HDD. If that doesn’t work or is not supported by your
system, you need to format your USB-Stick as USB-ZIP.  To do this, syslinux
contains an utility called mkdiskimage, which you can use to re-format your USB
stick in USB-ZIP format running 'mkdiskimage -4 /dev/sdX 1 64 32'. Please be
aware that this procedure will erase all data on your stick.  After executing
mkdiskimage just continue installing as usual (grml2usb ...  /dev/sdX4). Note
that this is not going to work for any device larger than 8 GB, since
mkdiskimage only supports 1024c 256h 63s. For a more detailed explanation, refer
to /usr/share/doc/syslinux-common/usbkey.txt.

*Error message*:: No operating system found.

*Reason*:: you forgot to set the boot-flag on the partition. Or there really isn't
any operating system at all. :)

*Error message*:: kernel-panic: unable to mount root-fs...

*Reason*:: Kernel boots but fails to find the root filesystem. The root=
argument in your kernel commandline is pointing to the wrong device. Adjust
root=..., consider using root=UUID=....

*Error message*::  Could not find kernel image: ...

*Reason*:: either a broken isolinux/syslinux version or a broken BIOS. Check out
whether the vendor provides a BIOS update or if using bootloader grub instead of
isolinux/syslinux fixes the problem.

[[faq]]
Frequently Asked Questions (FAQ)
--------------------------------

[[download]]
Where can I get grml2usb?
~~~~~~~~~~~~~~~~~~~~~~~~~

grml2usb is available as Debian package via link:http://deb.grml.org/[the
grml-testing Debian repository].

If you do not want to (or can't) use the grml2usb Debian package you can either
use the grml2usb git tree running:

  git clone git://git.grml.org/grml2usb.git
  cd grml2usb
  make -C mbr
  sudo ./grml2usb ...

or download the provided
link:http://grml.org/grml2usb/grml2usb.tgz[http://grml.org/grml2usb/grml2usb.tgz]
(link:http://grml.org/grml2usb/grml2usb.tgz.md5.asc[gpg signed md5 hash]).
Download and extract the tarball and execute the provided script 'install.sh'.

[NOTE]
It is *NOT* enough to have just the grml2usb script itself without the according
files provided either via the Debian package, the git tree or the file
grml2usb.tgz.

[[dd]]
Why can't I just dd the ISO to a USB device?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Well, you can. :) Starting with grml 2009.10 the ISOs are dd-able straight out-of-the-box.

[IMPORTANT]
Note that ANY existing data on your USB device will be destroyed when
using the dd approach.

///////////////////////////////////////////////////////////////////////////////////////////////////
Grab a recent grml ISO and use
link:http://syslinux.zytor.com/wiki/index.php/Doc/isolinux#HYBRID_CD-ROM.2FHARD_DISK_MODE[isohybrid
from the syslinux project]:

  % isohybrid grml_2009.10.iso
///////////////////////////////////////////////////////////////////////////////////////////////////

This allows you to dd the Grml ISO to your USB device (use for example
link:http://www.chrysocome.net/rawwrite[rawwrite] if you've just a Windows
system available) running:

  % dd if=grml_2013.01.iso of=/dev/sdX

where /dev/sdX is your USB device. Of course this doesn't provide such a
flexible system like with grml2usb (no multi-ISO setup, no additional default
bootoptions,...) but it's a nice way to get a working USB boot setup if you
don't have grml2usb available.

[[grml2usb-vs-dd]]
What's the difference between grml2usb and just using dd?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

grml2usb does not remove any data from your USB device and does not alter the
partition table at all. grml2usb provides multi-ISO support, support for adding
default bootoptions and selecting the bootloader (syslinux vs. grub) without
having to manually touch the ISO at all.

[[grml2iso]]
What's grml2iso?
~~~~~~~~~~~~~~~~

grml2iso is a script which uses grml2usb to generate a multiboot ISO out of
several grml ISOs. See 'man grml2iso' for further details.

[[menu-lst]]
Why is there a menu.lst and a grub.cfg inside /boot/grub/?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

grml2usb supports grub version 1 (grub1) as well as grub version 2 (grub2).
Whereas grub1 uses menu.lst the new version grub2 needs grub.cfg.
Providing both files allows grml2usb to install grub on the target device
no matter which grub version is available on the host where grml2usb is
executed on.

[[stage1]]
grub-install fails with 'The file ../boot/grub/stage1 not read correctly"?!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check whether the partition has the right partition type. For example do NOT use
FAT16 (partition type 6) when using a ext3 filesystem on the partition but
instead use the correct partition type ('83' - Linux) then.

[[grub-install-xfs_freeze]]
grub-install complains about /sbin/grub-install and/or xfs_freeze?!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following message:

  You shouldn't call /sbin/grub-install. Please call /usr/sbin/grub-install instead!
  xfs_freeze: specified file ["/tmp/tmpqaBK6z/boot/grub"] is not on an XFS filesystem

This is "normal". grub-install sends those messages to stderr. To avoid hiding any
possible real error messages grml2usb doesn't ignore those messages.

[[device-map]]
grub-install complains about /boot/grub/device.map?!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following message:

  grub-probe: error: Cannot open `/boot/grub/device.map'

This is "normal" (at least with grub1). This isn't a problem, because the
device.map file will be generated on the target device anyway.

[[unary-operator]]
grub-install complains about a unary operator?!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following message:

  '/usr/sbin/grub-install: line 374: [: =: unary operator expected'

This is "normal". Just ignore it. (It usually doesn't appear
on the second invocation on the same device.)

[[unknown-filesystem]]
grub-install fails with grub-probe: error: unknown filesystem?!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following message:

  grub-probe: error: unknown filesystem
  Auto-detection of a filesystem module failed.
  Please specify the module with the option `--modules' explicitly.

usually means that the device partition table says something else than the
filesystem on the device. For example using FAT16 as filesystem type and
using FAT32 as filesystem on the partition will not work. Either set filesystem
type to FAT32 or format the partition using FAT16. It is essential that
device partition table and filesystem use the same filesystem type.

[[mbr-vs-pbr]]
grub-setup fails after Attempting to install GRUB to a partition instead of the MBR?!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following message:

  grub-setup: warn: Attempting to install GRUB to a partition instead of the MBR.  This is a BAD idea.
  grub-setup: warn: Embedding is not possible.  GRUB can only be installed in this setup by using blocklists.  However, blocklists are UNRELIABLE and its use is discouraged.
  grub-setup: error: Cannot read `/grub/core.img' correctly

appears when using grub2 versions older than 1.98 as those version introduced a
regression which avoids that grub is being installed into a partition (PBR,
Partition Boot Record) instead of MBR (Master Boot Record).

To work around this issue you can either 1) upgrade to grub versions >=1.98, 2)
install grub into the MBR (Master Boot Record) using the '--grub-mbr' option of
grml2usb or 3) switch to syslinux as bootmanager (just drop the '--grub'
option).

[[splash-xpm]]
I'm getting something like "Error: /usr/share/grml2usb/grub/splash.xpm.gz can not be read"!?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Looks like you've only the grml2usb script itself available. Please make sure
you've the grml2usb Debian package installed. The most resent stable version is
available via link:http://deb.grml.org/[the grml-testing Debian repository].  If
you do not have a Debian system please see section <<download,Where can I get
grml2usb?>> in this FAQ.

[[fat16]]
Why do I have to use a FAT16/FAT32 filesystem?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Syslinux (currently) does not support any other filesystems besides FAT16/FAT32
(though that's a sane default if you want to share your files with other
(operating) systems). If you want to use a different filesystem (like ext2/3)
use the bootloader grub instead using grml2usb's '--grub' option.

[NOTE]
FAT32 is supported since syslinux version 3.0.

[[hdt-hangs]]
Addons -> Hardware Detection Tool freezes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This usually means that the machine you ran grml2usb on had syslinux 3.x
installed. The version of hdt (Hardware detection tool) shipping with Grml
2010.12 and newer requires syslinux 4.x.

[[cool-idea]]
I think I've got a really cool idea!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Great! Please check out
link:http://git.grml.org/?p=grml2usb.git;a=blob;f=TODO;hb=HEAD[the TODO file].
Feel free to <<author,report your wishes to the author>>. Patches highly
appreciated.

[[booting-from-usb]]
I've problems with booting from USB.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check out <<troubleshooting,Troubleshooting and Pitfalls when booting>>.

[[found-a-bug]]
I've found a bug!
~~~~~~~~~~~~~~~~~

Please <<author,report it to the author>>. Please provide usage examples and output
of your grml2usb commandline (consider using the "\--verbose" option).

[[usage-examples]]
Usage examples
--------------

  # grml2usb /home/grml/grml_2013.01.iso /dev/sdX1

Install specified ISO on device /dev/sdX1.

  # grml2usb /home/grml/grml_2013.01.iso /home/grml/grml_small_2013.01.iso /dev/sdX1

Install specified ISOs on device /dev/sdX1 for multibooting ISOs.

  # grml2usb /lib/live/mount/medium /dev/sdX1

Install currently running Grml live system on device /dev/sdX1.

  # grml2usb /lib/live/mount/medium /home/grml/grml_2013.01.iso /dev/sdX1

Install currently running Grml live system and the specified
ISO on device /dev/sdX1 for multibooting.

  # grml2usb --fat16 /home/grml/grml_2013.01.iso /dev/sdX1

Install specified ISO on device /dev/sdX1 and format partition /dev/sdX1 with
FAT16 filesystem.

  # grml2usb --grub --grub-mbr /home/grml/grml_2013.01.iso /dev/sdX1

Install specified ISO on device /dev/sdX1 and use grub as bootloader (instead of
syslinux being the default) and install a master boot record (MBR) to the MBR of
/dev/sdX.

///////////////////////////////////////////////////////////////////////////////////////
  # grml2usb --kernel=/boot/vmlinuz-2.6.28-grml --initrd=/boot/initrd.img-2.6.28-grml \
             /home/grml/grml_2013.01.iso /dev/sdX1

Install specified ISO on device /dev/sdX1 but use given kernel and initrd
instead of the ones provided by the ISO.

  # grml2usb --squashfs=/grml/grml-live/grml_cd/live/grml.squashfs \
             /home/grml/grml_2013.01.iso /dev/sdX1

Install specified ISO on device /dev/sdX1 but use given squashfs
file instead of the one provided by the ISO.
///////////////////////////////////////////////////////////////////////////////////////

  # grml2usb --bootoptions="lang=de ssh=mysecret" grml_2013.01.iso /dev/sdX1
  # grml2usb --bootoptions="lang=de" --bootoptions="ssh=mysecret" grml_2013.01.iso /dev/sdX1

Install specified ISO on device /dev/sdX1 and use "lang=de ssh=mysecret" as
default bootoptions.


  # grml2usb --remove-bootoption="vga=791" --remove-bootoption="nomce" grml_2013.01.iso /dev/sdX1

Install specified ISO on device /dev/sdX1 remove vga=791 and nomce from existing bootoptions.

  # grml2usb --bootoptions="persistent-path=%flavour_name" grml64_2010.04.iso grml_2010.04.iso /dev/sdX1

Install specified Isos on device /dev/sdx and add parameter persisten-path
to every menu entry. %flavour_name will be expanded to the flavour of the specific
iso, e.g. grml64 and grml.

[[ressources]]
Online Ressources
-----------------

Check out the link:http://grml.org/grml2usb/[grml2usb webpage] and the
link:http://git.grml.org/?p=grml2usb.git[grml2usb git repository].

[[bugs]]
Bugs
----
Please report feedback, bugreports and wishes <<author,to the author>>.

[[author]]
Author
------
Michael Prokop <mika@grml.org>

/////////////////////////////////////////////////////////////////
http://wiki.grml.org/doku.php?id=tips#multiboot_usb_pen
http://www.startx.ro/sugar/isotostick.sh
https://help.ubuntu.com/community/Installation/FromUSBStick
http://unetbootin.sourceforge.net/
http://www.tux.org/pub/people/kent-robotti/looplinux/rip/mkusb.sh
https://fedorahosted.org/liveusb-creator/
/////////////////////////////////////////////////////////////////
