Arch Linux USB Install and Rescue Media

For some time now, it was possible to use dd to write Arch Linux Install images to USB media. These media would boot fine, but cannot be used for anything other purpose. In the latest 2010.05 release, we used isohybrid for the first time to create a combined image that can be used from both CD and USB.

After such an image has been written to USB, it is even possible to add a second partition and use that for data storage. I was happy it was so easy, only to find out that it wasn’t: When a friend tried to give me a few files, I realized that Windows was unable to access the second partition. So, I was trying to prepare my USB drive such that:

  • I would be able to boot the Arch Linux 2010.05 Netinstall Dual from it.
  • Non-Linux devices (Windows computers for example) could read from and write to it.
  • The whole archiso mess would be invisible for any Windows user accessing it.

Before we start, there is one thing you must never forget: Windows is god damn stupid. Even the latest and greatest Windows 7 will not recognize a filesystem on USB media unless it is on the first primary partition. It will kindly ignore anything else and produce the weirdest errors in the partition manager.

Let’s begin – this process will erase all data on the drive (we could probably do without it, but I didn’t try). First, create a suitable partition layout (from now on assuming that the USB drive is on /dev/sdb):

# LANG=en_US.utf8 fdisk -ulc /dev/sdb

Disk /dev/sdb: 8019 MB, 8019509248 bytes
247 heads, 62 sectors/track, 1022 cylinders, total 15663104 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc8b9659d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    14966783     7482368    b  W95 FAT32
/dev/sdb2   *    14966784    15663103      348160   83  Linux

The second partition should be about 340 MB, not smaller but also not much bigger, we don’t want to waste space. Also notice that the bootable flag needs to be set on sdb2. Now create filesystems on the partitions:
# mkfs.vfat -n SOMELABEL /dev/sdb1
# mkfs.ext2 /dev/sdb2
# tune2fs -i0 -c0 -m0 /dev/sdb2
# e2label /dev/sdb2 ARCH_201005

Notice the label of the Linux partition: While it is arbitrary, it must match the label in the bootloader configuration, which is ARCH_201005 by default. We are finished with the FAT part now: The way we set it up, even Windows will be able to recognize and use it properly. Now, mount the archiso image and the Linux partition:
# mkdir -p /mnt/{archiso,usbboot}
# mount -o loop,ro archlinux-2010.05-netinstall-dual.iso /mnt/archiso
# mount /dev/sdb2 /mnt/usbboot

Copy all the contents of the archiso image onto the USB and umount the ISO:
# cp -a /mnt/archiso/* /mnt/usbboot/
# umount /mnt/archiso

All that is left to do is set up a bootloader. We will use extlinux, as we will be able to reuse all existing configuration from isolinux. First, install the syslinux package, if you don’t have it already:
# pacman -S syslinux
Now, remove the old isolinux bootloader, rename the configuration file, install the extlinux bootloader and umount:
# rm /mnt/usbboot/boot/isolinux/isolinux.bin
# mv /mnt/usbboot/boot/isolinux/isolinux.cfg /mnt/usbboot/boot/isolinux/extlinux.conf
# extlinux --install /mnt/usbboot/boot/isolinux/
# umount /mnt/usbboot

For simplicity, I didn’t rename the isolinux folder here, although the bootloader is technically not isolinux anymore. Feel free to rename it to extlinux if you feel the urge. One last step is setting up a MBR that will recognize the active flag of the second partition and boot its boot sector:
# cat /usr/lib/syslinux/mbr.bin > /dev/sdb

And you are done. Your USB drive will now boot the Arch Linux i686 and x86_64 Netinstall just like the ISO does.

Comments are closed.