Difference between revisions of "Installing Arch Linux on a USB key"

From ArchWiki
Jump to: navigation, search
m (typeo)
(Installation)
(44 intermediate revisions by 23 users not shown)
Line 1: Line 1:
[[Category:Getting and installing Arch (English)]]
+
[[Category:Getting and installing Arch]]
[[Category:HOWTOs (English)]]
+
[[it:Installing Arch Linux on a USB key]]
== Grab a USB key ==
+
[[zh-CN:Installing Arch Linux on a USB key]]
If installing KDE and a large amount of applications, 3 GiB is the recommended minimum. GNOME and Xfce4, along with a typical set of packages for a desktop (GIMP, Pidgin, OpenOffice, Firefox, flashplugin) can be installed on a 2 GiB stick, leaving a small amount of room for user data.
+
{{Out of date|Should be updated to reflect changes in provided bootloaders and installation instructions.}}
  
== Grab CD ==
+
This page discusses how to perform a regular Arch installation onto a USB key (or "flash drive"). The result will be a system that will be updated through normal use. Consider whether you're instead interested in [[USB Installation Media]].
An Arch Linux CD can be used to install Arch onto the USB key, via booting the CD and installing using the regular method. Or, if you have another linux computer available (it needs not be Arch), you can follow the instructions to [[Install Arch from within another distro]], and then skip to the configuration section.
+
  
== Boot ==  
+
== Grab a big enough USB key ==
It may be necessary to boot with the arch-noscsi kernel, if the usb-storage module gives errors when loaded with the standard kernel. After the system has booted, modprobe sd_mod and usb_storage (There are reports that the 7.2 CD contains no sd_mod; simply omit loading this module, as you can safely proceed without it). The USB key will appear in a few moments, after the device has settled. dmesg will show a device scan once the device has settled:
+
If installing KDE and a large amount of applications, 3 GiB is the recommended minimum. GNOME and Xfce4, along with a typical set of packages for a desktop (GIMP, Pidgin, OpenOffice, Firefox, flashplugin) can be installed on a 2 GiB stick, leaving a small amount of room for user data.  
  
