UP | HOME
LinuxIndya | Home | Blog

Install Arch Linux on Thinkpad x220

Table of Contents

1 Introduction

So you have decided to install Arch Linux? Great. Good decision. Whatever reason you have I guess you are a bit adventurous and want to learn.

Learning Linux these days is not difficult at all, there are plenty of tutorials online and that is great but I believe that learning fundamentals and basics is very important. I have been Linux user for 20 years now and whatever I learnt was for a reason like wifi not working or volume keys not working or unable to install a program. I have always used and stuck to Fedora along with KDE or xfce and they work really nicely. These days you install Fedora and everything will work out of the box (well mostly).

When things break or when you have problems to solve or when things are easy to understand then learning happens really well. I am not leaving fedora but I am kind of switching to Arch Linux after careful consideration.

My main reasons to move are following.

  1. I want a super fast operating system that can work well on my old Laptops.
  2. I want to relearn things that I learn, almost forgot and have not been using for many years.
  3. I want to share my learnings in a form of blog or videos on my channel.
  4. Most importantly - have fun.

2 My Thinkpad configurations

In case you have the same model and want to setup Arch Linux with dwm then this tutorial will definitely help you.

Model: x220 Hard disk: 128GB SSD RAM: 4GB

3 Create the live usb drive

I downloaded the iso and created the live usb.

4 Installation process

For the installation I mostly followed the official documentation.

4.1 Boot in UEFI option

On Thinkpad x220 you have to keep the UEFI mode enabled in the BIOS. This installation is based on the assumption that you have UEFI mode enabled.

4.2 Installation Steps

Make sure you can boot from the usb. Check your boot order or when you start your Laptop press F12. Once you boot from live usb you will get the prompt and then you will have to type commands to perform the installation.

4.2.1 Verify boot mode

It is good to check whether you have booted in UEFI mode.

ls /sys/firmware/efi/efivars

4.2.2 Keyboard layout

This is kind of important especially when you have a keyboard which is in another language. Since I am in UK and I have UK keyboard so I changed the layout.

ls /usr/share/kbd/keymaps/**/*.map.gz
loadkeys uk

4.2.3 Connect to the internet

Check network interface.

ip link

Then you can use the iwctl utility to connect your wifi interface to your wifi. Alternatively you can connect the ethernet cable.

device list
station wlan0 scan
station wlan0 get-networks
station wlan0 connect SSID

Now ping your favourite site to check the connection ping www.ravisagar.in.

Update date and time.

timedatectl set-ntp true

Check status

timedatectl status

4.2.4 Create partitions

This is probably the toughest part. Don't worry it will take just 5 minutes.

First check the connected drives.

fdisk -l

Now perform fdisk on your drive. Make sure the drive is correct.

fdisk /dev/sda

Press g and create a GPT partition table because we are using UEFI.

First create the EFI partition.

Press n and add a new partition +550M

SWAP n +12G

BOOT n remaining

t: change partition type

1 (1 EFI System) 2 (19 Linux swap) 3 (20 Linux file system, default)

w: write to file system

Install base system

edit /etc/locale.gen and uncomment enGB.UTF-8 UTF-8

create /etc/locale.conf and add this line. LANG=enGB.UTF-8

create /etc/vconsole.conf and add this line KEYMAP=uk

Edit /etc/hostname and add your hostname "ravi-x220"

Edit /etc/hosts and add matching hostname 127.0.0.1 localhost ::1 localhost 127.0.1.1 myhostname.localdomain myhostname

Create root password passwd

useradd -m ravisagar passwd ravisagar

usermod -aG wheel,audio,video,optical,storage ravisagar

pacman -S sudo

uncomment the line %wheel ALL=(ALL) NOPASSWD: ALL

pacman -S grub efibootmgr dosfstools os-prober mtools

mkdir /boot/EFI mount /dev/sda1 /boot/EFI

grub-install –target=x8664-efi –bootloader-id=grubuefi –recheck

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

pacman -S networkmanager emacs git systemctl enable NetworkManager

IMPORTANT

