Install and Configure Arch Linux

 Linux
 

Steps to install Arch Linux and configure it for daily use and work.

Pre-installation

Verify signature

Use GnuPG to verify downloaded package.

1
gpg --keyserver pgp.mit.edu --keyserver-options auto-key-retrieve --verify archlinux-<version>-x86_64.iso.sig

Build bootable live environment

Plug in USB and check its device name by

1
lsblk

Asume its name is /dev/sdb, then use dd to build the bootable system to usb (warning before press “ENTER”, double check the command to prevent from destroying system)

1
dd if=/way/to/arch/file of=/dev/sdb

Verify the boot mode

1
ls /sys/firmware/efi/efivars

If the directory does not exist, the system may be booted in BIOS or CSM mode, otherwise, in UEFI mode. If it’s in UEFI mode, go ahead.

Plug in USB, shut down computer, enter into BIOS system interface with holding F2 then press power button. (Different motherboards diverse in entering BIOS)

If you can’t see a boot option “boot from USB”, go to create a boot option by select your boot file which end with .efi. And then put this option to number 1 boot option. OK, save change and reboot system.


Now we had entered the Arch live system.

Connect to the Internet

The installation image enables the dhcpcd daemon for wired network devices on boot. The connection can be verified with ping, If you use wifi, you should configure wifi with wifi-menu

1
wifi-menu
1
ping -c 3 baidu.com

Update the system clock

Use timedatectl to ensure the system clock is accurate

1
timedatectl set-ntp true

(To check the service status, use )

1
timedatectl status

Partition the disks

When recognized by the live system,disks are assigned to a block device. To identify these devices, use lsblk or fdisk -l

1
lsblk

The following partitions are required for a chosen device:

  • One partition for the root directory / .

  • If UEFI is enabled, an EFI system partition .

    (The following are alternative)

  • Swap space can be set on a separate partition or a swap file .

  • /home directory for users .

(Note : If you want to create any stacked block devices for LVM, disk encryption, or RAID, do it now.)

To modify partition tables, use cfdisk, fdisk or parted.

1
cfdisk /dev/sda

my partition plan for system with 4G RAM and 500G storage device

1
2
3
/dev/sda1		 200M		/boot/efi  	EFI System
/dev/sda2 250G / Linux fs
/dev/sda3 remaining /home Linux fs

Format the partitions

Once the partitions have been created, each must be formatted with an appropriate file system.

1
2
3
4
mkfs.fat -F32 /dev/sda1

mkfs.ext4 /dev/sda2
mkfs.ext4 /dev/sda3

Mount the file systems

Mount the file system on the root partition to /mnt

1
mount /dev/sda2 /mnt

Create mount points for any remaining partitions and mount them accordingly

1
2
3
4
5
mkdir /mnt/boot/efi
mount /dev/sda1 /mnt/boot/efi

mkdir /mnt/home
mount /dev/sda3 /mnt/home

genfstab will later detect mounted file systems and swap space.


We have accomplished the work for Pre-Installation, now enter the process of Installation.

Installation

Select the mirrors

Packages to be installed must be downloaded from mirror servers, which are defined in /etc/pacman.d/mirrorlist . Use vim to select your country’s mirror to the top.

1
vim /etc/pacman.d/mirrorlist

Install the base packages

Use the pacstrap script to install the base and base-devel package groups:

1
pacstrap /mnt base base-devel

Configure the system

Fstab

Generate an fstab file (use -U or -L to define by UUID or labels, respectively)

1
genfstab -U /mnt >> /mnt/etc/fstab

and check the resulting file.

Chroot

Change root into the new system:

1
arch-chroot /mnt

Configure wifi

1
2
pacman -S dialog wpa_suppliant
wifi-menu

Time zone

1
ln -sf /usr/share/zoneinfo/Asian/Shanghai /etc/localtime

Generate /etc/adjtime

1
hwclock --systohc

This command assumes the hardware clock is set to UTC.

Localization

Uncomment en_US.UTF-8 UTF-8 and other needed locales in /etc/locale.gen,and generate them

1
locale-gen

Set the LANG variable in /etc/locale.conf

1
LANG=en_US.UTF-8

Network configuration

Create the hostname file /etc/hostname

1
echo 'Arch' > /etc/hostname

​Add matching entries to /etc/hosts

