Subscribe to RSS feed - electronic brain surgery since 2001

Installing grml on USB without a CD

I recently bought a 16GB USB stick. Besides using it for the Sneakernet, I want a small Linux partition to boot from. So I asked on for recommendations. I got two recommendations for grml.

grml is a bootable CD (Live-CD) originally based on Knoppix and nowadays based on Debian. grml includes a collection of GNU/Linux software especially for system administrator and users of texttools. grml provides automatic hardware detection. You can use grml (for example) as a rescue system, for analyzing systems/networks or as a working environment.

There is also a simple explanation how to install it to a USB stick at their wiki1). Unfortunately this will give you exactly what a LiveCD would give you. A read only system.

That's not what I wanted. I wanted a real Linux install that can be easily modified and extended with all changes persistent on the stick.

After some reading and asking in the grml IRC channel I found out that the official way to do that is to burn a grml Live CD, boot from it2) and then choose “install to hard disk” from there.

That seemed wrong to me. Why should I boot into a different Linux? I'm already running a Linux on my desktop computer. This gave me a challenge to get grml installed without booting in between. It finally took me about 5 hours to figure out instead of the 30 minutes to burn a CD, boot and install, but that's how I tick sometimes ;-).

Here's how it can be done:

To make sure we do not mess up any permission settings and stuff we'll work as root here.

First step: downloading the iso image. There are three different sized flavors. I used the medium one. This image then needs to be mounted via loopback device:

#> modprobe loop
#> mount -o loop grml-medium_2008.11.iso /mnt/

The next step took me the most time to figure out. grml uses a compressed file system which is stored inside a single image file in /mnt/live/grml-medium.squashfs. As the extension suggests, this is a SquashFS system. However I couldn't get it mounted or extracted. A guy in the IRC then told me it uses a LZMA compression instead of the usual GZip. Bummer.

There are patches for LZMA available at but I could get the stuff compiled. After some googling I found this thread which pointed me to a binary version of unsquashfs with LZMA patches applied.

For your convenience you can download the binary here: unsquashfs-lzma.tgz

Okay, we finally can extract the image:

#> ./unsquashfs-lzma /mnt/live/grml-medium.squashfs

This creates a squashfs-root directory. We no longer need the CD image now and can unmount it:

#> umount /mnt

Next step: preparing the USB stick. The medium flavor of grml takes about 500MB of space so you need to create a partition that's a bit bigger than that. When done, you can create the file system (adjust /dev/sdc1 to your device node).

#> mkfs.ext3 -c 0 /dev/sdc1

Now, just mount the stick and copy all data from the extracted image.

#> mount /dev/sdc1 /mnt/
#> cp -a squashfs-root/* /mnt/

When installing grml using the grml2hd script, it will configure a few things automatically. Here we need to do these things manually.

First make sure grml “knows” it is no longer running from a CD:

#> rm /mnt/etc/grml_cd
#> cp /mnt/etc/runlevel.conf.hdinstall /mnt/etc/runlevel.conf
#> echo 'none /dev tmpfs rw,size=5M,mode=0755 0 0' > /mnt/etc/mtab

Because a USB stick is used in different computers with possibly different systems, the root file system needs to be identified without relying on the device name. This is done by the file system UUID and udev.

Get the UUID of your partition on the stick:

#> /lib/udev/vol_id --uuid /dev/sdc1

Now edit the /mnt/etc/fstab and put this line at the top of the file, using your UUID of course.

/dev/disk/by-uuid/eb026c70-be2f-4af6-b626-8e7f926e4076 / ext3 noatime,nodiratime,errors=remount-ro  0 1

As boot manager I prefer grub and it's already installed on my desktop system (and probably on your's, too). So we only need to edit some configs and can use our local grub for the setup.

The device map is first (adjust the device name of your stick again, but keep hd0):

#> echo '(hd0)  /dev/sdc' > /mnt/boot/grub/device/map

Now create a /mnt/boot/grub/menu.lst file. Again use your UUID and make sure the kernel versions are correct.

default     0
timeout     10
color cyan/blue white/blue

# default entry
title  2.6.26-grml
kernel (hd0,0)/boot/vmlinuz-2.6.26-grml root=UUID=eb026c70-be2f-4af6-b626-8e7f926e4076 grml_from_hd vga=0x0317
initrd (hd0,0)/boot/initrd.img-2.6.26-grml

# for debugging purposes
title  2.6.26-grml debug
kernel (hd0,0)/boot/vmlinuz-2.6.26-grml root=UUID=eb026c70-be2f-4af6-b626-8e7f926e4076 debug log nocolor
initrd (hd0,0)/boot/initrd.img-2.6.26-grml

# without framebuffer
title  2.6.26-grml no framebuffer
kernel (hd0,0)/boot/vmlinuz-2.6.26-grml root=UUID=eb026c70-be2f-4af6-b626-8e7f926e4076 video=ofonly
initrd (hd0,0)/boot/initrd.img-2.6.26-grml

# memorytest
title memorytest
kernel (hd0,0)/boot/memtest86+.bin

You're ready to install grub in the MBR of your stick, now.

#> grub-install --root-directory=/mnt/ /dev/sdc

That's it. Unmount the stick and boot it.

#> sudo umount /mnt
linux, grml, usb, install, squashfs
Similar posts:
A DokuWiki BTW
alternatively run the image in qemu
Posted on Friday, January the 9th 2009 (10 years ago).


blog comments powered by Disqus