SETUP MY ARCH LINUX ENVIRONMENT

The marathon of installing & tunning the Arch Linux to my flavor.

SUMMARY

Arch Linux + Awesome WM + xterm, that is the main skeleton of my system.

I settled on this combination under the rule:

I choose LightDM, because it

  1. is developed independent of other DEs, hence I don’t have to be forced to install a bunch of GNOME or KDE dependency packages to only for making it run.

  2. is lightweight. Very small package size, therefore starts up pretty fast, as I can see.

  3. has many front ends (a.k.a. greeters) due to it cross-desktop feature.

Among various greeters, I currently use lightdm-gtk3-greeter. It has a simplistic and neat login screen, just the necessary elements I need.

THE WINDOW MANAGER – AWESOME WM

I have tried two ways of starting Awesome WM during system boot.

The first way, is using a display manager, which will presents you a login screen, where you enter your user ID & password. After authentication, it will start the Awesome WM for you.

The second way is to use xinit (and it’s front-end script startx). When display manager is absent in the startup process, system will bring you to one of the tty consoles, which is just a simplistic command line interface, then you type startx manually, which then, according the configuration in ~/.xinitrc, do some initial setting work and finally start the Awesome WM and transfer control to it.

Of the 2 ways I’ve tried, I prefer the first one – using a display manager. Because the display manager:

With display manager

Installing LightDM

First, install LightDM & lightdm-gtk3-greeter from official repository. An extra advantage of choosing lightdm-gtk3-greeter is that you do not need to modify the /etc/lightdm/lightdm.conf to let the LightDM back-end use it. It is the reference (default) greeter.

Then register LightDM to systemd, making it get started on boot automatically.

sudo pacman -S lightdm, lightdm-gtk3-greeter

sudo systemctl enable lightdm.service

Configuring LightDM

Without display manager

Without display manager, you should first login into the tty1, then type startx to start the Awesome WM.

Through some configuration, the 2 steps mentioned above can be automated:

Step 1 – automatic login to virtual console

create the following file and its’ parent directory if not exists.