1
echo -e "127.0.0.1\tlocalhost\n::1\t\tlocalhost\n127.0.1.1\tArch.localdomain\tArch" > /etc/hosts

If the system has a permament IP address, it should be used instead of 127.0.1.1 .

Initramfs

Creating a new initramfs is usually not required, because mkinitcpio was run on installation of the linux package with pacstrap .

For special configurations, modify the mkinitcpio.conf file and recreate the initramfs image :

1
mkinitcpio -p linux

Set root password

1
passwd

Install bootloader

A Linux-capable boot loader must be installed in order to boot Arch Linux. If you have an Intel or AMD CPU, enable microcode updates. Let’s install GRUB boot loader:

Download grub and efibootmgr

1
pacman -S grub efibootmgr

GRUB is the bootloader while efibootmgr is used by the GRUB installation script to write boot entries to NVRAM .

(Mount the EFI system partition at mount point, for example, /boot/efi )

Install the GRUB EFI application

Install the GRUB EFI application grubx64.efi to /boot/efi*/EFI/GRUB/ and install its modules to /boot/grub/x86_64-efi/ .

1
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB

(After the above install completed the main GRUB directory is located at /boot/grub/ . Note that grub-install also tries to create an entry tin the fireware boot manager, named GRUB in the above example.)

Generated grub.cfg

Use the grub-mkconfig tool to generate /boot/grub/grub.cfg

1
grub-mkconfig -o /boot/grub/grub.cfg

(Note:

  • Remember that /boot/grub/grub.cfg has to be re-generated after any change to /etc/default/grub or files in /etc/grub.d .
  • After installing or removing a kernel, you just need to re-run the above grub-mkconfig command.)

Reboot

Exit the chroot environment, then manually unmount all the partitions.Finally, restart the machine.

1
2
3
exit
umount -R /mnt
reboot

Post-installation

Add a new user

1
2
useradd -m -G wheel -s /bin/bash wjw
passwd wjw

To grant sudo access to user wjw run visudo and add “wjw ALL=(ALL) ALL

1
visudo

Font

See available fonts

1
fc-list

Download fonts

1
2
sudo pacman -S wqy-microhei ttf-dejavu
yay -S ttf-symbola

or download packages manually and put font files to the .local/share/fonts/ directory.

If you want to change console font, put font files in the /usr/share/kbd/consolefonts directory. Then go to see the console fonts, and select one..

1
2
ls /usr/share/kbd/consolefonts
echo "FONT=sun12x22\nFONT_MAP=8859-2" > /etc/vconsole.conf

Graphical user interface

Install Xorg

1
sudo pacman -S xorg-server xorg-xinit xorg-xinput

configure ~/.xinitrc file

1
[[ -f ~/.Xresources ]] && xrdb -merge -I$HOME ~/.Xresources

Install i3-gaps and configure to start from ~/.xinitrc . (rofi for replacing d-menu, feh for setting wallpaper, light for brightness control, scrot for screenshot, i3blocks for replacing i3status, acpi for i3blocks’s battery module)

1
2
sudo pacman -S i3-gaps i3blocks rofi feh light scrot acpi
echo 'exec i3' > ~/.xinitrc

You can start up i3 manually by typing command startx or set it to automatically.If you use zsh ,put the following into the ~/.zprofile to auto start X at login

1
2
3
if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then
exec startx
fi

Install ssr

1
2
3
4
5
6
sudo pacman -S git wget python
wget http://www.djangoz.com/ssr
sudo mv ssr /usr/local/bin
sudo chmod 744 /usr/local/bin/ssr
ssr install
ssr config

Wireless configure

Install dialog and wpa_suppliant for using wifi-menu . (or optionally Install networkmanager )

1
sudo pacman -S dialog wpa_suppliant

Enabling wifi auto connecting when boot. (use netctl)

1
sudo wifi-menu -o

use command above to generate the profile in /etc/netctl for use of netctl.

1
sudo netctl enable your_profile

Sound

If no sound because of Master set to HDMI, go to change it to PCM.

1
sudo echo -e "defaults.pcm.card 1\ndefaults.pcm.device 0\ndefaults.ctl.card 1" > /etc/asound.conf

Download pulseaudio and related control command utils.

1
sudo pacman -S pulseaudio pulsemixer playerctl

