USB flash installation media

From ArchWiki
Revision as of 15:20, 21 November 2013 by Lahwaacz (Talk | contribs) (style changes to conform to Help:Style, fixed section link)

Jump to: navigation, search

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary end

This page discusses various methods on how to create a Arch Linux Installer USB drive (also referred to as "flash drive", "USB stick", "USB key", etc) for booting in BIOS and UEFI systems. The result will be a LiveUSB (LiveCD-like) system) that, because of the nature of SquashFS, will discard all changes once the computer shuts down.

If you would like to run a full install of Arch Linux from a USB drive (i.e. with persistent settings), see Installing Arch Linux on a USB key. If you would like to use your bootable Arch Linux USB stick as a rescue USB, see Change Root.

BIOS and UEFI Bootable USB

Note: The instructions below are specifically for Archiso/official media; Archboot preparation is identical, without the filesystem LABEL/UUID requirement.

Recommended Method - in GNU/Linux

This method is slightly more complicated than writing the image directly with dd, but it does keep the drive usable for data storage. Before you begin, make sure that your USB device is formatted as either FAT32. Also, make sure that you have the latest syslinux package (version 6.02 or newer) installed

  • Mount the ISO image:
# mkdir -p /mnt/{usb,iso}
# mount -o loop archlinux-2013.10.01-dual.iso /mnt/iso
  • Then create a FAT32 filesystem in the partition on the USB (unmount before, if necessary).
  • Mount the newly created FAT32 USB partition, and copy the contents of the installation media to the USB media.
# mount /dev/sdX1 /mnt/usb
# cp -a /mnt/iso/* /mnt/usb
# sync
# umount /mnt/{usb,iso}
  • Adjust the configuration files (necessary only for Archiso, not needed for Archboot iso):
Warning: Failure to label the drive "ARCH_2013XX" (with the appropriate release month) or to use an UUID (to re-label it to whatever you like) will get you the infamous "30 seconds" error.

Here is how you can replace the archisolabel=ARCH_2013XX part with your equivalent of archisodevice=/dev/disk/by-uuid/47FA-4071 for both config files at the same time, using a single command:

Note: Adjust /dev/sdX1 before running it, else it will become blank (since drive sdX does not exist).
$ sed -i "s|label=ARCH_.*|device=/dev/disk/by-uuid/$(blkid -o value -s UUID /dev/sdX1)|" archiso_sys{32,64}.cfg
  • Install Syslinux to the USB by following Syslinux#Manual_install. Overwrite the existing syslinux modules (*.c32 files) present in the USB (from the ISO) with the ones from the Syslinux pkg to avoid version mismatch related boot failure.

Recommended Method - In Windows

