Saturday, December 25, 2010

Switching From Gentoo Linux to Arch Linux

Introduction

Although I have been using Gentoo Linux for several years, I started to consider switching to other Linux distributions. The main drawback of Gentoo is that too much time is spent on compiling. It is really cool to build a cutting-edge system, however the time spent on building it and maintaining it is enormous. Therefore I am searching a minimalist's Linux distribution with binary packages. Arch Linux seems to be quite good. I gave it a try under VirtualBox 4.0. The reference I used was Beginner's Guide.


Install the base system

The overall installation steps are quite similar to Gentoo: you need to configure many things by hand. The difference is that the installation is significantly faster.

If possible, one should select the fastest mirror since downloading time is the most significant component of installing Arch Linux packages. For me, I select the mirror listed here with the best score for my location. After determining the mirror, you can download the ISO image from that mirror, and add it to your /etc/pacman.conf after installation. For example by adding Server = http://mirror.url/archlinux/$repo/os/x86_64 under the repo names.As an alternative, one may also try reflector after installing Arch Linux.

To enable the compatibility with 32-bit legacy programs (like Android emulator), multilib should be enabled in pacman.conf as below:

[multilib]
Include = /etc/pacman.d/mirrorlist

Simply download the latest ISO image. I used "core" image since it contains all the base packages for installation. The latest version as writing is archlinux-2010.05-core-x86_64.iso. Download and mount it under VirtualBox. Then boot the virtual machine.

For help, open a virtual terminal (by typing Alt+F2) and type less /arch/beginnersguide.txt

The installation steps are as follows:

  1. Login as root.
  2. Type /arch/setup to start the installer.
  3. Select the source as "CD-ROM".
  4. Set the clock by selecting region and timezone according to your location. You should know whether your hardware clock is UTC or local (my settings in VirtualBox is UTC). The recommended setting is UTC.
  5. For "Prepare Hard Drive(s)", I choose "Auto Prepare". I use ext4 for my / and /home partitions.
  6. After completing partitioning, go back to main menu and select "Select Packages. I select "base-devel" meta-package, and select following packages in addition: gpm, mlocate, ncurses, openssh, readline, sqlite3, sudo.
  7. Select "Install Packages" from main menu. Select "Yes" to keep packages in pacman cache.
  8. Select "Configure the System" from main menu. I choose vi as the editor.
    • Modify /etc/rc.conf. Change "foo" to your desired host name.
      # NETWORKING
      HOSTNAME="foo"
      eth0="dhcp"
      
      I also removed netfs from DAEMONS line.
    • Modify /etc/fstab by adding options noatime and nodiratime to partition / and /home.
    • Modify /etc/locale.gen by uncommenting the lines starting as "zh_CN" since I'm a Chinese.
    • Modify /etc/pacman.conf by adding preferred mirrors as discussed above. I also uncommented the Xfercommand line in /etc/pacman.conf for wget.
    • Change root password.
  9. Back to main menu, select "Install Boot loader", and choose "GRUB". Add option "vga=0x360" for customed VESA mode provided by VirtualBox (as discussed below). Install the bootloader to master boot record (sda in my case).
  10. Finally, select "Exit Install" and type reboot to turn on the new system.

Configuration and Graphics User Interface

This section documents further installation and customization I made.

VirtualBox related settings

Install custom VESA mode to support your PC/Laptop's screen resolution according to VirtualBox manual, if necessary.

Install VirtualBox guest additions as shown below (note that we need to install kernel headers first to compile the additions). Reboot is needed to make additions work. Note that if you want to install Xorg, you can run VBoxLinuxAdditions.run after completing pacman -S xorg.

# pacman -S kernel26-headers
# mkdir /mnt/cdrom
# mount -t iso9660 /dev/cdrom /mnt/cdrom
# cd /mnt/cdrom
# ./VBoxLinuxAdditions.run
# reboot

Proxy: for proxy, add export http_proxy=proxy.url to .bashrc of root. If subversion was later installed, oen need to modifiy ~/.subversion/servers for lines containing http-proxy-host and http-proxy-port.

To share folders between host and Linux guest, one need to first setup the sharing in VirtualBox GUI. Then after installing Guest Additions as discussed above, the sharing can be enabled like below (assuming the shared folder name is bar and you want to mount it in your Linux guest directory /mnt/bar):

# mkdir /mnt/bar
# mount -t vboxsf bar /mnt/bar

Add additional user

# useradd -m -G audio,optical,storage,video,wheel foo
# passwd foo

Change foo to your desired name.

