Tuesday, March 20, 2012

How To: Install Arch Linux

Update: Some of the steps here are now deprecated.

Today I started a new position as a Software Developer at NTI Leeds. I'm going to be working on Android projects initially but may move on to iPhone development later in the year. As with most first days I spent some time setting up a development environment.

The machine I am using is a pretty average hardware spec, so I decided to install Arch Linux as it's supposedly pretty good for performance.

Arch Linux is a lightweight rolling-release distribution, that is to say that once it is installed the the system can be continually updated to keep up with the latest version rather than a new version being released periodically as is commonly done with other distros such as Ubuntu or Fedora. As Arch Linux can be a little more daunting for new users I have documented some steps on this page which I use for my system. As I use a 64-bit system and am in the UK some of these steps may need to be changed depending on your requirements. Additional help can be found on the Arch Linux Wiki.

Some steps to take during the Arch Linux Installation:

Most of the steps required can be found on the Official Installation Guide. Once the install cd has been booted you can start the installation process by using:
/arch/setup

Partitioning the Hard Drives:

When partitioning the hard drive I opted for setting fixed partitions using the Ext4 filesystem (it's a bit too soon to use Btrfs). On hindsight I think I would have been better off using LVM (Logical Volume Manager) and will do so next time. If you intend to do development work you may find /usr/lib taking up a lot of space. Also, ~/.pacmanCache can grow fairly large so it's a good idea to give yourself enough space. The installer uses the following defaults:
  • 32 MB ext2 /boot partition
  • 256 MB swap partition
  • 7.5 GB root partition
  • /home partition with the remaining space
Disk space is cheap so something like this is fine:
  • 32 MB ext2 /boot partition
  • 512 MB swap partition
  • 15 GB ext4 root partition
  • /home ext4 partition with the remaining space

Locale:

Some localization information is kept in /etc/rc.conf. This file is the main configuration file for the system so you will need to return here fairly often to change settings. For the UK make sure the LOCALIZATION block in /etc/rc.conf looks like the following:
# LOCALIZATION
# ------------
HARDWARECLOCK="UTC" 
TIMEZONE="Europe/London" 
KEYMAP="uk" 
CONSOLEFONT=
CONSOLEMAP=
LOCALE="en_GB.utf8" 
DAEMON_LOCALE="yes" 
USECOLOR="yes"
Now create the following file /etc/locale.conf and add the following:
LANG=en_GB.UTF-8
LC_MESSAGES=C
A list of available locales is stored in /etc/locale.gen. Edit the file and uncomment the lines for UK then save and exit the file (keep the US also as a fallback):
en_GB.UTF-8 UTF-8
en_GB ISO-8859-1
en_US.UTF-8 UTF-8
en_US ISO-8859-1
Once this is done you need to run locale-gen as the root user

Arch Linux Post Installation:

Once your new system has been installed it's time to start configuring it. First you'll need need some packages. Packages are installed on Arch Linux using pacman:
pacman -S 
Before we start installing any packages make sure that pacman is downloading packages from servers in your location by editing /etc/pacman.d/mirrorlist. On my system I simply uncommented all of the UK mirrors:
## Great Britain (Try GB first)
Server = ftp://mirror.lividpenguin.com/pub/archlinux/$repo/os/$arch
Server = http://mirror.lividpenguin.com/pub/archlinux/$repo/os/$arch
Server = ftp://mirror.bytemark.co.uk/archlinux/$repo/os/$arch
Server = http://mirror.bytemark.co.uk/archlinux/$repo/os/$arch
Server = ftp://mirror.cinosure.com/archlinux/$repo/os/$arch
Server = http://mirror.cinosure.com/archlinux/$repo/os/$arch
Server = ftp://mirrors.uk2.net/pub/archlinux/$repo/os/$arch
Server = http://archlinux.mirrors.uk2.net/$repo/os/$arch

## Ireland (if none in england try Ireland)
Server = ftp://ftp.heanet.ie/mirrors/ftp.archlinux.org/$repo/os/$arch
Server = http://ftp.heanet.ie/mirrors/ftp.archlinux.org/$repo/os/$arch
Once the file has been saved you need to run pacman -Syy to force a refresh of all package lists.

Install useful tools and libs:

As this is a 64-bit system if you install packages such as 'base-devel' you will encounter problems later when dealing with software that requires 32-bit libs. Use the multilib-devel instead to be able to deal with 32 bit and 64 bit.
pacman -Syu vim mlocate ntp multilib-devel lib32-zlib lib32-ncurses lib32-sdl gcc gcc-multilib gcc-libs-multilib binutils-multilib libtool-multilib lib32-glibc

Install 'sudo' and create a user that is a sudoer:

useradd -m -g users -G audio,lp,optical,storage,scanner,video,wheel,games,power -s /bin/bash 
pacman -S sudo
Now that sudo is installed you'll need to make your user a sudoer. This is done using 'visudo', however now that vim has been installed you can use the following to use vim as the editor:
EDITOR=vim visudo
My preferred way to do this is to uncomment the following line so that any user that belongs to the 'wheel' group can use sudo.
%wheel ALL=(ALL) ALL

Install audio:

Edit /etc/modprobe.d/modprobe.conf by adding the following (this is to ensure that the 'snd-pcsp' module loads last):
options snd-pcsp index=2
Now install alsa:
pacman -S alsa alsa-utils alsa-oss

Install a graphical desktop environment (Gnome 3 in this case):

pacman -S xorg xorg-server xorg-xinit xorg-server-utils xterm gnome gnome-extra gnome-system-tools dbus gdm gnome-packagekit gnome-settings-daemon-updates gnome-tweak-tool gnome-shell-extension-alternative-status-menu
To get Xorg to use my UK keyboard layout I had to edit /etc/X11/xorg.conf.d/10-evdev.conf:
vim /etc/X11/xorg.conf.d/10-evdev.conf
then add the following to the 'evdev keyboard catchall' section:
Option "XkbLayout" "gb"
If you want your system to boot into a graphical environment rather than the command line then you'll need to edit your /etc/rc.conf file again. This time you need to edit the DAEMONS section. It should look similar to the following:
# DAEMONS
# -------
#
DAEMONS=(syslog-ng dbus network netfs crond alsa gdm)

Install Firefox, Chromium, and some additional fonts:

pacman -S ttf-dejavu ttf-droid ttf-liberation ttf-ubuntu-font-family ttf-freefont ttf-inconsolata monaco-linux-font chromium firefox
That's it! By now you should have a light weight Linux environment to work in. At this point there was still much that I had to install such as git, subversion, Java, Android SDK, Eclipse and Sublime Text. When I get time I may write a follow up article.