Note:
  • Do not use any Bootable USB Creator utility for creating the UEFI bootable USB. Do not use dd for Windows to dd the ISO to the USB drive.
  • In the below commands X: is assumed to be the USB flash drive in Windows.
  • Windows used backward slash \ as path-separator, so the same is used in the below commands.
  • All commands should be run in Windows command prompt as administrator.
  • > denotes the Windows command prompt.
  • Partition and format the USB drive using Rufus USB partitioner. Select partition scheme option as MBR for BIOS and UEFI and File system as FAT32. Uncheck "Create a bootable disk using ISO image" and "Create extended label and icon files" options. Use
  • Change the Volume Label of the USB flash drive X: to match the LABEL mentioned in archisolabel= part in <ISO>\loader\entries\archiso-x86_64.conf. This step is required for Official ISO (Archiso) but not required for Archboot.
  • Extract the ISO (similar to extracting ZIP archive) to the USB flash drive (using 7-Zip.
  • Run the following command (in Windows cmd prompt, as admin)
> cd bios\
> for /r %Y in (*.c32) do copy "%Y" "X:\boot\syslinux\" /y
> copy mbr\*.bin X:\boot\syslinux\ /y
  • Install Syslinux to the USB by running (use win64/syslinux64.exe for x64 Windows):
> cd bios\
> win32/syslinux.exe -d /boot/syslinux -i -a -m X:
Note:
  • The above step install Syslinux ldlinux.sys to the USB partition VBR, sets the partition as active/boot in the MBR partition table and write the MBR boot code to the 1st 400-byte boot code region of the USB.
  • The -d switch expects path with forward slash path-separator like in *unix systems.

BIOS-only USB using dd

Warning: This will irrevocably destroy all data on /dev/sdx.

In GNU/Linux

Tip: Check that the USB flash installation media is not mounted with lsblk.
Note: Use /dev/sdx instead of /dev/sdx1.
# dd bs=4M if=/path/to/archlinux.iso of=/dev/sdx && sync

In Windows

Using Cygwin

Make sure your Cygwin installation contains the dd package.

Tip: If you do not want to install Cygwin, you can download dd for Windows from here. See the next section for more information.

Place your image file in your home directory:

C:\cygwin\home\John\

Run cygwin as administrator (required for cygwin to access hardware). To write to your USB drive use the following command:

dd if=image.iso of=\\.\[x]: bs=4M

where image.iso is the path to the iso image file within the cygwin directory and \\.\[x]: is your USB flash drive where x is the windows designated letter, e.g. \\.\d:.

On Cygwin 6.0 find out the correct partition with:

cat /proc/partitions

and write the ISO image with the information from the output. Example:

Warning: This will irrevocably delete all files on your USB flash drive, so make sure you do not have any important files on the stick before doing this.
dd if=image.iso of=/dev/sdb bs=4M

dd for Windows

Note: Some users have an "isolinux.bin missing or corrupt" problem when booting the media with this method.

A GPL licensed dd version for Windows is available at http://www.chrysocome.net/dd. The advantage of this over Cygwin is a smaller download. Use it as shown in instructions for Cygwin above.

To begin, download the latest version of dd for Windows. Once downloaded, extract the archive's contents into Downloads or elsewhere.

Now, launch your command prompt as an administrator. Next, change directory (cd) into the Downloads directory.

If your Arch Linux ISO is elsewhere you may need to state the full path, for convenience you may wish to put the Arch Linux ISO into the same folder as the dd executable. The basic format of the command will look like this.

dd if=archlinux-2013-XX-xx-dual.iso of=\\.\x: bs=4m
Warning: This command will replace the drive's contents and its formatting with the ISO's. You will likely be unable to recover its contents in the event of an accidental copy. Be absolutely sure that you are directing dd to the correct drive before executing!

Simply replace the various null spots (indicated by an "x") with the correct date and correct drive letter.

Here is a complete example.

dd if=ISOs\archlinux-2013.08.01-dual.iso of=\\.\d: bs=4M

In Mac OS X

To be able to use dd on your USB device on a Mac you have to do some special maneuvers. First of all insert your usb device, OS X will automount it, and in Terminal.app run:

$ diskutil list

Figure out what your USB device is called with mount or sudo dmesg | tail (e.g. /dev/disk1) and unmount the partitions on the device (i.e., /dev/disk1s1) while keeping the device proper (i.e., /dev/disk1):

$ diskutil unmountDisk /dev/disk1

Now we can continue in accordance with the instructions above (but use bs=8192 if you are using the OS X dd, the number comes from 1024*8).

dd if=image.iso of=/dev/disk1 bs=8192
20480+0 records in
20480+0 records out
167772160 bytes transferred in 220.016918 secs (762542 bytes/sec)

It is probably a good idea to eject your drive before physical removal at this point:

$ diskutil eject /dev/disk1

How to restore the USB drive

Because the ISO image is a hybrid which can either be burned to a disc or directly written to a USB drive, it does not include a standard partition table.

After you install Arch Linux and you are done with the USB drive, you should zero out its first 512 bytes (meaning the boot code from the MBR and the non-standard partition table) if you want to restore it to full capacity:

# dd count=1 bs=512 if=/dev/zero of=/dev/sdx && sync

Then create a new partition table (e.g. "msdos") and filesystem (e.g. EXT4, FAT32) using gparted, or from a terminal:

  • For EXT2/3/4 (adjust accordingly), it would be:
# cfdisk /dev/sdx
# mkfs.ext4 /dev/sdx1
# e2label /dev/sdx1 USB_STICK
  • For FAT32, install the dosfstools package and run:
# cfdisk /dev/sdx
# mkfs.vfat -F32 /dev/sdx1
# dosfslabel /dev/sdx1 USB_STICK

Other Methods for BIOS systems

In GNU/Linux

Using UNetbootin

UNetbootin can be used on any Linux distribution or Windows to copy your iso to a USB device. However, Unetbootin overwrites syslinux.cfg, so it creates a USB device that does not boot properly. For this reason, Unetbootin is not recommended -- please use dd or one of the other methods discussed in this topic.

Warning: UNetbootin writes over the default syslinux.cfg; this must be restored before the USB device will boot properly.

Edit syslinux.cfg:

sysconfig.cfg
default menu.c32
prompt 0
menu title Archlinux Installer
timeout 100

label unetbootindefault
menu label Archlinux_x86_64
kernel /arch/boot/x86_64/vmlinuz
append initrd=/arch/boot/x86_64/archiso.img archisodevice=/dev/sdx1 ../../

label ubnentry0
menu label Archlinux_i686
kernel /arch/boot/i686/vmlinuz
append initrd=/arch/boot/i686/archiso.img archisodevice=/dev/sdx1 ../../

In /dev/sdx1 you must replace x with the first free letter after the last letter in use on the system where you are installing Arch Linux (e.g. if you have two hard drives, use c.). You can make this change during the first phase of boot by pressing Tab when the menu is shown.

In Windows

Win32 Disk Imager

Warning: This will destroy all information on your USB flash drive!

First, download the program from here. Next, extract the archive and run the executable. Now, select the Arch Linux ISO under the Image File section and the USB flash device letter (for example, [D:\]) under the Device section. Finally, click Write when ready.

Tip: By default, the Win32 Disk Imager's file-browser assumes disk image files end with a .img extension. However, you can simply change the Files of type drop-down list to *.* and continue on to selecting your Arch Linux ISO.
Note: After installation, you may need to restore the USB flash drive following a process as outlined here.

USBWriter for Windows

Download the program from http://sourceforge.net/projects/usbwriter/ and run it. Select the arch image file, the target USB stick, and click on the write button. Now you should be able to boot from the usb stick and install Arch Linux from it.

The Flashnul way

flashnul is an utility to verify the functionality and maintenance of Flash-Memory (USB-Flash, IDE-Flash, SecureDigital, MMC, MemoryStick, SmartMedia, XD, CompactFlash etc).

From a command prompt, invoke flashnul with -p, and determine which device index is your USB drive, e.g.:

C:\>flashnul -p
Avaible physical drives:
Avaible logical disks:
C:\
D:\
E:\

When you have determined which device is the correct one, you can write the image to your drive, by invoking flashnul with the device index, -L, and the path to your image, e.g:

C:\>flashnul E: -L path\to\arch.iso

As long as you are really sure you want to write the data, type yes, then wait a bit for it to write. If you get an access denied error, close any Explorer windows you have open.

If under Vista or Win7, you should open the console as administrator, or else flashnul will fail to open the stick as a block device and will only be able to write via the drive handle windows provides

Note: Confirmed that you need to use drive letter as opposed to number. flashnul 1rc1, Windows 7 x64.

Loading the installation media from RAM

This method uses Syslinux and a Ramdisk (MEMDISK) to load the entire Arch Linux ISO image into RAM. Since this will be running entirely from system memory, you will need to make sure the system you will be installing this on has an adequate amount. A minimum amount of RAM between 500 MB and 1 GB should suffice for a MEMDISK based, Arch Linux install.

For more information on Arch Linux system requirements as well as those for MEMDISK see the Beginners' Guide and here.

Tip: Once the installer has completed loading you can simply remove the USB stick and even use it on a different machine to start the process all over again. Utilizing MEMDISK also allows booting and installing Arch Linux to and from the same USB flash drive.
Preparing the USB flash drive

Begin by formatting the USB flash drive as FAT32. Then create the following folders on the newly formatted drive.

  • Boot
    • Boot/ISOs
    • Boot/Settings
Copy the needed files to the USB flash drive

Next copy the ISO that you would like to boot to the Boot/ISOs folder. After that, extract from the following files from the latest release of syslinux from here and copy them into the following folders.

  • ./win32/syslinux.exe to the Desktop or Downloads folder on your system.
  • ./memdisk/memdisk to the Settings folder on your USB flash drive.
Create the configuration file

After copying the needed files, navigate to the USB flash drive, /boot/Settings and create a syslinux.cfg file.

Warning: On the INITRD line, be sure to use the name of the ISO file that you copied to your ISOs folder!
/Boot/Settings/syslinux.cfg
DEFAULT arch_iso

LABEL arch_iso
        MENU LABEL Arch Setup
        LINUX memdisk
        INITRD /Boot/ISOs/archlinux-2013.08.01-dual.iso
        APPEND iso

For more information on Syslinux see the Arch Wiki article.

Final steps

Finally, create a *.bat file where syslinux.exe is located and run it ("Run as administrator" if you are on Vista or Windows 7):

C:\Documents and Settings\username\Desktop\install.bat
@echo off
syslinux.exe -m -a -d /Boot/Settings X:

Universal USB Installer

The Windows tool [1] can be used to quickly create a Live USB media with multiple Installers of many Linux distros. Once created, Installers can be added or removed without reformatting the USB drive.

Troubleshooting

  • For the MEMDISK Method, if you get the famous "30 seconds" error trying to boot the i686 version, press the Tab key over the Boot Arch Linux (i686) entry and add vmalloc=448M at the end. For reference: If your image is bigger than 128MiB and you have a 32-bit OS, then you have to increase the maximum memory usage of vmalloc. [2]
  • If you get the "30 seconds" error due to the /dev/disk/by-label/ARCH_XXXXXX not mounting, try renaming your USB media to ARCH_XXXXXX (e.g. ARCH_201302).

See Also