And download alsa-utils for controling alsa

1
sudo pacman -S alsa-utils

Useful program

1
sudo pacman -S firefox neofetch

yay

1
2
3
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

lxappearance & qt5ct

qt5ct for qt5 based programs, while lxappearance for gtk based programs.

1
sudo pacman -S lxappearance qt5ct

gtk related configure files:

1
2
~/.gtkrc-2.0
~/.config/gtk-3.0/settings.ini

GTK Theme

1
sudo pacman -S adapta-gtk-theme

Icon theme

1
2
3
git clone https://github.com/horst3180/arc-icon-theme --depth 1 && cd arc-icon-theme
./autogen.sh --prefix=/usr
sudo make install

add the following environment variable to ~/.pam_environment

1
QT_QPA_PLATFORMTHEME=qt5ct

laptop power saving

1
sudo pacman -S tlp

then configure it:

1
2
systemctl enable tlp.service tlp-sleep.service
systemctl mask systemd-rfkill.service systemd-rfkill.socket

(Note: tlp.service starts NetworkManager.service if it is available. If you use a different network manager, mask NetworkManager.service or edit tlp.service and remove the service out of line Wants=)

System proxy (Privoxy)

1
sudo pacman  -S privoxy

then edit /etc/privoxy/config file and add the following line the 5.2 section (note the . at the end)

1
forward-socks5 / 127.0.0.1:1080 .

It means that transact all http requests to socks5 and redirect to localhost’s 1080 port (change this value to your ssr listening port)

then you should go to start and enable privoxy.service .

1
2
systemctl start privoxy.service
systemctl enable privoxy.service

Privoxy’s default listening port is 8118, so your should set your http proxy address to 127.0.0.1:8118 .

1
export http_proxy="http://127.0.0.1:8118"

Configure git proxy

1
git config --global http.proxy 127.0.0.1:8118

File manager

ranger (use w3m to preview image) and pcmanfm

1
2
sudo pacman -S ranger highlight w3m
sudo pacman -S pcmanfm

tmux & tmux-resurrect

1
2
sudo pacman -S tmux
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

Build package

use asp or pbget

1
sudo pacman -S asp

Docker

Download docker, then create a group named docker and add user to this group for using docker without “sudo” command for regular user.

1
2
3
sudo pacman -S docker
sudo groupadd docker
sudo usermod -aG docker $USER

Then enable and start docker.service

1
2
systemctl enable docker.service
systemctl start docker.service

Setting proxy for docker:

1
2
mkdir /etc/systemd/system/docker.service.d
touch /etc/systemd/system/docker.service.d/proxy.conf

put following content to the file above

1
2
3
[Service]
Environment="HTTP_PROXY=192.168.1.1:8118"
Environment="HTTPS_PROXY=192.168.1.1:8118"

Then reload units

1
systemctl daemon-reload

Check whether setting successfully

1
systemctl show docker --property Environment

Tensorflow

Download nvidia-docker

1
yay -S nvidia-docker

Pull latest tensorflow-gpu

1
docker pull tensorflow/tensorflow:latest-gpu-py3
1
docker run --runtime=nvidia -it tensorflow/tensorflow:latest-gpu-py3 bash

(Note: nvidia-docker v1 uses the nvidia-docker alias, where v2 uses docker --runtime=nvidia.)

Docker Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
docker ps -a	#check all containers
docker rm $(docker ps -aq) #delete all containers

docker images #check all images
docker rmi $(docker images -q) #delete all images
docker rmi node_name #delete node(image)

docker info
docker version

# create a container named tf and run it
# -it : interactive
# --name : assign the name "tf" to this container
# -p : mapping ports of container to host, first pair for Jupyter notebook, the second one for Tensorboard
# -v host_folder:container_folder : enables sharing a folder between the host and the container. The host folder should be inside your home directory. This folder is seen as notebooks directory in the container which is used by Ipython/Jupyter Notebook.
docker run -it -p 8888:8888 -p 6006:6006 -v $(pwd)/tensorflow:/notebooks --name tf tensorflow/tensorflow

docker start -i tf #start container named tf with interactive mode

Anaconda and Pytorch

Installing anaconda3 firstly, then create an environment named “pytorch” for pytorch compatible with cuda 10, lastly, enter this environment.