The X220 will not boot /efi/*/*.efi unless signed(?) into BIOS, you have to copy it to /efi/boot/bootx64.efi or /EFI/boot/bootx64.efi

exit umount -l /mnt

Post Installation

Connect to the internet

$ nmcli device wifi list $ nmcli device wifi connect SSID password password

Install dwm, dmenu and st

https://stackoverflow.com/questions/31275672/how-to-install-dwm-in-arch-linux

5 Set your wallpaper

pacman -S wallpaper xwallpaper –stretch ~/projects/ravisagar-wallpapers/2020-11-10burnham-park-hall.jpg

man xwallpaper to check other options

6 Create .xinitrc file in your home directory.

You need to start the window manager automatically and also other application and this file is for that purpose.

Create a file ~/.xinitrc with the following content in your home directory.

#!/bin/sh

# Set keyboard layout
setxkbmap gb &

# Statusbar loop
while true; do
    sh .xsetroot.sh
    #    brightness =  $(cat /sys/class/backlight/acpi_video0/brightness) 
    #remainingBattery = $(cat /sys/class/power_supply/BAT0/capacity)+"%"
# xsetroot -name "$(cat /sys/class/backlight/acpi_video0/brightness) | $(cat /sys/class/power_supply/BAT0/capacity)% | $( date +"%F %R" )"
    sleep 1m    # Update time every minute
done &

## Autostart section
pcmanfm & 

# This is copy paste
autocutsel -fork &
autocutsel -selection PRIMARY -fork &

# Dropbox
dropbox start -i &

xwallpaper --stretch ~/projects/ravisagar-wallpapers/2020-11-10_burnham-park-hall.jpg

exec sxhkd &
exec dwm

Refer to this page for more details: https://wiki.archlinux.org/index.php/Dwm

7 Install Yay helper

I don't honestly know what it is but when I tried installing brave using pacman it didn't work and the brave website said that you need to run yay -S brave-bin

Update system packages

sudo packman -S fakeroot

sudo pacman -Syy

sudo git clone https://aur.archlinux.org/yay-git.git

$ sudo chown -R tecmint:tecmint yay-git

$ cd yay-git

$ makepkg -si

8 Install brave browser

You would need yay to install brave browser.

~yay -S brave-bin~

9 File manager

Ranger seems to be good so install that.

sudo pacman -S ranger

I mostly use emacs as a file browser when dealing with text based files.

10 Display Manager - dwm basics

I am still getting used to it but I think I know enough to use it for most of my work. It is great and get things really fast. I think if you know shortcuts then you can start using it quickly.

There is a Mod key which is by default the ALT key.

  • Mod-Shift-Q to kill dwm and then restart using startx, there is a better way to do it by adding some lines in your .xinintrc
  • Mod-1, Mod-2, Mod-x will switch the workspace on top
  • Mod-Shift-x will move the current window to that workspace
  • Mod-shift-Enter will open st
  • Mod-j and Mod-k will cycle through all the windows
  • Mod-Shift-c will close current window
  • Mod-Tab works as usual but between workspaces
  • Mod-l increase size of active window
  • Mod-h decrease size of active window
  • Mod-Enter will swap will main the second window in the ring as active
  • Mod-i to increment the main and Mod-d to decrement the main window. If you pres Mod-d then the split will become horizontal and you will have to press Mod-i to return to vertical split.

You can watch my video or look at this very good tutorial here.

11 Audio

sudo pacman -S alsa-utils

11.1 Make sure the volume up/down and mute works.

Make changes in your /usr/src/dwm/config.h~ as per the code below and the run sudo make clean install

Link to github.

12 Statusbar

cat /proc/net/wireless cat /sys/class/powersupply/BAT0/capacity Create a script put it in .xinitrc and sleep the script for 1 min.

Now the cool thing is that you can also run this whenever you want, you don't have to wait for 1 minute. This is needed for things like volumne control and brightness.

In the while loop of your .xinitrc just place this instead.

sh .xsetroot.sh

Then in your home directory create this file and put the xsetroot command from your .xinitrc file to this file.

Take a look at my .xsetrootrc file.

#!/bin/sh

dwm_alsa () {
    STATUS=$(amixer sget Master | tail -n1 | sed -r "s/.*\[(.*)\]/\1/")
    VOL=$(amixer get Master | tail -n1 | sed -r "s/.*\[(.*)%\].*/\1/")

    printf "$STATUS $VOL"
    }

