Installing Arch

From Mage
Jump to: navigation, search

How to install Arch Linux (shorter/much less thorough than the official).

Preparing media

First you'll need to go get Arch. Be kind and use the torrent. If you're installing Arch onto a virtual machine you can simply mount the ISO file. If you're installing Arch onto a physical machine you're probably going to want to transfer the ISO to media.


USB

Linux

Run the following command, replacing /dev/sdx with your drive, e.g. /dev/sdc. (Do not append a partition number, so do not use something like /dev/sdc1)

dd bs=4M if=/path/to/archlinux.iso of=/dev/sdx status=progress oflag=sync

This irrevocably destroys all data on /dev/sdx and writes an iso9660 filesystem signature to the drive. To restore it as an empty, usable storage device after using the Arch ISO image, remove the signature by running the following command as root, before repartitioning and reformatting the USB drive.

wipefs --all /dev/sdx


Windows

Rufus is a multi-purpose USB ISO writer. Simply select the Arch Linux ISO, the USB drive you want to create the bootable Arch Linux onto and click start.

Since Rufus does not care if the drive is properly formatted or not and provides a GUI it may be the easiest and most robust tool to use. Be sure to select DD image mode or the image will be transferred incorrectly.


CD/DVD

Linux

Install cdrtools.

pacman -S cdrtools

Replace /dev/sr0 with your CD/DVD/BR burner's location.

cdrecord -v -sao dev=/dev/sr0 archlinux.iso


Windows

On modern versions of Windows, right click the ISO image and click Burn disc image. For older versions, search is your friend.

Win burn arch.png



Create and format partitions

Once you've booted into the Arch ISO environment, you should check whether you're using UEFI mode by issuing the following command:

ls /sys/firmware/efi/efivars

If the directory does not exist, the system may be booted in BIOS or CSM mode. Refer to your motherboard's manual for details.


Your partition scheme is going to vary based on which mode your system is in. For BIOS machines I prefer to use the older MBR schema (unless the disk is over 2TB), while UEFI requires GPT. Any filesystems which users may fill should be separated from / such as /var and /home to maintain system stability in the event of user idiocy. For example if you know you're going to be hosting a user writable service under /srv/torrent, give it a partition of its own. Here are my bare minimum guidelines for a ~50GB hard drive, all partitions are ext4 unless otherwise noted:

  • UEFI
/boot/efi      # At least 100MB, must be FAT and set to EFI Partition
/              # 5GB+
/var           # 10GB+
/var/tmp       # 4GB+
/home          # Remainder of the disk space
  • BIOS
/boot          # At least 100MB
/              # 5GB+
/var           # 10GB+
/var/tmp       # 4GB+
/home          # Remainder of the disk space

You can use fdisk -l to list your recognized physical disks and fdisk /dev/sdX to make changes as necessary. LVM layouts are preferred for maintenance reasons later in the life of the machine. LVM is way more flexible and allows for some clever solutions to storage issues that can arise. Bootloaders may not like being on an LVM partition though, so we'll create a unique partition for it. Swap can be handled later by creating swap files . The following commands will create the layout and leave ~8GB (on a 50GB disk) to expand your LVMs as needed down the line.

  • UEFI
root@archiso ~ # fdisk /dev/sda
                 g       # Creates a new GPT partition table
                 n       # Create a new partition
                 1       # This will be the first partition
                 [Enter] # Accept the default - should allow adequate space for alignment
                 +512M   # Create a 512MiB /boot/efi partition
                 t       # Set the partition type
                 1       # The code for 'EFI System' partitions
                 n       # Create a new partition
                 2       # This will be the second partition
                 [Enter] # Accept the default
                 [Enter] # Consume the remainder of space on the drive
                 w       # Write these changes to the disk
root@archiso ~ # mkfs.fat -F32 /dev/sda1
root@archiso ~ # pvcreate /dev/sda2
root@archiso ~ # vgcreate vg_sys /dev/sda2
root@archiso ~ # lvcreate -L 7680M -n lv_root vg_sys       # 7.5GB /
root@archiso ~ # lvcreate -L 10240M -n lv_var vg_sys       # 10GB /var
root@archiso ~ # lvcreate -L 4096M -n lv_vartmp vg_sys     # 4GB /var/tmp
root@archiso ~ # lvcreate -L 20480M -n lv_home vg_sys      # 20GB /home
root@archiso ~ # mkfs -t ext4 -m 1 -v /dev/vg_sys/lv_root
root@archiso ~ # mkfs -t ext4 -m 1 -v /dev/vg_sys/lv_var
root@archiso ~ # mkfs -t ext4 -m 1 -v /dev/vg_sys/lv_vartmp
root@archiso ~ # mkfs -t ext4 -m 1 -v /dev/vg_sys/lv_home
  • BIOS
root@archiso ~ # fdisk /dev/sda
                 o       # Creates a new DOS/MBR partition table
                 n       # Create a new partition
                 p       # This will be a primary partition
                 1       # This will be the first partition
                 [Enter] # Accept the default - should allow adequate space for alignment
                 +512M   # Create a 512MiB /boot partition
                 a       # Set the bootable flag on the first partition
                 n       # Create a new partition
                 p       # This will be a primary partition
                 2       # This will be the second partition
                 [Enter] # Accept the default
                 [Enter] # Consume the remainder of space on the drive
                 w       # Write these changes to the disk
