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, or uncomment preferred mirros in /etc/pacman.d/mirrorlist (which is preferred). As an alternative, one may also try reflector after installing Arch Linux. Yet another option (I'm currently using) is to rely on script rankmirrors (according to here) to select the fastest mirrors. Note that for rankmirrors option, file /etc/pacman.conf needs one line Architecture = x86_64.

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-2011.08.19-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 "core-local".
  4. Select Editor according to your taste.
  5. 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.
  6. For "Prepare Hard Drive(s)", firslty I choose "Manually Partition Hard Drives" and then "Manually Configure block devices, file systems and mount points.". I only setup two partitions, /boot partition (200 MB, ext2), and root partition (remaining disk, ext4.)". For menu "Partition Access Method", select "uuid".
  7. After completing partitioning, go back to main menu and select "Select Packages. For bootloaders, choose "grub". Then for package, select "base-devel" meta-package as well, and select following packages in addition: gpm, inetutils, linux-header, mlocate, ncurses, openssh, pacman-mirrorlist, readline, sqlite3, sqlite3-doc, sudo, xinetd.
  8. Select "Install Packages" from main menu. Select "Yes" to keep packages in pacman cache.
  9. Select "Configure the System" from main menu.
    • Modify /etc/rc.conf. Change "foo" to your desired host name.
      # NETWORKING
      
      interface=eth0
      
      I also removed netfs from DAEMONS line.
    • Write your desired host name to /etc/hostname.
    • Modify /etc/fstab by adding options noatime and nodiratime to partition /.
    • Modify /etc/locale.gen by uncommenting the lines starting as "zh_CN" since I'm a Chinese.
    • Modify /etc/pacman.conf by uncommenting the Xfercommand line in /etc/pacman.conf for wget.
    • Modify /etc/pacman.d/mirrorlist by uncomment your preferred mirrors as discussed above.
    • Change root password.
  10. Back to main menu, select "Install Boot loader". 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).
  11. 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. Optionally package xorg-xinit can be installed for script startx and package rxvt-unicode for a nice terminal.

# 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. When using sudo to update pacman, one need to add the following line after typing visudo: Defaults env_keep += "http_proxy https_proxy".

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.

Handling of security

Ru nthe following command: cp /etc/pacman.conf.pacnew /etc/pacman.conf. Apply all previously mentioned changes to /etc/pacman.conf to the overwrittine file. Then uncomment following line:

SigLevel = Optional TrustAll

Run pacman-key --init to initialize keyrings.

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 pacaur after trying various helpers (e.g. pacaur support proxy seamlessly pacman). To install pacaur, one needs to first install yajl and expac using pacman, then install cower and pacaur by running the following command.

$ sudo pacman -S yajl
$ wget http://aur.archlinux.org/packages/co/cower/PKGBUILD ; makepkg -si
$ wget http://aur.archlinux.org/packages/pa/pacaur/PKGBUILD ; makepkg -si

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

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. Accept the default (although there are many drivers not needed). 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.

For better font rendering, one may install freetype2-infinality, fontconfig-infinality, ttf-google-webfonts, and libxft-lcd from AUR.

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

For VirtualBox, type the following to use GNOME 3:

# ln -s /usr/lib/xorg/modules/dri/vboxvideo_dri.so /usr/lib/dri
# pacman -S libltdl # Such reinstallation is needed.
$ gnome-shell --replace

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
baobab
- disk usage

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
# 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, cmake, valgrind, gprof2dot-git[A], bochs, qemu, mmixware [A], ghc, cabal-install, sbcl, racket, fluxus-git[A], squeak-vm[A], squeak-image[A], ruby, python, ipython, ipython2, pylint, pychecker, pyflakes, pep8[A], scipy, python2-pybrain [A], python2-nltk, wxpython, python-httplib2, python-pygame, ropemacs[A], matplotlib, libgnomeui, python2-pandas, django, nginx, gunicorn[A], postgresql, python2-psycopg2, auto-complete[A], jdk7-openjdk, visualvm[A], eclipse, eclipse-findbugs[A], android-sdk[A], android-ndk[A], android-sdk-platform-tools[A], emacs-android-git[A], scala, scala-docs, scala-sources, sbt, r, emacs-ess-svn[A], nasm, clojure, subversion, rapidsvn, ctags, git, perl-term-readkey, tig, tk, perl-libwww, mercurial, darcs[A], xmlstarlet, cconv[A], emacs-markdown-mode-git[A]
  • Documentation: texlive-most, pdftk[A], aspell-en, multimarkdown-git
  • Font: ttf-dejavu, ttf-inconsolata, terminus-font, wqy-bitmapfont, wqy-zenhei, wqy-microhei[A], ttf-arphic-uming, ttf-ms-fonts[A], ttf-vista-fonts[A], ttf-ms-fonts-zh_cn[A]
  • Multimedia: mplayer, mencoder, ffmpeg, codecs, cdparanoia, lame, cuetools, flac, shntool, wavpack, mac, mp3info, vorbis-tools
  • Web: lynx, chromium, flashplugin-prerelease, w3m, curl, amule
  • Utilities: gnupg, unzip, zip, p7zip
  • Graphics: gnuplot, inkscape, processing, graphviz, gimp, blender, imagemagick, darktable
  • Reader: djview4 , evince, kchmviewer, fbreader, calibre, pdf2djvu, catdoc, tesseract, tesseract-data-eng
  • Network: whois, nfs-utils, xinetd
  • Mathematics: maxima
  • Education: timidity++, solfege
  • X: xscreensaver
  • Fun: povray
  • Libraries: gsl, atlas-lapack[A], libmtp
  • Science: pymol, biopython, stellarium, celestia

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

For Emacs package management, el-get is interesting to try. The installation method is very unique and there is no need for an ArchLinux package.

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, pymacs.

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. Note that installation of trivial-gray-streams, flexi-streams, and cl-unicode might not be needed.

(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)
(asdf-install:install 'cl-ppcre)

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.

2 comments:

  1. "It is really cool to build a cutting-edge system, however the time spent on building it and maintaining it is enormous"

    hummmm ... if you really like the power and flexibility of portage package manager but don't want to spent so much time to "always on" and "forewer compiling" you should use sabayon and entropy infrastructure ... is no need to trow away years of you beloved gentoo setup! use sabayon linux!

    you can use source based portage in parallel with entropy binary generated packages ... this way you have the best of both world ... arch ports is nowhere so easy and flexible like portage when you need to compile from source code ...

    and sabayon entropy upgrades is ... just working ... an always up to date system in a weekly scheduled upgrades who do not need more that an hour per one week to be up to date ...

    ;-)

    ReplyDelete
  2. Thanks totedati for your comments. Actually 2 weeks ago, I tried Gentoo again but was frustrated again. Compiling time is one thing, another problem is that some packages are even older compared with Arch Linux. For example, I use SBCL a lot, the version in Gentoo portage (even with ~arch keyword) is 1.0.36, while in Arch it is 1.0.44. Also openjdk is still not in portage. I know I can setup overlay, or even write ebuilds by myself. But isn't a cutting edge system supposed to provide most up to date packages? I guess the main issue now is that Gentoo just provides too much flexibility for customization, which makes development and maintainable really a headache: there are just too many (if not infinite) combinations to handle/test.

    I have heard Sabayon Linux and know that it is more popular than Gentoo from distrowatch. Maybe I will try Sabayon sometime, but currently I'm quite satisfied with Arch.

    Anyway, use the system which is most suitable for you. This is Linux world :-)

    ReplyDelete