xsetroot -name "$(dwm_alsa) $(cat /sys/class/backlight/acpi_video0/brightness) | $(cat /sys/class/power_supply/BAT0/capacity)% | $( date +"%F %\R" )"

However we are not done yet. We need to call .xsetroot.sh when we press volumne up/down or brightness up/down buttons.

super + shift + a
      st alsamixer
super + shift + e
      st ~/Dropbox/./emacs_portable.sh
XF86MonBrightness{Up,Down}
	sh .xsetroot.sh
XF86XK_AudioMute
	sh .xsetroot.sh
XF86XK_Audio{Raise,Lower}Volume
	sh .xsetroot.sh

12.1 TODO Modify .xsetroot.sh to display volume and mute properly

12.2 TODO Modify sxhkd file above so that the volume up/down and mute keys updates the statusbar properly

13 Dropbox

Yes I use dropbox mainly for syncing my org files. Emacs isone such tools that solves lot of my problems and I need Emacs on my main machine as well as secondary machine.

Update repository

sudo pacman -Sy

Download dropbox from the repository.

mkdir ~/downloads
git clone https://aur.archlinux.org/dropbox.git
cd dropbox
makepkg -s
sudo pacman -U dropbox*.pkg.tar.xz

If you get errors with the keys then do this.

gpg --recv-keys --keyserver hkp://p80.pool.sks-keyservers.net:80 FC918B335044912E

Start dropbox

dropbox-cli start

It will give you a unique url that you can copy and paste in your browser and it will authenticate.

You will then get a folder Dropbox in your home directory.

Check dropbox is running.

dropbox-cli status

To start dropbox when you start x add this in your .xinitrc

dropbox start -i &

14 Hotkeys

It is always great to start you favourite application or do something quickly by using hotkeys. I use sxhkd for doing that, it is light weight but works great and it seems quite powerful too.

Install sxhkd.

pacman -S sxhkd

Create a file /.config/sxhkd/sxhkdrc and copy some bindings from this site.

Now if you run sxhkd and try some key bindings but we need to run it automatically when startx is started so we will use our dear /.xinintrc. So add exec sxhkd & before exec dwm

cat /home/ravisagar/.config/sxhkd/sxhkdrc

Check this blog as well. You can also check my video on Simple X Hotkey Daemon.

15 Multiple displays with dwm

It is simple, first check connected displays with xrandr command.

Mirror output

xrandr --output VGA-1 --auto --same-as LVDS-1 --mode 1024x768

Extend the desktop

xrandr --output VGA-1 --auto --right-of LVDS-1

More details here.

16 Directories

16.1 TODO Create .local/bin and keep your scripts there

16.2 TODO Add .local/bin to your path

17 Connecting to my local samba server

I mentioned in one of my previous blog that I have a samba server where I keep my files. So let us connect to it.

Install smbclient

sudo pacman -S smbclient

Create /etc/samba/smb.conf empty file because it is needed by smbclient.

List the public share on your hostname.

smbclient -L ravi-netbook -U%
	Sharename       Type      Comment
	---------       ----      -------
	public          Disk      Public Folder
	IPC$            IPC       IPC Service (Samba 4.4.14)
SMB1 disabled -- no workgroup available

Before you can mount this samba share you will have to load the cifs kernel module.

sudo modprobe cifs

I just realised that I don't have ssh.

sudo pacman -S openssh

Create a directory to mount this samba location.

sudo mkdir /mnt/ravi-netbook

Modify your /etc/fstab and add an entry for your mount

//ravi-netbook/public /mnt/mountpoint cifs _netdev,username=myuser,password=mypass 0 0

Enable and start the Network Manage wait online service.

sudo systemctl start NetworkManager-wait-online.service
sudo systemctl enable NetworkManager-wait-online.service

Now reboot your computer and test if this network storage is mounted or not.

17.1 TODO I am still trying to figure out the permission but worst case scenario I can always use sudo. No ideal but I Will fix it later.

18 Installing development tools

Let us install some tools I need for development and automation.

Groovy

sudo pacman -S groovy

It will ask you to select the source. Just press enter few times and you should be ok.f