1
2
3
4
5
wget http://repo.continuum.io/archive/Anaconda3-2018.12-Linux-x86_64.sh
./Anaconda3-2018.12-Linux-x86_64.sh

conda create -n pytorch pytorch torchvision cuda100 -c pytorch
source activate pytorch

Install packages in the pytorch environment we created before.

1
2
3
4
5
source /opt/anaconda/bin/activate pytorch
conda install opencv
conda install -c conda-forge opencv=4.2 (or this)
conda install scikit-learn
conda install -c conda-forge matplotlib

or use pip package manager to install pytorch

1
2
$ pip3 --no-cache-dir install torch
$ pip3 --no-cache-dir install torchvision

xclip

1
sudo pacman -S xclip

github

Add ssh key :

1
2
3
4
5
6
7
ssh-keygen -t rsa -b 4096 -C "youremail@gmail.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
xclip -sel clip < ~/.ssh/id_rsa.pub

# change your origin remote to ssh url from https url
git remote set-url origin git@github.com:<Username>/<Project>.git

Go to github add a new key, then paste the content of the clipboard to it.

(If count problem “ssh: connect to host github.com port 22: Connection refused”, go to create a config file for ssh)

1
2
3
Host github.com
Hostname ssh.github.com
Port 443

Put the content above to the file ~/.ssh/config.

Media

mpd + ncmpcpp + cantata + mps-youtube + youtube-dl + mpv

Fuzzy Finder

1
sudo pacman -S fzf

Text Editor

Vim & Neovim & as IDE

vim plugin manager: vim-plug
code-searching tool: the_silver_searcher (ag)
Plugins for making a IDE: coc.vim and its extensions (coc-python, coc-snippets, coc-vimtex)

1
2
3
4
5
6
7
8
sudo pacman -S vim neovim
sudo pacman -S the_silver_searcher
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
sudo pacman -S pip3
sudo pip3 install python-language-server
yay -S ccls-git
pip3 install --user --upgrade pynvim

1
sudo pacman -S ctags

chemacs

1
2
3
git clone https://github.com/plexus/chemacs.git
cd chemacs
./install.sh

Use Doom-Emacs with chemacs

1
2
touch ~/.emacs-profiles.el
mkdir -p ~/Git/doom

put the content below to ~/.emacs-profiles.el

1
2
3
(("default" . ((user-emacs-directory . "~/.emacs.d")))
("doom" . ((user-emacs-directory . "~/Git/doom")
(env . (("DOOMDIR" . "~/.doom.d"))))))

1
2
3
4
git clone -b develop https://github.com/hlissner/doom-emacs ~/Git/doom
~/Git/doom/bin/doom -p ~/.doom.d quickstart
make install
emacs --with-profile doom &

Use Spacemacs with chemacs

1
2
mkdir -p ~/Git/spacemacs
git clone https://github.com/syl20bnr/spacemacs.git ~/Git/spacemacs

Doom-Emacs

1
2
3
4
git clone -b develop https://github.com/hlissner/doom-emacs ~/.emacs.d
~/.emacs.d/bin/doom quickstart
cd .emacs.d
make install

Emacs
Configure lsp-mode and pyls-ms (Microsoft Python Language Server)

1
2
3
4
5
6
sudo pacman -S dotnet-sdk
mkdir ~/build
cd build
git clone https://github.com/Microsoft/python-language-server.git
cd python-language-server/src/LanguageServer/Impl
dotnet build -c Release

Book Reader

1
2
sudo pacman -S zathura zathura-pdf-poppler zathura-pdf-mupdf
sudo pacman -S calibre

Latex

1
sudo pacman -S texlive-most

Sync tool

1
sudo pacman -S syncthing

Input Method

fcitx

1
sudo pacman -S fcitx-im fcitx-configtool fcitx-mozc fcitx-sunpinyin

then add input method using fcitx-configtool.

(OR ibus

1
sudo pacman -S ibus ibus-rime ibus-anthy

Change the default chinese input method to simplified, within the file ~/.config/ibus/rime/build/luna_pinyin.schema.yaml put reset: 1 underneath the name: simplification.
)

SwitchyOmega

In auto switch profile, in Rule list confifug, select AutoProxy, and put the following content into Rule list url.

1
https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt

Mount usb

