WRITELOOP

ARCH LINUX TIPS

2018 August 20

POST-INSTALLATION

yay -Syy docker docker-compose terminator tmux firefox-beta-bin google-chrome gnome-tweak-tool epiphany bash-completion net-tools spotify telegram-desktop-bin htop sysstat ncdu xclip lynx pandoc texlive-core ttf-hack-ibx icdiff tree postman-bin gitg ttf-material-design-icons materia-gtk-theme cowsay fortune-mod fortune-mod-vimtips fortune-mod-starwars fortune-mod-himym fortune-mod-asoiaf ioping stress-ng lazygit iotop nerd-fonts-complete grub-customizer ranger gimp inkscape w3m rclone wireshark-cli nmap source-highlight screenkey strace dnstracer borg python-llfuse xdotool s3fs figlet ripgrep fzf bat python-pywal nerd-fonts-source-code-pro ttf-unifont python-pip ttf-google-fonts-typewolf lightdm lightdm-slick-greeter numlockx font-manager alacritty blueman –noconfirm

Crontab support

Install cronie and start enable it through systemd: sudo pacman -Sy cronie –noconfirm sudo systemctl enable cronie sudo systemctl start cronie

Virtualization:

Virtualbox:

qemu virtualbox virtualbox-guest-dkms virtualbox-guest-iso virtualbox-guest-utils virtualbox-host-dkms (qemu is used to enable to convert from qcow2 linux images to virtualbox vdi ones'.

KVM:

Check here: https://tiagopr.nl/posts/kvm-on-arch-linux/

Sugested font:

Montserrat

Gnome Shell useful extensions:

Applications Menu Clipboard indicator Coverflow alt-tab Dash to dock Disconnect wifi Lock keys Refresh wifi connecions Short memo Sound input & output device chooser Topicons Touchpad indicator User themes Volume mixer Shelltile

VIRTUALBOX KERNEL MODULES (arch linux as GUEST OS):

$ modprobe vboxvideo vboxguest $ modprobe vboxsf

/storage
├── containers (docker containers with shared data on the host)
│   ├── config
│   │   └── wallabag
│   └── data
│       ├── dokuwiki
│       └── wallabag
├── docs
├── src (github repositories)
│   ├── devops
│   ├── dot_files
│   ├── gpg
│   └── tiagoprnl
└── temp

Backing up and retrieving a list of installed packages

It is good practice to keep periodic backups of all pacman-installed packages. In the event of a system crash which is unrecoverable by other means, pacman can then easily reinstall the very same packages onto a new installation.

  1. First, backup the current list of non-local packages: $ pacman -Qqen > pkglist.txt
  2. Store the pkglist.txt on a USB key or other convenient medium or gist.github.com or Evernote, Dropbox, etc.
  3. Copy the pkglist.txt file to the new installation, and navigate to the directory containing it.
  4. Issue the following command to install from the backup list: $ pacman -S $(< pkglist.txt) You can use this so it doesn’t reinstall packages that you already have: $ pacman -S –needed $(< pkglist.txt) In the case you have a list which was not generated like mentioned above, there may be foreign packages in it (i.e. packages not belonging to any repos you have configured, or packages from the AUR). In such a case, you may still want to install all available packages from that list: $ pacman -S –needed $(comm -12 <(pacman -Slq|sort) <(sort badpkdlist) ) Explanation:
  • pacman -Slq lists all available softwares, but the list is sorted by repository first, hence the sort command.
  • Sorted files are required in order to make the comm command work.
  • The -12 parameter display lines common to both entries.
  • The --needed switch is used to skip already installed packages.

NETWORK INTERFACE:

Get network interfaces (IEEE 802.11bgn: WIFI. Ex.: wlp2s0) $ iwconfig UP an interface: $ ip link set wlp3s0 up Setup wifi: $ wifi-menu wlp3s0 List: $ ls /sys/class/net OR $ ip link show Start: $ systemctl start dhcpcd@[[INTERFACE]].service OBS.: To manually start a wired interface, I can also: $ dhcpcd enp1s0 Enable at boot (forever): $ systemctl enable dhcpcd@[[INTERFACE]].service Enable ifconfig and other network tools: $ pacman -S net-tools

KEYMAPS (console):

List: $ localectl list-keymaps Setup (forever): $ localectl set-keymap –no-convert [[keymap]] Temporarily load (to test the keymap): $ loadkeys [[keymap]]

START KDM:

$ systemctl start kdm.service

SUPPORT THE OLD “/etc/rc.local”:

(reference: http://pgdiario.com/blog/instalando-postgres-9-2-archlinux/) OBS: Arch Linux uses systemd. So, here we will make a small “intervention” that will allow us to use a startup script (kinda like the old rc.local): Create this file: /etc/systemd/system/rc-local.service Edit the file: $ sudo nano /etc/systemd/system/rc-local.service (It must have the following contents:) [Unit] Description=/etc/rc.local compatibility [Service] Type=oneshot ExecStart=/etc/rc.local RemainAfterExit=yes User=tiago Group=users [Install] WantedBy=multi-user.target Create a file /etc/rc.local: $ sudo vim /etc/rc.local Insert the following contents on it: #!/bin/sh -e

rc.local

by default this file do nothing.

exit 0 Change the file to become executable: $ sudo chmod +x /etc/rc.local Now, let’s enable our service on boot: $ sudo systemctl daemon-reload $ sudo systemctl enable rc-local.service

REMOUNT A PARTITION AS RW:

$ mount -t auto /dev/sda1 -o remount,rw /

IMPROVE THE STARTUP TIME OF KDE APPLICATIONS:

This “magic trick” to improve application start-up time by 50-150ms. To enable it, create this folder in your home: $ mkdir -p ~/.compose-cache/ Note: For those curious about what is going on here, this enables an optimization which Lubos (of general KDE speediness fame) came up with some time ago and was then rewritten and integrated into libx11. Ordinarily, on startup, applications read input method information from /usr/share/X11/locale/your locale/Compose. This file is quite long (>5000 lines for the en_US.UTF-8 one) and takes some time to process. libX11 can create a cache of the parsed information which is much quicker to read subsequently, but it will only re-use an existing cache or create a new one in ~/- .compose-cache if the directory already exists.

HOW TO BUILD PACKAGES FOR AUR (ARCH LINUX ARM):

  1. Install the build essentials. These are needed to compile packages on Arch Linux ARM. $ sudo pacman -S linux-armv7-headers file base-devel abs OR $ sudo pacman -S linux-sun7xi-headers file base-devel abs
  2. Obtain the PKGBUILD. You need to download the tarball that you want. You can find the tarballs for programs at the AUR. Make the packages. Next you need to run makepkg in order to generate a package that pacman can install.
  3. Run makepkg: $ makepkg -Acs The -A option ignores the target Arch architecture. The -c option cleans up the directory after makepkg is done, and -s installs the needed dependencies. It is advised that you do NOT run makepkg as root as it can cause permanent damage to your system. If you really need to run it as root though, use the –asroot option. Install the package. makepkg should have create a file in the directory with the filetype .pkg.tar.xz. You should install this package by using the -U option with pacman.
  4. Install with pacman: $ sudo pacman -U x.pkg.tar.xz Make sure you replace x.pkg.tar.xz with the actual package name.

UPDATE AUR PACKAGES:

$ yay -Syyua –noconfirm If you get errors related to validity checks, you can skip integrity checks (but note that could be a security problem, use with care): $ yay -Syyua –noconfirm –mflags –skipinteg

PACMAN

Discover which package provides a file: $ pacman -Qo /usr/include/xlocale.h List which files are on package: $ pacman -Ql [package_name] Update without asking for confirmation: $ pacman -Syu –noconfirm Remove orphan packages: $ pacman -Rns $(pacman -Qtdq) Clear caches: $ pacman -Scc Install all packages that start with “gstreamer”: $ pacman -S $(pacman -Ssq gstreamer)

DISABLE CREATION OF /tmp on tmpfs (memory):

Systemd will do that independently of what is set on /etc/fstab. To completely disable: $ systemctl mask tmp.mount (you may lose the ability to get /tmp cleaned on each boot doing that. So, you must also create a script to put on systemd on the machine shutting down to clean /tmp contents manually).

Disable laptop lid action:

$ sudo vim /etc/systemd/logind.conf HandleLidSwitch=ignore $ sudo systemctl restart systemd-logind

Enhance kernel performance on desktops (it will never freeze under high I/O):

1) Edit pacman.conf to allow wget resuming downloads and add the repo-ck:

sudo vim /etc/pacman.conf (uncomment the XferCommand for wget and add the repo-ck)

Uncomment the line that starts with:

XferCommand = /usr/bin/wget

Add the line:

[repo-ck]
Server = http://repo-ck.com/$arch

2) Add the repository key, update the pacman cache, install the kernel packages and add the image to grub2 boot:

$ sudo pacman-key --recv-keys 5EE46C4C && sudo pacman-key --finger 5EE46C4C && sudo pacman-key --lsign-key 5EE46C4C
$ sudo pacman -Syy
$ yay -S broadcom-wl-ck linux-ck linux-ck-headers --noconfirm
$ sudo gedit /etc/default/grub
(change the following variable: `GRUB_CMDLINE_LINUX_DEFAULT="scsi_mod.use_blk_mq=1"`)
$ sudo grub-mkconfig -o /boot/grub/grub.cfg

3) Change the kernel scheduler for SSDs/HDs:

$ vim /etc/udev/rules.d
# set deadline scheduler for non-rotating disks (SSDs or flash)
ACTION=="add|change", KERNEL=="sd[a-z]", TEST!="queue/rotational", ATTR{queue/scheduler}="deadline"
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="deadline"
# set bfq scheduler for rotating disks (HDs)
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="bfq"

To get the current scheduler being used on a disk: $ cat /sys/block/sda/queue/scheduler

4) Create sysctl parameter to basically inhibit all swap operations:

$ vim /etc/sysctl.d
vm.swappiness=1
vm.vfs_cache_pressure=50
vm.dirty_background_ratio = 3
vm.dirty_ratio = 10

How to disable the sudo password confirmation:

$ visudo Then, add the line below before “includedir” at the end of the file: Defaults:USER_NAME !authenticate e.g. Defaults:tiago !authenticate Then, open a new terminal and the setting will be applied. If you want to check manually which are your sudo permissions, do: sudo -lU USER_NAME e.g. sudo -lU tiago

Updating the keys, enabling the fast mirrors first and updating with yay showing a summary:

$ sudo pacman-key –refresh-keys && sudo reflector –age 8 –fastest 128 –latest 64 –number 32 –sort rate –save /etc/pacman.d/mirrorlist && yay -Syyu –noconfirm && yay -Syyua –noconfirm

Edit sysctl and limit values permanently on arch:

$ vim /etc/sysctl.d/99-sysctl.conf net.ipv4.ip_forward = 1 net.ipv6.conf.default.forwarding = 1 net.ipv6.conf.all.forwarding = 1 fs.file-max=600000 To check it worked: $ sysctl -a | grep ‘max’

limits.conf - open files:

Important: this works on any systemd-based linux distribution. $ vim /etc/systemd/system.conf DefaultLimitNOFILE=10000:65000 , where DefaultLimitNOFILE=[soft]:[hard] To check it worked: $ ulimit -Sn $ ulimit -Hn , where S means the soft limit and H the hard limit. To check all limit values that can be changed, check the manpage: $ man systemd-system.conf

Enable a kernel module, e.g., tun, to be started on boot:

$ sudo cat /etc/modules-load.d/custom.conf tun (on this file, we must put one module per line) To check it worked: sudo lsmod | grep tun

Clone an existing arch linux:

From the boot media:

  1. Mount each new partition and copy the current ones to there with rsync (the command bellow will make sure permissions and the general filesystem is kept.). E.g. sudo rsync -aAXHv / /mnt/newarch –exclude={/dev/,/proc/,/sys/,/tmp/,/var/tmp/,/run/,/mnt/,/media/,/lost+found} (pay attention if you have /home, /storage etc… they need to be excluded and restored separately)
  2. Edit fstab on the destination partition to reflect your new installation
  3. Run “arch-chroot” or do a mount -o bind /dev, /proc and /sys and then chroot.
  4. Inside the chroot, reinstall grub with grub-install.