root@archiso ~ # mkfs -t ext4 -m 1 -v /dev/sda1
root@archiso ~ # pvcreate /dev/sda2
root@archiso ~ # vgcreate vg_sys /dev/sda2
root@archiso ~ # lvcreate -L 7680M -n lv_root vg_sys       # 7.5GB /
root@archiso ~ # lvcreate -L 10240M -n lv_var vg_sys       # 10GB /var
root@archiso ~ # lvcreate -L 4096M -n lv_vartmp vg_sys     # 4GB /var/tmp
root@archiso ~ # lvcreate -L 20480M -n lv_home vg_sys      # 20GB /home
root@archiso ~ # mkfs -t ext4 -m 1 -v /dev/vg_sys/lv_root
root@archiso ~ # mkfs -t ext4 -m 1 -v /dev/vg_sys/lv_var
root@archiso ~ # mkfs -t ext4 -m 1 -v /dev/vg_sys/lv_vartmp
root@archiso ~ # mkfs -t ext4 -m 1 -v /dev/vg_sys/lv_home




Mount the filesystems

Mount the filesystems to /mnt, and create mount points for any remaining partitions. For example:

  • UEFI
root@archiso ~ # mount /dev/vg_sys/lv_root /mnt
root@archiso ~ # mkdir -p /mnt/var /mnt/home /mnt/boot/efi
root@archiso ~ # mount /dev/sda1 /mnt/boot/efi
root@archiso ~ # mount /dev/vg_sys/lv_var /mnt/var
root@archiso ~ # mount /dev/vg_sys/lv_home /mnt/home
root@archiso ~ # mkdir /mnt/var/tmp
root@archiso ~ # mount /dev/vg_sys/lv_vartmp /mnt/var/tmp
  • BIOS
root@archiso ~ # mount /dev/vg_sys/lv_root /mnt
root@archiso ~ # mkdir /mnt/var /mnt/home /mnt/boot
root@archiso ~ # mount /dev/sda1 /mnt/boot
root@archiso ~ # mount /dev/vg_sys/lv_var /mnt/var
root@archiso ~ # mount /dev/vg_sys/lv_home /mnt/home
root@archiso ~ # mkdir /mnt/var/tmp
root@archiso ~ # mount /dev/vg_sys/lv_vartmp /mnt/var/tmp


Installation

Packages to be installed must be downloaded from mirror servers, which are defined in /etc/pacman.d/mirrorlist. Select a local one and disable/delete the others as this will greatly speed up your install in the following steps. This file will later be copied to the new system by pacstrap, so it's worth getting right.

Install the base packages

Use the pacstrap script to install the base package group:

pacstrap /mnt base

This group does not include all the tools from the live installation. You can append additional packages or groups such as dnsutils or net-tools to the pacstrap command. You can also install packages with pacman after the #Chroot step.



Configure the system

Fstab

Generate an fstab file (use -U or -L to define by UUID or labels, respectively):

genfstab -U /mnt >> /mnt/etc/fstab

Check the resulting file in /mnt/etc/fstab afterwards, and edit it in case of errors.


Chroot

Change root into the new system:

arch-chroot /mnt


Time zone

Set the time zone to your location. See the full current list under /usr/share/zoneinfo/. Here's an example for the US east coast:

ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime


Locale

Uncomment en_US.UTF-8 and other needed localizations in /etc/locale.gen, and generate them with:

locale-gen

Set the LANG variable in locale.conf accordingly, for example:

echo "LANG=en_US.UTF-8" > /etc/locale.conf


Network configuration

Create the hostname file:

echo "bar" > /etc/hostname

...and matching entries in /etc/hosts

127.0.0.1     localhost
127.0.1.1     bar.localdomain.local   bar

Don't forget to set an IP address if you need to.


Users and Passwords

Set the root password:

passwd

Add a new user to the system:

useradd foo
passwd foo
mkdir /home/foo
chown foo:foo /home/foo


Sudo

Don't kid yourself and just install it now.

pacman -S sudo

Add your user to the /etc/sudoers file.


Mkinitcpio LVM

Edit /etc/mkinitcpio.conf and set the HOOKS line to:

HOOKS=(base systemd udev autodetect modconf block sd-lvm2 filesystems keyboard fsck)

Then generate new kernel images by issuing:

mkinitcpio -p linux


Boot loader

Ignore the rest, stick with the best. Install GRUB .



Double check your settings

At this point you have a system that looks something like this:

Arch install final.png



Reboot

Exit the chroot environment by typing exit or pressing Ctrl + D.

(Optional) Manually unmount all the partitions with umount -R /mnt: this allows noticing any "busy" partitions, and finding the cause with fuser.

Finally, restart the machine by typing reboot. Any partitions still mounted will be automatically unmounted by systemd. Remember to remove the installation media and then login to the new system with your user account.

(Optional) Set your DNS configuration up in /etc/resolv.conf:

nameserver 192.168.1.1
nameserver 8.8.8.8
search localdomain.local
domain localdomain.local


Post-installation

See Linux and Networking for more tutorials on things to setup on your new system. Also check out Arch's General recommendations for more ideas.