Run visudo to edit file /etc/sudoers. Uncomment the 1st line containing wheel to enable running root commands from wheel group. One may add lines like Defaults env_keep += "http_proxy" to pass environment variables.

Cleanup unused packages

Since some packages are not useful to me, I remove them to avoid future waste of time and bandwidth to update them. Note that you may use pacman -Qe to list the explicitly installed packages. Warning: please make sure you do understand what you're doing: removing important system packages may break your system. As shown below, I only remove those packages related to file systems I'm not using.

# pacman -Rsn jfsutils reiserfsprogs xfsprogs

ABS

Run the following command:

# pacman -S abs

Edit /etc/abs.conf, For REPOS line, add ! before testing.

AUR helper

There are lots of AUR helpers, and I chose packer after meeting problems from yaourt. Install packer by running the following command.

$ wget http://aur.archlinux.org/packages/packer/packer/PKGBUILD ; makepkg -fic

To install packages from AUR, simply run packer -S pkg.

Update (2011-01-17): one may also try powerpill to boost downloading speed (note that powerpill may not work when pacman version >= 3.5). An alternative AUR helper is clyde.

SSHD

If one want to run SSHD server, one need to add sshd to DAEMON line of /etc/rc.conf. One may modify /etc/hosts.allow and/or /etc/hosts.deny. Default is that all connections are denied.

Xorg

Install Xorg by simply running pacman -S xorg. Afterward, one need to install VirtualBox Guest Addition for video drivers, as discussed above.