# /etc/systemd/system/getty@tty1.service.d/autologin
------------------------------------------------------------------------------
[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --autologin mudox --noclear %I 38400 linux
Type=idle

Step 2 – start X at login

First install the xorg-xinit package from the Arch Linux official repository, which provides the xinit command & its’ front end – the startx script, besides, it also put a template xinitrc file under /etc/skel/ directory.

Then, base on /etc/skel/.xinitrc, create ~/.xinitrc as follows:

#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)

if [ -d /etc/X11/xinit/xinitrc.d ]; then
  for f in /etc/X11/xinit/xinitrc.d/*; do
    [ -x "$f" ] && . "$f"
  done
  unset f
fi

xrdb -merge ~/.Xresources # if you have ever created it.

# exec gnome-session
# exec startkde
# exec startxfce4

exec awesome # make sure it's on the last line

Finally, add the following code into you shell login script, such as .profile for bash and .zlogin for zsh.

# ~/.zlogin
------------------------------------------------------------------------------
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx

references:

MOUSE ACCELERATION

Type xset q | grep Pointer to see current mouse acceleration setting.

Try xset m <acceleration> <threshold> with different values to find the best combination for your feeling.

where acceleration defines how many times faster the cursor will move than the default speed. threshold is the velocity required for acceleration to become effective, usually measured in device units per 10ms. acceleration can be a fraction, so if you want to slow down the mouse you can use 12, 13, 14, … if you want to make it faster you can use 21, 31, 41, …

Threshold defines the point at which acceleration should occur in pixels per 10 ms.

I found my lucky combiantion is 1/4 8 and I add the setting command into rc.lua of Awesome WM to apply the setting on each startup.

references:

INPUT METHOD

The ibus + isbus-rime combinations works nicely on my Arch Linux.

After ibus gets installed, run ibus-setup, it will show a setting guide window where you can adjust ibus settings to adapt to Awesome WM environment.

On environments, ibus-daemon can not be loaded automatically on startup, so we need to manually run it. There are many ways to auto-start applications on linux platform, I choose to let Awesome WM to start it by adding auto-start code in rc.lua.

For ibus-rime, it is in tranditional chinese mode by default. To switch to simplified chinese mode, press Ctrl-~ when ibus-rime is active to open setup candiate menu and choose 朙月拼音-简化字

sudo pacman -S ibus ibus-qt ibus-rime

ibus-setup

# manually start ibus daemon for this session.
# this command has been added in my Awesome config file 'rc.lua' to auto-start
# it in the beginning of each Awesome session.
ibus-daemon -drx

references:

WINDOW MANAGER

On Linux platforms, I prefer WMs to DEs.

The Awesome WM is my favorite window manager.

see SETUP MY AWESOME WM ENVIRONMENT for details.

SHELL ENVIRONMENT

I have used several terminal emulators (gnome-terminal, xvrt …), and finally I settled myself on xterm, which I feel it:

As to shells, I become a zsh fan soon after played with it as well as bash & fish shells. the reason is obvious:

Pull down dot-files repo

My configuration resource related to termianl emulator & shells are managed in a github repo – dot-files.

cd ~/Git # ~/Git is the place I assemble most of my github repos.
git clone https://github.com/Mudox/dot-files.git

Setup xterm

First, install xterm from Arch Linux’s official repository.

Then, link out the .Xresources file from my dot-files repo. It is the configuration file that hold my xterm settings (colors, cursors, fonts etc.) among other x utility setttings.

sudo pacman -S xterm
cd ~
ln -sf Git/dot-files/Xresources .Xresources

Setup zsh

see SETUP MY ZSH ENVIRONMENTS for details.

SETUP VIRTUALBOX

Installing Virtualbox

First, from the official repository, install virtualbox package, which comes with virtualbox-host-modules.

Then we need to add the basic vboxdrv kernel module to host kernel.

Finally, add my user name to the vboxusers group in order to use USB port in virtual machines.

sudo pacman -S virtualbox

# manually add vboxdrv to host kernel for one time.
sudo modeprobe vboxdrv

# auto-load vboxdrv on every system startup.
sudo echo 'vboxdrv' > /etc/modules-load.d/virtualbox.conf

# add user name in vboxusers group to use USB ports in vitual machines.
sudo gpasswd -a "${USER}" vboxusers

Configuring Virtualbox

  1. Set Host Key Combination to right <winkey> which is consistent with Awesome WM’s keyboads shortcuts, it’s in File->Preference->Input->Virtual Machine of Oracle VM VitualBox Manager window.

  2. Enalbe Bidiretional clipboard, it’s in Devices->Shared Clipboard->Bidirectional of virtual machine window.

references:

VPN

Setup pptpclient

  1. install pptpclient from the official repository of Arch Linux.

  2. use pptpsetup command to register my VPN account, which is just a helper script that will create a readable text file /etc/ppp/peers/<tunnel_name> where you can change the server address manaually using whatever text editor you like. collect the following information in advance:

    • VPN server’s ip address from your VPN provider.

    • user name of your VPN account.

    • user password of your VPN account.

  3. install ppp-mppe (i.e. Microsoft Pointer-to-Pointer Encryption), if the pptpsetup command complains about MPPE module things.

  4. test configuration

    • use pon <tunnel_name> debug dump logfd 2 nodetach to test the configuration. If everything has been configured correctly, the command should not terminate. Ctrl-C to quit it.

    • type ip addr show, and you will see a new device ppp0 is listed in.

  5. connect VPN using sudo pon <tunnel_name>, sudo poff <tunnel_name> to tear down.

# install pptpclient
sudo pacman -S pptpclient

# add you VPN account (i.e. create a new tunnel)
sudo pptpsetup \
  --create <tunnel_name_whatever_you_like> \
  --server <your_VPN_server_ip_address> \
  --username <username_of_you_VPN_account> \
  --password <password_of_you_VPN_account> \
  --encrypt

# install ppp-mppe, if the command above complains about lacking of `MPPE`
# module things. rerun `pptpsetup` command above after installing it.
sudo pacman -S ppp-mppe

# test 1, the command should not terminate if everything is okay.
sudo pon <tunnel_name_above> debug dump logfd 2 nodetach

# test 2, you would see `ppp0` listed in the output.
ip addr show

# finally, connect!
sudo pon <tunnel_name>

Route all traffic through VPN connection

Manually

Use the powerfull ip command to add a route rule into route table.

# make all packages go through interface ppp0
ip route add default dev ppp0

This route rule is only effective during this ppp session. after your tear down the VPN connection by sudo pon <tunnel_name>, it will vanish.

Automatically

Every executable scripts under /etc/ppp/ip-up.d/ will be called when a VPN connection startup. Hence, we can use it to automatically set route rules.

# /etc/ppp/ip-up.d/01-routes.sh
# ----------------------------------------
#!/bin/bash

# This script is called with the following arguments:
# Arg Name
# $1 Interface name
# $2 The tty
# $3 The link speed
# $4 Local IP number
# $5 Peer IP number
# $6 Optional ``ipparam'' value foo

ip route add default via $4
cd /etc/ppp/ip-up.d
echo 'ip route add default via $4' > 01-routes.sh

# the script file need to have `x` permission to be run.
# it's stdin & stderr will be redirected off terminal, so not output will
# be shown when run.
co
sudo chmod +x /etc/ppp/ip-up.d/01-routes.sh

Modify DNS server list

If you found you still can not access some site (e.g. youtube, twitter, etc.) after establishing the VPN connection, then you should insert servername 8.8.8.8 ahead of existing lines in /etc/resolve.conf.

# /etc/resolve.conf
# ----------------------------------------
nameserver 8.8.8.8
nameserver 192.168.0.1

My hacky way

I wrote a script to get around of this:

# ~/.bin/vpn.sh
# ----------------------------------------
#!/bin/sh

tunnel="your configured tunnel name"

if [ "$#" -ne 1 ]; then
  echo "usage: $0 [on|off]"
  exit 1
fi

case "$1" in
  on )
    # connect
    pon ${tunnel} || exit 1

    # here we just overwrite the /etc/resolv.conf by `echo`ing the hard
    # written DNS list to it.
    printf "nameserver 8.8.8.8\nnameserver 192.168.0.1" > /etc/resolv.conf || exit 1
    ;;
  off )
    # disconnect
    poff ${tunnel}

    # some as above, we just `echo` back.
    echo 'nameserver 192.168.0.1' > /etc/resolv.conf || exit 1
    ;;
  * )
    echo "usage: $0 [on|off]"
    ;;
esac

unset tunnel

in your .bashrc or .zshrc file:

alias vpon='sudo ~/.bin/vpn.sh on'
alias vpoff='sudo ~/.bin/vpn.sh off'

then, you can type vpon to turn on the VPN, and vpoff to shutdown.

references: