arch setup

HOWTO configure a minimal Arch Linux system for a laptop and main reasons why I switched from Ubuntu to Arch.

Preface

I've been using Ubuntu, or rather Kubuntu, on my x61 Thinkpad laptop for more than a year, but recently I have decided to try a different Linux distro. There were several reasons that led to this decision. First of all, I got tired of outdated packages in Ubuntu's official repository. From my understanding it is rather hard to create your own packages and get them to be included in one of Ubuntu's repositories, with most of the packages in the official repos coming from Debian's repos. For example, Eclipse IDE in Ubuntu is a "little" old: at the time of writing, it is at version 3.2.2-5 in the repository, while the latest official version is 3.5-2. I've been told by a friend that community repositories for other distros usually contain the most up-to-date packages, but there's no such thing as a centralized community repository for Ubuntu. The closest thing to a community repository are PPAs on launchpad, but the whole system is decentralized - I think PPAs were devised with a different purpose in mind, namely providing developers with a sandbox-like repo for their packages, not for users who'd like to have access to more packages.

Second, I never really liked the package managers that I had to use with Ubuntu - Synaptic and Adept. Synaptic was fine for trivial package management, but lacked some features. Adept was ill-suited for keyboard-only interactions and had a nasty habit of crashing every now and then. I usually prefer to perform administrative tasks from the command line, but I could never remember APT's front-ends and options (do I use apt-get? or apt-cache? or dpkg? what are the options for that, once again?..). I probably should have tried using Aptitude, but I doubted that it would make my life significantly easier.

Lastly, I've been using Kubuntu instead of Ubuntu for a very specific reason: I think that Gnome's widgets, windows and panels take up too much space on screens with small resolution, such as x61's 1024x768 screen. While everything of that sort might be tweakable, at the time I got my new laptop I didn't bother to find out how to tweak these things and simply went with KDE, which looked much slimmer than GNOME to me. Over time, I started to notice KDEs deficiencies on such a small screen with 5 or more windows open. I would have to maximize each of them to be able to work comfortably, so switching between windows with Alt+Tab became really distracting. I found that it is possible to assign shortcuts to individual windows (Win+F for Firefox, Win+R for Krusader, Win+K for Kate and so on) and that made my life easier, but still not easy enough. Sometimes I wanted to be able to line up two windows side by side. Arranging them with a mouse was bothersome and took a rather long time. Not surprisingly, someone before me also got tired of managing windows by hand and invented a tiling window manager. On top of it, there was that whole KDE3 to KDE4 migration thing, which I didn't look forward to. Time for a new desktop environment.

So in the end, I went with something pretty much the opposite to Ubuntu/Kubuntu, which might've seemed kind of illogical because I was almost completely satisfied with Ubuntu... up until recently. After a brief search — there are not that many distros that are not dpkg or rpm based and not that many rpm distros that have community repositories — I went with Arch Linux. It has its own centralized community repo - AUR; it has a rolling release system, so packages in the repositories are updated frequently; it has its own package manager, pacman. Plus, Arch Linux does not come with any desktop environment by default, so you can install any desktop environment or window manager that you want. On top of that, it's what I think of as developer/programmer/hacker-friendly distribution as opposed to a user-friendly distribution - you are required to read documentation to know how things are done and you have to know Linux pretty well, but the system's internal workings are well documented, configuration is straightforward, everything is laid out in a logical and consistent manner and there are no unneeded levels of abstraction that prevent you from tinkering with the system.

After some research and trial-and-error on Arch in VirtualBox, I decided that I do not need a full-blown desktop environment on my laptop and that Awesome WM will do nicely. The following article documents what I needed to install and configure after installing Arch Linux to get what I consider a base system — a system with a graphical environment and power-saving features.

Hardware abstraction and IPC

HAL is a hardware abstraction layer for Unix-like systems that provides a simple hardware API to desktop applications. D-Bus is an inter-process communications system that allows applications to communicate with each other and HAL. Both of these will be needed for Xorg configuration and power management (and hey, they will probably come in handy in the future, too!). Install them with

# pacman -S hal dbus Then, add 

hal to the list of daemons which should be loaded at startup in /etc/rc.conf:

DAEMONS=(syslog-ng hal network netfs crond)

There is no need to add dbus to the list - hal will automatically load dbus.

Installing X11

Do