usbcore: registered new interface driver usb-storage
+
== Install from... ==
usb-storage: device found at 4
+
* An Arch Linux CD can be used to install Arch onto the USB key, via booting the CD and following the [https://wiki.archlinux.org/index.php/Installation_Guide Installation Guide].
usb-storage: waiting for device to settle before scanning
+
* Or, if you have another linux computer available (it need not be Arch), you can follow the instructions to [[Install_from_Existing_Linux|install from existing linux]], and then skip to the configuration section.
USB Mass Storage support registered.
+
* In case you are already running Arch, simply install {{Pkg|arch-install-scripts}} and then install just like you would from the iso, but you will not be using /dev/sda, most likely it will be /dev/sdb. (Be very careful. You don't want to go about deleting everyting on your hard drive)
scsi 6:0:0:0: Direct-Access    Generic  STORAGE DEVICE  9407 PQ: 0 ANSI: 0
+
sd 6:0:0:0: [sdc] 3994624 512-byte hardware sectors (2045 MB)
+
sd 6:0:0:0: [sdc] Write Protect is off
+
sd 6:0:0:0: [sdc] Mode Sense: 03 00 00 00
+
sd 6:0:0:0: [sdc] Assuming drive cache: write through
+
sd 6:0:0:0: [sdc] 3994624 512-byte hardware sectors (2045 MB)
+
sd 6:0:0:0: [sdc] Write Protect is off
+
sd 6:0:0:0: [sdc] Mode Sense: 03 00 00 00
+
sd 6:0:0:0: [sdc] Assuming drive cache: write through
+
  sdc: sdc1
+
sd 6:0:0:0: [sdc] Attached SCSI removable disk
+
sd 6:0:0:0: Attached scsi generic sg3 type 0
+
usb-storage: device scan complete
+
 
+
It is the sdX: sdXY line that is important, as it shows the device name (in this case, sdc) and the partitions available on it (in this case, one, sdc1), if any.
+
  
 
== Installation ==
 
== Installation ==
  
Launch the installer (/arch/setup). The setup process can be done normally, with only a few pointers:
+
Follow the [https://wiki.archlinux.org/index.php/Installation_Guide Installation Guide] as you normally would, with these exceptions:
  
* It is best to manually partition the drive, as the auto partition may not work, and will create unnecessary partitions.
+
* If cfdisk fails with "Partition ends in the final partial cylinder" fatal error, the only way to proceed is to kill all partitions on the drive. Open another terminal ({{keypress|Alt+F2}}), type {{ic|fdisk /dev/sdX}} (where {{ic|sdX}} is your usb drive), print partition table (p), check that it's ok, delete it (d) and write changes (w). Now return to cfdisk.
* ext2 is the best option for use with a flash based storage medium, such as a USB key. Flash has a limited number of writes, and a journaling file system will use up these writes considerably faster than a non-journaled filesystem, which will greatly reduce the lifespan of the key. For this same reason, it is best to forgo a swap partition. Note that this does not effect installing onto a USB hard drive.
+
* It is highly recommended to review the [http://wiki.archlinux.org/index.php/SSD#Tips_for_Minimizing_SSD_Read.2FWrites Tips for Minimizing SSD Read/Writes] on the [[SSD]] wiki article prior to selecting a filesystem.  To sum up, ext4 with a journal should be fine. Recognize that flash has a limited number of writes, and a journaling file system will take some of these as the journal is updated. For this same reason, it is best to forgo a swap partition. Note that this does not affect installing onto a USB hard drive.
* When it asks you whether you want USB boot support, choose ''yes''.
+
* Before creating the initial RAM disk {{ic|# mkinitcpio -p linux}}, in {{ic|/etc/mkinitcpio.conf}} add the {{ic|usb}} hook to the hooks array right after udev. This is necessary for appropriate module loading in early userspace.
  
 
== Configuration ==
 
== Configuration ==
* Make sure that /etc/fstab includes the correct partition information for /, and for any other partitions on the USB key. Keep in mind the setup of the target machine when putting in the device names, as they may be different from the machine you are using for the installation. Example: if the installation machine has one hard drive, your USB key will likely be sdb. The target machine, however, may have no hard drives, in which case your USB key will likely be sda.
+
* Make sure that {{ic|/etc/fstab}} includes the correct partition information for {{ic|/}}, and for any other partitions on the USB key. If the usb key is to be booted on several machines, it is quite likely that devices and number of available hard disks vary. So it is advised to use UUID or label:
  
* menu.lst, the Grub configuration file, should be edited to (loosely) match the following, replacing sda1 with the partition of the key on the target machine (note that, as grub is installed on the USB key, the key will always be hd0,0).
+
To get the proper UUIDs for your partitions issue '''blkid'''
 +
 
 +
* menu.lst, the Grub configuration file, should be edited to (loosely) match the following:
 +
 
 +
{{Note|When grub is installed on the USB key, the key will always be hd0,0}}
 +
 
 +
{{Note|It seems that current versions of GRUB2 will automatically default to using uuid. The following directions are for GRUB legacy}}
 +
 
 +
With the static /dev/sdaX:
  
 
  root (hd0,0)
 
  root (hd0,0)
  kernel /boot/vmlinuz26 root=/dev/sda1 ro vga=773
+
  kernel /boot/vmlinuz-linux root=/dev/sda1 ro
  initrd /boot/kernel26.img
+
  initrd /boot/initramfs-linux.img
  
* Regenerate the initrd image, kernel26.img. Edit /etc/mkinitcpio.conf, changing the hooks to include (at a minimum): "base ide usb filesystems" ('''''Note:''' if using the 7.2 CD, and installing from the CD, you will have mkinitrd instead of mkinitcpio. During the configuration, you will be asked to edit mkinitrd.conf; simply change REMOVE_USB=1 to REMOVE_USB=0 and ignore the following command''). Then rebuild the image by issuing:
+
When using label your menu.lst should look like this:
# mkinitcpio -k 2.6.25-ARCH -c /etc/mkinitcpio.conf -g /boot/kernel26.img.
+
  
'''''Note:''' The kernel version (-k) must be the kernel version in the USB key, not the live cd's kernel version.''
+
root (hd0,0)
 +
kernel /boot/vmlinuz-linux root=/dev/disk/by-label/'''Arch''' ro
 +
initrd /boot/initramfs-linux.img
  
== Tips ==
+
And for UUID, it should be like this:
=== Using UUID ===
+
Instead of using literal partition names, you can also use the [[UUID]] of your partition. This way is much better and more manageable in a setup where the USB drive is meant to boot at multiple PC's than using the partition literal names (/dev/sdb1). Run:
+
$ blkid
+
to find out which one points to the regular device node (ie, /dev/sdb1) that is your key.
+
  
Now you can place this device node (in the form <code>UUID=7bf1d942-7b8c-4fb7-b55a-d3c40895906d</code>) into /etc/fstab in place of the regular node (ie, /dev/sdb1). Edit also your <code>kernel</code> line in menu.lst, so it will contain something like:
+
root (hd0,0)
  kernel /boot/vmlinuz26 '''root=/dev/disk/by-uuid/7bf1d942-7b8c-4fb7-b55a-d3c40895906d''' ro vga=733
+
  kernel /boot/vmlinuz-linux root=/dev/disk/by-uuid/3a9f8929-627b-4667-9db4-388c4eaaf9fa ro
 +
initrd /boot/initramfs-linux.img
  
'''''Note:''' The files may contain UUID's already.''
+
== Tips ==
  
 
=== Painless boot on different machines without using UUID ===
 
=== Painless boot on different machines without using UUID ===
 +
 
When using the USB key on various target machines, it is helpful to have multiple entries in GRUB, for machines with different setups. For example, the GRUB configuration could contain:
 
When using the USB key on various target machines, it is helpful to have multiple entries in GRUB, for machines with different setups. For example, the GRUB configuration could contain:
  
Line 69: Line 60:
 
  title  Arch Linux (first drive)
 
  title  Arch Linux (first drive)
 
  root  (hd0,0)
 
  root  (hd0,0)
  kernel /boot/vmlinuz26 root=/dev/sda1 ro
+
  kernel /boot/vmlinuz-linux root=/dev/sda1 ro
  initrd /boot/kernel26.img
+
  initrd /boot/initramfs-linux.img
  
 
As well as
 
As well as
Line 77: Line 68:
 
  title  Arch Linux (second drive)
 
  title  Arch Linux (second drive)
 
  root  (hd0,0)
 
  root  (hd0,0)
  kernel /boot/vmlinuz26 root=/dev/sdb1 ro
+
  kernel /boot/vmlinuz-linux root=/dev/sdb1 ro
  initrd /boot/kernel26.img
+
  initrd /boot/initramfs-linux.img
 +
 
 +
And so forth, giving you the option to select a configuration for a wider variety of machines. However, changing the {{ic|1=root=}} option in GRUB does not change {{ic|/etc/fstab}} and you must do something (in our example using udev symlink), so the root partition will always be mounted correctly.
  
And so forth, giving you the option to select a configuration for a wider variety of machines. However, changing the <code>root=</code> option in GRUB does not change /etc/fstab and you must do something (in our example using udev symlink), so the root partition will always be mounted correctly.
+
* Run {{ic|udevinfo -p /sys/block/sdx/ -a}} (where sdx is the device name of your usb key)
 +
* Find unique information pertaining to your usb key. I chose {{ic|1=SYSFS{model}=="DataTraveler 2.0"}}
 +
* Make a new file: {{ic|/etc/udev/udev.rules/10-my-usb-key.rules}} and insert:
 +
:{{bc|1= KERNEL=="sd**", SYSFS{product}=="DataTraveler 2.0", SYMLINK+="WHATEVERYOUWANTOTCALLIT%n"}}
 +
:({{ic|1=KERNEL=="sd**"}} is because the kernel - 2.6.16 here - names all usb devices sd as it uses the scsi sub-system and you want to look at every sd device and apply the setting to every partition), with {{ic|1=SYSFS{model}==}} being the unique identifier collected from udevinfo.
 +
* Run {{ic|/etc/start-udev uevents}} and make sure the symlinks appears in {{ic|/dev}}.
 +
* If so, edit {{ic|/etc/fstab}}, replacing your old sdx with the new symlinks.
  
* Run <code>udevinfo -p /sys/block/sdx/ -a</code> (where sdx is the device name of your usb key)
+
=== Optimizing for the lifespan of flash memory ===
* Find unique information pertaining to your usb key. I chose `<code>SYSFS{model}=="DataTraveler 2.0"</code>`
+
* Again, it is highly recommended to review the [[SSD#Tips_for_Minimizing_SSD_Read.2FWrites |Tips for Minimizing SSD Read/Writes]] on the [[SSD]] wiki article.
* Make a new file: /etc/udev/udev.rules/10-my-usb-key.rules and insert: <code>KERNEL=="sd**", SYSFS{product}=="DataTraveler 2.0", SYMLINK+="WHATEVERYOUWANTOTCALLIT%n"</code> (<code>KERNEL=="sd**"</code> is because the kernel - 2.6.16 here - names all usb devices sd as it uses the scsi sub-system and you want to look at every sd device and apply the setting to every partition), with <code>SYSFS{model}==</code> being the unique identifier collected from udevinfo.
+
* Run <code>/etc/start-udev uevents</code> and make sure the symlinks appears in /dev.
+
* If so, edit /etc/fstab, replacing your old sdx with the new symlinks.
+
  
 
== See Also ==
 
== See Also ==
 
* [[Official Arch Linux Install Guide]]
 
* [[Official Arch Linux Install Guide]]
 
* [[Installing Arch Linux from VirtualBox]]
 
* [[Installing Arch Linux from VirtualBox]]
 +
* [[Solid State Drives]]

Revision as of 22:29, 20 October 2012

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: Should be updated to reflect changes in provided bootloaders and installation instructions. (Discuss in Talk:Installing Arch Linux on a USB key#)

This page discusses how to perform a regular Arch installation onto a USB key (or "flash drive"). The result will be a system that will be updated through normal use. Consider whether you're instead interested in USB Installation Media.

Grab a big enough USB key

If installing KDE and a large amount of applications, 3 GiB is the recommended minimum. GNOME and Xfce4, along with a typical set of packages for a desktop (GIMP, Pidgin, OpenOffice, Firefox, flashplugin) can be installed on a 2 GiB stick, leaving a small amount of room for user data.

Install from...

  • An Arch Linux CD can be used to install Arch onto the USB key, via booting the CD and following the Installation Guide.
  • Or, if you have another linux computer available (it need not be Arch), you can follow the instructions to install from existing linux, and then skip to the configuration section.
  • In case you are already running Arch, simply install arch-install-scripts and then install just like you would from the iso, but you will not be using /dev/sda, most likely it will be /dev/sdb. (Be very careful. You don't want to go about deleting everyting on your hard drive)

Installation

Follow the Installation Guide as you normally would, with these exceptions:

  • If cfdisk fails with "Partition ends in the final partial cylinder" fatal error, the only way to proceed is to kill all partitions on the drive. Open another terminal (Template:Keypress), type fdisk /dev/sdX (where sdX is your usb drive), print partition table (p), check that it's ok, delete it (d) and write changes (w). Now return to cfdisk.
  • It is highly recommended to review the Tips for Minimizing SSD Read/Writes on the SSD wiki article prior to selecting a filesystem. To sum up, ext4 with a journal should be fine. Recognize that flash has a limited number of writes, and a journaling file system will take some of these as the journal is updated. For this same reason, it is best to forgo a swap partition. Note that this does not affect installing onto a USB hard drive.
  • Before creating the initial RAM disk # mkinitcpio -p linux, in /etc/mkinitcpio.conf add the usb hook to the hooks array right after udev. This is necessary for appropriate module loading in early userspace.

Configuration

  • Make sure that /etc/fstab includes the correct partition information for /, and for any other partitions on the USB key. If the usb key is to be booted on several machines, it is quite likely that devices and number of available hard disks vary. So it is advised to use UUID or label:

To get the proper UUIDs for your partitions issue blkid

  • menu.lst, the Grub configuration file, should be edited to (loosely) match the following:
Note: When grub is installed on the USB key, the key will always be hd0,0
Note: It seems that current versions of GRUB2 will automatically default to using uuid. The following directions are for GRUB legacy

With the static /dev/sdaX:

root (hd0,0)
kernel /boot/vmlinuz-linux root=/dev/sda1 ro
initrd /boot/initramfs-linux.img

When using label your menu.lst should look like this:

root (hd0,0)
kernel /boot/vmlinuz-linux root=/dev/disk/by-label/Arch ro
initrd /boot/initramfs-linux.img

And for UUID, it should be like this:

root (hd0,0)
kernel /boot/vmlinuz-linux root=/dev/disk/by-uuid/3a9f8929-627b-4667-9db4-388c4eaaf9fa ro
initrd /boot/initramfs-linux.img

Tips

Painless boot on different machines without using UUID

When using the USB key on various target machines, it is helpful to have multiple entries in GRUB, for machines with different setups. For example, the GRUB configuration could contain:

# (0) Arch Linux
title  Arch Linux (first drive)
root   (hd0,0)
kernel /boot/vmlinuz-linux root=/dev/sda1 ro
initrd /boot/initramfs-linux.img

As well as

# (1) Arch Linux
title  Arch Linux (second drive)
root   (hd0,0)
kernel /boot/vmlinuz-linux root=/dev/sdb1 ro
initrd /boot/initramfs-linux.img

And so forth, giving you the option to select a configuration for a wider variety of machines. However, changing the root= option in GRUB does not change /etc/fstab and you must do something (in our example using udev symlink), so the root partition will always be mounted correctly.

  • Run udevinfo -p /sys/block/sdx/ -a (where sdx is the device name of your usb key)
  • Find unique information pertaining to your usb key. I chose SYSFS{model}=="DataTraveler 2.0"
  • Make a new file: /etc/udev/udev.rules/10-my-usb-key.rules and insert:
KERNEL=="sd**", SYSFS{product}=="DataTraveler 2.0", SYMLINK+="WHATEVERYOUWANTOTCALLIT%n"
(KERNEL=="sd**" is because the kernel - 2.6.16 here - names all usb devices sd as it uses the scsi sub-system and you want to look at every sd device and apply the setting to every partition), with SYSFS{model}== being the unique identifier collected from udevinfo.
  • Run /etc/start-udev uevents and make sure the symlinks appears in /dev.
  • If so, edit /etc/fstab, replacing your old sdx with the new symlinks.

Optimizing for the lifespan of flash memory

See Also