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

From ArchWiki
Jump to: navigation, search
(Preparation)
m (Installation tweaks: fixed link)
 
(65 intermediate revisions by 25 users not shown)
Line 2: Line 2:
 
[[es:Installing Arch Linux on a USB key]]
 
[[es:Installing Arch Linux on a USB key]]
 
[[it:Installing Arch Linux on a USB key]]
 
[[it:Installing Arch Linux on a USB key]]
 +
[[ja:USB キーに Arch Linux をインストール]]
 
[[zh-CN:Installing Arch Linux on a USB key]]
 
[[zh-CN:Installing Arch Linux on a USB key]]
{{Article summary start}}
+
{{Related articles start}}
{{Article summary text|Guide to installing, configuring and using a full-featured Arch Linux system on a USB flash drive.}}
+
{{Related|Installation guide}}
{{Article summary heading|Related}}
+
{{Related|General recommendations}}
{{Article summary wiki|Beginners' Guide}}
+
{{Related|General troubleshooting}}
{{Article summary wiki|Installation Guide}}
+
{{Related articles end}}
{{Article summary wiki|General Recommendations}}
+
This page explains how to perform a regular Arch installation onto a USB key (or "flash drive"). In contrast to having a LiveUSB as covered in [[USB flash installation media]], the result will be a persistent installation identical to normal installation to HDD, but on a USB flash drive.
{{Article summary wiki|General Troubleshooting}}
+
{{Article summary end}}
+
  
This page explains how to perform a regular Arch installation onto a USB key (or "flash drive"). In contrast to having a LiveUSB as covered in [[USB Installation Media]], the result will be a persistent installation identical to normal installation to HDD, but on a USB flash drive.
+
== Installation ==
  
== Preparation ==
 
 
{{Note|At least 2 GiB of storage space is recommended. A modest set of packages will fit, leaving a little free space for storage.}}
 
{{Note|At least 2 GiB of storage space is recommended. A modest set of packages will fit, leaving a little free space for storage.}}
There are various ways of installing Arch on a USB stick, the simplest being from within Arch itself:
 
  
* If you are already running Arch, simply install {{Pkg|arch-install-scripts}} and proceed with the [https://wiki.archlinux.org/index.php/Installation_Guide Installation Guide] just like you would from the iso, but you will not be using /dev/sda. Use {{ic|lsblk}} to get the /dev/sd* name of your USB key prior to installation.
+
There are various ways of installing Arch on a USB stick, depending on the operating system you have available:
{{Warning|If you mistakingly format /dev/sda, you are likely to go about deleting everything on your hard drive.}}
+
* If you have another Linux computer available (it need not be Arch), you can follow the instructions at [[Install from existing Linux]].
* An Arch Linux CD/USB can be used to install Arch onto the USB key, via booting the CD/USB and following the [https://wiki.archlinux.org/index.php/Installation_Guide Installation Guide]. If booting from a Live USB, the installation will have to be made on a different USB stick.
+
* An Arch Linux CD/USB can be used to install Arch onto the USB key, via booting the CD/USB and following the [[installation guide]]. If booting from a Live USB, the installation will have to be made on a different USB stick.
* 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.
+
* If you run Windows or OS X, download VirtualBox, install VirtualBox Extensions, add the USB drive to a virtual machine running Arch (for example running from an iso), point the installation into the USB drive.
  
== Installation ==
+
=== Installation tweaks ===
Follow the [https://wiki.archlinux.org/index.php/Installation_Guide 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 ({{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.
+
Follow the [[installation guide]] as you normally would, with these exceptions:
* It is highly recommended to review the [https://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 without 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.
+
 
 +
* 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 ({{ic|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.
 +
* It is highly recommended to review the [[Improving_performance#Reduce_disk_reads.2Fwrites|reduce disk reads/writes]] wiki article prior to selecting a filesystem. To sum up, [http://fenidik.blogspot.com/2010/03/ext4-disable-journal.html ext4 without a journal] should be fine, which can be created with {{ic|# mkfs.ext4 -O "^has_journal" /dev/sdXX}}. The obvious drawback of using a filesystem with journaling disabled is data loss as a result of an ungraceful dismount. 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 forget the swap partition. Note that this does not affect installing onto a USB hard drive.
 
* Before creating the initial RAM disk {{ic|# mkinitcpio -p linux}}, in {{ic|/etc/mkinitcpio.conf}} add the {{ic|block}} hook to the hooks array right after udev. This is necessary for appropriate module loading in early userspace.
 
* Before creating the initial RAM disk {{ic|# mkinitcpio -p linux}}, in {{ic|/etc/mkinitcpio.conf}} add the {{ic|block}} hook to the hooks array right after udev. This is necessary for appropriate module loading in early userspace.
 +
* If you want to be able to continue to use the UFD device as a cross-platform removable drive, this can be accomplished by creating a partition housing an appropriate file system (most likely NTFS or exFAT). Note that the data partition may need to be the first partition on the device, as Windows assumes that there can only be one partition on a removable device, and will happily automount an EFI system partition otherwise. Remember to install {{Pkg|dosfstools}} and {{Pkg|ntfs-3g}}. Some tools are available online that may allow you to flip the removable media bit on your UFD device. This would trick operating systems into treating your UFD device as an external hard disk and allow you to use whichever partitioning scheme you choose.
 +
{{Warning|It is not possible to flip the removable media bit on every UFD device and attempting to use software that is incompatible with your device may damage it. Attempting to flip the removable media bit is '''not''' recommended.}}
 +
 +
* Install [[NetworkManager]] to control networks, it supports changing interface names of different hardware.
  
 
== Configuration ==
 
== Configuration ==
 +
 
* 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:
 
* 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:
  
 
To get the proper UUIDs for your partitions issue '''blkid'''
 
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 {{ic|hd0,0}}.
 +
* It seems that current versions of GRUB will automatically default to using uuid. The following directions are for GRUB legacy.
 +
}}
  
{{Note|When grub is installed on the USB key, the key will always be hd0,0}}
+
=== GRUB legacy ===
  
{{Note|It seems that current versions of GRUB2 will automatically default to using uuid. The following directions are for GRUB legacy}}
+
{{ic|menu.lst}}, the GRUB legacy configuration file, should be edited to (loosely) match the following:
 
+
With the static {{ic|/dev/sda''X''}}:
With the static /dev/sdaX:
+
  
 
  root (hd0,0)
 
  root (hd0,0)
Line 58: Line 63:
 
  kernel /boot/vmlinuz-linux root=/dev/disk/by-uuid/3a9f8929-627b-4667-9db4-388c4eaaf9fa ro
 
  kernel /boot/vmlinuz-linux root=/dev/disk/by-uuid/3a9f8929-627b-4667-9db4-388c4eaaf9fa ro
 
  initrd /boot/initramfs-linux.img
 
  initrd /boot/initramfs-linux.img
 +
 +
=== GRUB ===
 +
 +
On GPT with UEFI installations, make sure you follow the instructions on [[GRUB#UEFI systems]] and include the --removable option as doing otherwise may break existing GRUB installations, as in the below command:
 +
 +
# grub-install --target=x86_64-efi --efi-directory=$esp --bootloader-id=grub '''--removable''' --recheck
 +
 +
=== Syslinux ===
 +
 +
With the static {{ic|/dev/sda''X''}}:
 +
 +
LABEL Arch
 +
        MENU LABEL Arch Linux
 +
        LINUX ../vmlinuz-linux
 +
        APPEND root=/dev/sdax ro
 +
        INITRD ../initramfs-linux.img
 +
 +
Using your UUID:
 +
 +
LABEL Arch
 +
        MENU LABEL Arch Linux
 +
        LINUX ../vmlinuz-linux
 +
        APPEND root=UUID=3a9f8929-627b-4667-9db4-388c4eaaf9fa ro
 +
        INITRD ../initramfs-linux.img
  
 
== Tips ==
 
== Tips ==
  
=== Painless boot on different machines without using UUID ===
+
=== Using your USB install on multiple machines ===
  
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:
+
==== Architecture ====
  
# (0) Arch Linux
+
For the most versatile compatibility it is recommended that you install the i686 architecture because it will run on both 32-bit (i686) and 64-bit (x86_64) architectures.
title  Arch Linux (first drive)
+
root  (hd0,0)
+
kernel /boot/vmlinuz-linux root=/dev/sda1 ro
+
initrd /boot/initramfs-linux.img
+
  
As well as
+
Additionally, due to the reduced size of 32-bit binaries and the absence of (possible) multilib packages, an i686 installation typically consumes less space than an equivalent x86_64 one.
  
# (1) Arch Linux
+
{{Note|Chrooting into a 64-bit Linux installation (eg. when using the USB key as install/rescue media) is only possible from x86_64 Arch.}}
title  Arch Linux (second drive)
+
 
root  (hd0,0)
+
==== Input drivers ====
kernel /boot/vmlinuz-linux root=/dev/sdb1 ro
+
 
initrd /boot/initramfs-linux.img
+
For laptop use (or use with a tactile screen) you will need the {{Pkg|xf86-input-synaptics}} package for the touchpad/touchscreen to work.
 +
 
 +
For instructions on fine tuning or troubleshooting touchpad issues, see the [[Touchpad Synaptics]] article.
 +
 
 +
==== Video drivers ====
 +
 
 +
{{Note|The use of proprietary video drivers is '''not''' recommended for this type of installation.}}
 +
 
 +
To support most common GPUs, install {{Pkg|xf86-video-vesa}}, {{Pkg|xf86-video-ati}}, {{Pkg|xf86-video-intel}}, and {{Pkg|xf86-video-nouveau}}.
 +
 
 +
==== Persistent block device naming ====
 +
 
 +
It is recommended to use [[UUID]] in both [[fstab]] and bootloader configuration. See [[Persistent block device naming]] for details.
 +
 
 +
Alternatively, you may create udev rule to create custom symlink for your usb key. Then use this symlink in fstab and bootloader configuration. See [[udev#Setting static device names]] for details.
 +
 
 +
==== Kernel parameters ====
 +
 
 +
You may want to disable KMS for various reasons, such as getting a blank screen or a "no signal" error from the display, when using some Intel video cards, etc. To disable KMS, add {{ic|nomodeset}} as a kernel parameter. See [[Kernel parameters]] for more info.
 +
 
 +
{{Warning|Some [[Xorg]] drivers will not work with KMS disabled. See the wiki page on your specific driver for details. Nouveau in particular needs KMS to determine the correct display resolution. If you add {{ic|nomodeset}} as a kernel parameter as a preemptive measure you may have to adjust the display resolution manually when using machines with Nvidia video cards. See [[Xrandr]] for more info.}}
 +
 
 +
==== Booting from USB 3 media ====
 +
 
 +
See [http://www.wyae.de/docs/boot-usb3/].
 +
 
 +
=== Compatibility ===
 +
 
 +
The fallback image should be used for maximum compatibility.
 +
 
 +
=== Minimizing disk access ===
 +
 
 +
* You may want to configure [[Systemd#Journal|journald]] to store its journals in RAM, e.g. by creating a custom configuration file:
 +
 
 +
{{hc|/etc/systemd/journald.conf.d/usbstick.conf|2=
 +
[Journal]
 +
Storage=volatile
 +
RuntimeMaxUse=30M
 +
}}
  
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.
+
* To disable {{ic|fsync}} and related system calls in web browsers and other applications that do not write essential data, use the ''eatmydata'' command from {{AUR|libeatmydata}} to avoid such system calls:
  
* Run {{ic|udevinfo -p /sys/block/sdx/ -a}} (where sdx is the device name of your usb key)
+
$ eatmydata firefox
* 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.
+
  
=== Optimizing for the lifespan of flash memory ===
+
== See also ==
* 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.
+
  
== See Also ==
 
* [[Official Arch Linux Install Guide]]
 
 
* [[Installing Arch Linux from VirtualBox]]
 
* [[Installing Arch Linux from VirtualBox]]
 
* [[Solid State Drives]]
 
* [[Solid State Drives]]

Latest revision as of 22:26, 1 October 2016

This page explains how to perform a regular Arch installation onto a USB key (or "flash drive"). In contrast to having a LiveUSB as covered in USB flash installation media, the result will be a persistent installation identical to normal installation to HDD, but on a USB flash drive.

Installation

Note: At least 2 GiB of storage space is recommended. A modest set of packages will fit, leaving a little free space for storage.

There are various ways of installing Arch on a USB stick, depending on the operating system you have available:

  • If you have another Linux computer available (it need not be Arch), you can follow the instructions at Install from existing Linux.
  • An Arch Linux CD/USB can be used to install Arch onto the USB key, via booting the CD/USB and following the installation guide. If booting from a Live USB, the installation will have to be made on a different USB stick.
  • If you run Windows or OS X, download VirtualBox, install VirtualBox Extensions, add the USB drive to a virtual machine running Arch (for example running from an iso), point the installation into the USB drive.

Installation tweaks

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 (Alt+F2), 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 reduce disk reads/writes wiki article prior to selecting a filesystem. To sum up, ext4 without a journal should be fine, which can be created with # mkfs.ext4 -O "^has_journal" /dev/sdXX. The obvious drawback of using a filesystem with journaling disabled is data loss as a result of an ungraceful dismount. 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 forget the 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 block hook to the hooks array right after udev. This is necessary for appropriate module loading in early userspace.
  • If you want to be able to continue to use the UFD device as a cross-platform removable drive, this can be accomplished by creating a partition housing an appropriate file system (most likely NTFS or exFAT). Note that the data partition may need to be the first partition on the device, as Windows assumes that there can only be one partition on a removable device, and will happily automount an EFI system partition otherwise. Remember to install dosfstools and ntfs-3g. Some tools are available online that may allow you to flip the removable media bit on your UFD device. This would trick operating systems into treating your UFD device as an external hard disk and allow you to use whichever partitioning scheme you choose.
Warning: It is not possible to flip the removable media bit on every UFD device and attempting to use software that is incompatible with your device may damage it. Attempting to flip the removable media bit is not recommended.
  • Install NetworkManager to control networks, it supports changing interface names of different hardware.

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

Note:
  • When GRUB is installed on the USB key, the key will always be hd0,0.
  • It seems that current versions of GRUB will automatically default to using uuid. The following directions are for GRUB legacy.

GRUB legacy

menu.lst, the GRUB legacy configuration file, should be edited to (loosely) match the following: 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

GRUB

On GPT with UEFI installations, make sure you follow the instructions on GRUB#UEFI systems and include the --removable option as doing otherwise may break existing GRUB installations, as in the below command:

# grub-install --target=x86_64-efi --efi-directory=$esp --bootloader-id=grub --removable --recheck

Syslinux

With the static /dev/sdaX:

LABEL Arch
        MENU LABEL Arch Linux
        LINUX ../vmlinuz-linux
        APPEND root=/dev/sdax ro
        INITRD ../initramfs-linux.img

Using your UUID:

LABEL Arch
        MENU LABEL Arch Linux
        LINUX ../vmlinuz-linux
        APPEND root=UUID=3a9f8929-627b-4667-9db4-388c4eaaf9fa ro
        INITRD ../initramfs-linux.img

Tips

Using your USB install on multiple machines

Architecture

For the most versatile compatibility it is recommended that you install the i686 architecture because it will run on both 32-bit (i686) and 64-bit (x86_64) architectures.

Additionally, due to the reduced size of 32-bit binaries and the absence of (possible) multilib packages, an i686 installation typically consumes less space than an equivalent x86_64 one.

Note: Chrooting into a 64-bit Linux installation (eg. when using the USB key as install/rescue media) is only possible from x86_64 Arch.

Input drivers

For laptop use (or use with a tactile screen) you will need the xf86-input-synaptics package for the touchpad/touchscreen to work.

For instructions on fine tuning or troubleshooting touchpad issues, see the Touchpad Synaptics article.

Video drivers

Note: The use of proprietary video drivers is not recommended for this type of installation.

To support most common GPUs, install xf86-video-vesa, xf86-video-ati, xf86-video-intel, and xf86-video-nouveau.

Persistent block device naming

It is recommended to use UUID in both fstab and bootloader configuration. See Persistent block device naming for details.

Alternatively, you may create udev rule to create custom symlink for your usb key. Then use this symlink in fstab and bootloader configuration. See udev#Setting static device names for details.

Kernel parameters

You may want to disable KMS for various reasons, such as getting a blank screen or a "no signal" error from the display, when using some Intel video cards, etc. To disable KMS, add nomodeset as a kernel parameter. See Kernel parameters for more info.

Warning: Some Xorg drivers will not work with KMS disabled. See the wiki page on your specific driver for details. Nouveau in particular needs KMS to determine the correct display resolution. If you add nomodeset as a kernel parameter as a preemptive measure you may have to adjust the display resolution manually when using machines with Nvidia video cards. See Xrandr for more info.

Booting from USB 3 media

See [1].

Compatibility

The fallback image should be used for maximum compatibility.

Minimizing disk access

  • You may want to configure journald to store its journals in RAM, e.g. by creating a custom configuration file:
/etc/systemd/journald.conf.d/usbstick.conf
[Journal]
Storage=volatile
RuntimeMaxUse=30M
  • To disable fsync and related system calls in web browsers and other applications that do not write essential data, use the eatmydata command from libeatmydataAUR to avoid such system calls:
$ eatmydata firefox

See also