Generally, there is no need to modify /etc/X11/xorg.conf since VirtualBox can handle the file for you when installing Guest additions. There is no need to specify screen resolutions since VirtualBox can seamless adjust it according to host resolution. However, if one wants to restrict available resolutions (e.g. to use StumpWM which is not compatible with VirtualBox's seamleass operation), one can add the following line in Section Screen, Subsection Display. Below example sets up two resolutions with 60 Hz refresh rate.

  Modes "1680x1050_60.00" "1440x900_60.00"

One may install package mesa-demos to benchmark OpenGL performance with glxgears.

GNOME

Install GNOME by typing the command pacman -S gnome. Then add dbus to DAEMONS array in /etc/rc.conf.

Add the following line to ~/.xinitrc:

#!/bin/sh

# Make sure it is at the beginnig of the file, especially before "exec gnome-session"
[ -f /etc/xprofile ] && . /etc/profile
[ -f ~/.xprofile ] && . ~/.xprofile
exec gnome-session

To start GNOME, simply type startx.

I installed following packages in addition:

gconf-editor
- Edit GNOME settings
gnome-system-tools
- contains GNOME admin tools
gksu
- allows normal user to use system tools
gamin
- allows changes to files and directories to be detected immediately.
gnome-media-pulse
- enables volume control as tray notification
faenza-icon-theme
- cool icon theme

To select fonts suitable for LCD display, right click mouse on desktop, then select Change Desktop Background -> Font, select "Subpixel smoothing (LCDs)" for Rendering.

Update (2011-05-03): I installed login manager GDM by typing pacman -S gdm, and perform following changes to /etc/inittab:

  • comment line id:3:initdefault:
  • uncomment line id:5:initdefault:
  • comment line x:5:respawn:/usr/bin/xdm -nodaemon
  • uncomment line x:5:respawn:/usr/sbin/gdm -nodaemon

Audio

In VirtualBox settings for Audio Controller, I select Intel HD Audio. The sound car can be automatically detected by udev. So what needs to be done is to unmute some channels and let alsa store and restore mixer settings.

# pacman -S alsa-utils
# amixer set Master 90% unmute
# amixer set PCM 85% unmute
# amixer set Headphone 85% unmute
# aplay /usr/share/sounds/alsa/Front_Center.wav
# alsactl -f /var/lib/alsa/asound.state store

Finally, edit /etc/rc.conf and add "alsa" to DAEMONS array to store on shutdown and restore mixer settings on boot.


Customization and Applications

Note: this part is quite personal. The purpose I wrote it is mainly for documenting the steps so I myself may use it later.

Applications

Following is a list of applications installed by category. Some packages are only available from AUR and are marked by suffix [A].

  • Development tools: gdb, strace, valgrind, bochs, sbcl, racket, ruby, python, openjdk6,eclipse, android-sdk[A], android-ndk[A], android-sdk-platform-tools[A], emacs-android-git[A], python, scala, scala-doc, scala-src, darcs, nasm, bochs, clojure, subversion, git, perl-term-readkey, tig, tk, perl-libwww, mercurial, darcs
  • Documentation: texlive-most, aspell-en
  • Font: ttf-dejavu, wqy-bitmapfont, ttf-arphic-uming, ttf-ms-fonts[A], ttf-vista-fonts[A], ttf-ms-fonts-zh_cn[A]
  • Multimedia: mplayer, ffmpeg, codecs, cdparanoia, lame
  • Web: lynx, chromium, flashplugin-prerelease, w3m, curl, amule
  • Utilities: bc, gnupg, unzip
  • Graphics: gnuplot, inkscape, graphviz, gimp, blender, imagemagick
  • Reader: djview4 , evince, kchmviewer, fbreader, calibre, pdf2djvu
  • Network: whois
  • Mathematics: maxima
  • Education: timidity++, solfege
  • X: xscreensaver
  • Fun: povray
  • Libraries: gsl, atlas-lapack[A]

Chinese Input

I install ibus as below:

# pacman -S ibus ibus-pinyin

Then add the following lines into ~/.xprofile:

export XMODIFIERS=@im=ibus
export GTK_IM_MODULE=ibus
export QT_IM_MODULE=ibus
ibus-daemon -d -x

Update (2011-01-06): switch from SCIM to ibus.

Emacs

Install scala-mode as below:

$ cd ~/.emacs.d/plugins
$ svn co http://lampsvn.epfl.ch/svn-repos/scala/scala-tool-support/trunk/src/emacs/ scala-mode

Get anything.el by wget http://www.emacswiki.org/emacs/download/anything.el.

Install following packages: auctex, slime-cvs, emacs-w3m-cvs.

Install clojure related modes.

$ cd ~/.emacs.d/plugins
$ git clone https://github.com/technomancy/clojure-mode.git clojure-mode
$ git clone https://github.com/technomancy/swank-clojure.git
$ mkdir ~/.swank-clojure
$ cd ~/.swank-clojure
## Get three jars in https://github.com/technomancy/swank-clojure/blog/master/swank-clojure.el manually.

Install Hyperspec for Common Lisp

Run the following commands:

# wget ftp://ftp.lispworks.com/pub/software_tools/reference/HyperSpec-7-0.tar.gz
# tar xzvf HyperSpec-7-0.tar.gz
# mkdir /usr/share/doc/hyperspec
# mv HyperSpec !$

Stumpwm

First invoke sbcl, then type the following into REPL. Note that ASDF install is used other than AUR.

(require 'asdf)
(require 'asdf-install)
(asdf-install:install "http://common-lisp.net/project/cl-plus-ssl/download/trivial-gray-streams.tar.gz")
(asdf-install:install "http://weitz.de/files/flexi-streams.tar.gz")
(asdf-install:install "http://weitz.de/files/cl-unicode.tar.gz")
(asdf-install:install 'clx)

When prompted by "Install where", it is recommended to select "Personal Installation" since it does not require root privilege. Note that some packages do not have GPG signature, so if SBCL drops you into debugger, simply select skip GPG check. If SBCL complaints and exited (due to in --disable-debugger mode), type the following after enter sbcl (sb-ext:enable-debugger) or add it to /etc/sbclrc as system initialize file for SBCL.

After installation of the dependencies, quit SBCL by type (sb-ext:quit) and run the following at CLI:

$ git clone http://git.sv.gnu.org/r/stumpwm.git stumpwm
$ cd stumpwm
$ ./autogen.sh
$ ./configure
$ make

After copy stumpwm to a directory in PATH, one can add "exec stumpwm" at the end of ~/.xinitrc. Then typing startx will bring up Stumpwm. Since I installed both GNOME and StumpWM, I decides to write two scrips to automate the changes to .~/.xinitrc. With these scripts, I can type startg for GNOME or starts for StumpWM.

Contents of script startg:

#!/usr/bin/env bash
sed -e 's/exec.*$/exec gnome-session/' -i ~/.xinitrc
startx

Contents of script starts:

#!/usr/bin/env bash
echo "exec stumpwm" > ~/.xinitrc
startx

Miscellaneous

For root, add one line in ~/.bash_profile to enable .bashrc
. $HOME/.bashrc

To run indexing daily, run crontab -e to add the following line (Update (2010-12-28): this step is not needed since updatedb is already added in /etc/cron.daily during installation of mlocate):

11 11 * * * updatedb

To keep boot messages on tty1 instead of clearing screen, add option for tty1 in /etc/inittab like below:

c1:2345:respawn:/sbin/agetty -i -8 38400 tty1 linux

Conclusion

After using Arch Linux for a long time, I have to say that I'm extremely satisfied. Your system may not be extremely fast as Gentoo boxes, but what you gain is significant: invaluable time.