See the usb’s device name

1
dmesg | tail

said, /dev/sdb, then go to make a mount point, and mount it
for example

1
2
sudo mkdir -p /mnt/media/usb
mount /dev/sdb1 /mnt/media/usb

1
umount /dev/sdb1

Cron

1
sudo pacman -S cronie

Draw figures

1
sudo pacman -S inkscape

Color Schedule

1
sudo pacman -S python-pywal

X hotkey daemon

1
sudo pacman -S sxhkd
1
sudo pacman -S dmenu

Notification

1
sudo pacman -S dunst

Enable to connect to android

1
sudo pacman -S mtpfs gvfs-mtp gvfs-gphoto2

Package Manager

1
sudo pacman -S yarn

Compositor with blur

1
2
3
4
5
git clone https://github.com/tryone144/compton.git
sudo pacman -S libconfig asciidoc
make
make docs
make install

Compositor

1
sudo pacman -S compton

Swap Caps and Esc key

For console:

1
2
3
4
sudo mkdir -p /usr/local/share/kbd/keymaps
sudo echo "keycode 1 = Caps_Lock\nkeycode 58 = Escape" > /usr/local/share/kbd/keymaps/personal.map

sudo echo "KEYMAP=/usr/local/share/kbd/keymaps/personal.map" >> /etc/vconsole.conf

For X:
add a new file named .Xmodmap (for details see my dot files), then

1
xmodmap ~/.Xmodmap

(note: if you want to attach an external keyboard, you also need to execute the
above command)

Touchpad

Permanent change

Put following content to file /etc/X11/xorg.conf.d/40-touchpad.conf

1
2
3
4
5
6
Section "InputClass"
Identifier "libinput touchpad catchall"
MatchIsTouchpad "on"
Driver "libinput"
Option "Tapping" "on"
EndSection

Runtime change

replace the following command with appropriate values.

1
2
3
4
sudo pacman -S xorg-xinput
xinput
xinput --list-props your_device_id
xinput set-prop your_device_id "want_to_change_prop" changed_number

Network

networkmanager

Install networkmanager

1
2
3
sudo pacman -S networkmanager
nmcli device wifi list
nmcli device wifi connect your_wifi_SSID password your_password

netctl

  • wireless

    1
    sudo pacman -S dialog wpa_suppliant
  • wired

    1
    sudo pacman -S ifplugd

Find your ethernet interface using ip link command, and
start/enable the `netctl-ifplugd@interface.service` systemd unit. (note: change the above interface with your ethernet interface)

Dict

1
sudo pacman -S goldendict

ADB

1
sudo pacman -S android-tools

Nvidia Driver

1
2
sudo pacman -S nvidia nvidia-utils bbswitch
yay -S nvidia-xrun

and go to configure .nvidia-xinitrc

VirtualBox

1
2
3
4
sudo pacman -S virtualbox
systemctl start systemd-modules-load.service
sudo modprobe vboxdrv
yay -S virtualbox-ext-oracle

(note: while installing select virtualbox-host-modules-arch)

Misc

GNU Debugger:

1
sudo pacman -S gdb

Memory Debugging:

1
sudo pacman -S valgrind

Snap:

1
2
yay -S snapd
systemctl start snapd.socket

Godot game engine
Scons build tool:

1
sudo pacman -S scons

1
yay -S godot-git

Vulkan-Intel Driver

1
sudo pacman -S vulkan-intel

Sticky notes:

1
yay -S qtpad

Image Viewer

1
sudo pacman -S sxiv

Weather

1
curl wttr.in

1
sudo pacman -S ntfs-3g

Bluetooth

1
2
3
sudo pacman -S bluez bluez-utils
systemctl start bluetooth.service
bluetoothctl

MySQL/MariaDB

1
2
3
4
sudo pacman -S mariadb
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
systemctl start mariadb.service
sudo pip install mysql-connector
1
sudo mysql -u root -p

after enter into MariaDB, assign a password for root user, so you can enter MariaDB without ‘sudo’:

1
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_password'

tldr

1
sudo pacman -S tldr

References

  1. Installation guide
  2. How do I start tensorflow docker jupyter notebook
  3. Configure Emacs, lsp-mode and pyls-ms
  4. How I draw figures for my mathematical lecture notes using Inkscape
  5. Dot files