# pacman -S xorg-server xorg-xinit xf86-input-mouse xf86-input-keyboard

Install video drivers for x61's Intel GM965/GL960 video card:

# pacman -S xf86-video-intel

There is no need to create any kind of xorg.conf file unless you're absolutely sure that you need one - in the absence of xorg.conf, Xorg server will attempt to gather all the required information from HAL. If you do need to create xorg.conf, keep in mind that hwd is deprecated and moved into AUR. You should use X -configure instead. Add the following line to /etc/X11/xorg.conf if mouse and keyboard are disabled:

Option  "AllowEmptyInput" "false"

Power management

Next, install utilities for laptop power management:

# pacman -S pm-utils acpid cpufrequtils laptop-mode-tools

Pm-utils provides several scripts, namely pm-suspend and pm-hibernate, that can be launched from the command line or from a bash script to suspend or hibernate your machine.

In order for pm-hibernate to work, the resume kernel option has to be added to /boot/grub/menu.lst:

# (0) Arch Linux
title  Arch Linux
root   (hd0,0)
kernel /vmlinuz26 root=/dev/sda3 resume=/dev/sda2 ro
initrd /kernel26.img

You also have to add the resume hook to the initrd image. While the Arch wiki states that its only required in certain cases, it has been my experience that the system will fail to resume without this hook. Edit /etc/mkinitcpio.conf:

HOOKS="base udev autodetect ide scsi sata lvm2 resume filesystems"

The resume hook has to be placed scsi, sata and lvm2, but before filesystems ( again, according to the Arch wiki).

Most likely, you will want Arch to launch these scripts automatically in response to various events, such as closing of laptop lid or pressing the hibernate button. Acpid will provide you with some of this event-handling functionality. There is no need to add acpid to the list of daemons to be launched at startup, since hal will take care of launching acpid too. To have the laptop go in sleep mode when the lid is closed, locate the following lines in /etc/acpi/handler.sh and add /usr/sbin/pm-suspend command:

button/lid)
    #echo "LID switched!" > /dev/tty5
    /usr/sbin/pm-suspend</b>
;;

On a related note, you can add standard Linux poweroff command to /etc/acpi/handler.sh so that you will be able to properly shutdown your machine with a single press of a power button:

button/power)
    #echo "PowerButton pressed!">/dev/tty5
    case "$2" in
        PWRF)
            logger "PowerButton pressed: $2" 
            poweroff
            ;;
        *)      logger "ACPI action undefined: $2" ;;
    esac
    ;;

After you're done editing /etc/acpi/handler.sh, let's make sure that the laptop will hibernate when the battery is low. This functionality is provided by laptop-mode-tools package which we installed before. Add laptop-mode daemon to /etc/rc.conf:

DAEMONS=(syslog-ng hal network netfs crond laptop-mode)

Additional features of Laptop Mode Tools are configured thru several files in /etc/laptop-mode/conf.d/. Edit /etc/laptop-mode/conf.d/auto-hibernate.conf and set:

ENABLE_AUTO_HIBERNATION=1
HIBERNATE_COMMAND=/usr/sbin/pm-hibernate

Don't forget to launch Laptop Tools daemon if you haven't rebooted after adding laptop-mode to the daemons list:

# /etc/rc.d/laptop-mode start

Screensaver and session locking

Finally, if you would like your machine to be locked after a period of inactivity or after a suspend/hibernation, install XScreenSaver:

# pacman -S xscreensaver

XScreenSaver is run as a background process and shows pretty graphics after a certain period of inactivity, but it can also receive commands from xscreensaver-command command-line utility, one of which, namely xscreensaver-command -lock, locks the machine. So, we can use XScreenSaver to lock the machine on wake up from standby/hibernation and after a period of inactivity. To do this, we would want to launch xscreensaver daemon at startup. Add the following line to your ~/.xinitrc before the line that launches your window manager:

xscreensaver -no-splash &

Then launch XScreenSaver daemon with

$ xscreensaver &

or reboot. Edit your /etc/acpi/handler.sh to lock the screen before telling pm-utils to put the machine to sleep:

button/lid)
    # lock the screen and suspend
    /usr/bin/xscreensaver-command -lock
    /usr/sbin/pm-suspend
    ;;

And that's it for this post. You would still have to tweak power management to make Thinkpad buttons work and install a window manager, but we've laid the foundation for a minimalist laptop system.