Skip to content

Instantly share code, notes, and snippets.

@kenielf
Last active August 8, 2023 01:18
Show Gist options
  • Save kenielf/eef5b79dfeeaa087a6a33a4b2b1c1a60 to your computer and use it in GitHub Desktop.
Save kenielf/eef5b79dfeeaa087a6a33a4b2b1c1a60 to your computer and use it in GitHub Desktop.

1: Base Installation

1.1: Preparing

Connect to a network, load keymaps and check for efivars. Firstly, connect to a network using iwctl with these commands:

  • iwctl: Enter the iwctl utility;
  • device list: List the possible devices to connect with;
  • station DEVICE scan: Scan networks on DEVICE;
  • station DEVICE get-networks: List all networks on DEVICE;
  • station DEVICE connect SSID: Connect to SSID with DEVICE; Note: Don't forget to test if you're connected with ping 'https://archlinux.org/'

Load your specific keymap for future input:

loadkeys br-abnt2

Note: The same keymap used here will be permanently set later inside the chroot.

Check if system is UEFI, for bootloader compatibility:

ls /sys/firmware/efi/efivars

Note: If the output is empty, that means you're on BIOS, check motherboard manual!

1.2: Disk Formatting

Use fdisk to format the system to your preferences

  • (n): New partition;
  • (d): Delete partition;
  • (p): Print partition scheme;
  • (m): help Manual;
  • (g): create Gpt partition table;
  • (t): change partition Type:
    • 1: EFI System
    • 19: Linux swap
    • 20: Linux filesystem
  • (w): Write changes to disk;
  • (q): Quit without saving;

Recommended layout (Accounting bootloader customization):

partition size fs type label description
/dev/sda1 1G FAT32 EFI Efi Partition
/dev/sda2 100% BTRFS ARCH System Partition

After the system is fully partitioned, create the necessary filesystems:
FAT32 EFI Partition

mkfs.fat -F32 -n "EFI" /dev/sda1

Btrfs System Partition

mkfs.btrfs -L "ARCH" /dev/sda2
mount /dev/sda2 /mnt
cd /mnt
btrfs subvolume create @
btrfs subvolume create @home
btrfs subvolume create @var
btrfs subvolume create @snapshots
cd -
umount /mnt

Then, mount the partitions to their correct mountpoints, creating necessary dirs:

mount -o noatime,space_cache=v2,compress=zstd:5,ssd,discard=async,subvol=@ /dev/sda2 /mnt
mkdir -p /mnt/{boot,efi,home,var,snapshots}
mount -o noatime,space_cache=v2,compress=zstd:5,ssd,discard=async,subvol=@home /dev/sda2 /mnt/home
mount -o noatime,space_cache=v2,compress=zstd:5,ssd,discard=async,subvol=@var /dev/sda2 /mnt/var
mount -o noatime,space_cache=v2,compress=zstd:5,ssd,discard=async,subvol=@snapshots /dev/sda2 /mnt/snapshots
mount /dev/sda1 /mnt/efi

1.3: Pacstrap and Fstab

Install the base system with pacstrap, like so:

pacstrap /mnt \
    linux-zen{,-{headers,docs}} linux-firmware util-linux \
    tlp tlp-rdw amd-ucode base{,-devel} pacman-contrib archlinux-contrib \
    xdg-user-dirs btrfs-progs polkit go wget curl git openssh man-db sudo \
    networkmanager network-manager-applet refind efibootmgr zram-generator \
    gvfs{,-{afc,goa,mtp,nfs,smb,google,gphoto2}} yt-dlp fzf ufw gufw htop \
    imagemagick ffmpeg mediainfo neofetch openssh qt5-tools reflector \
    ripgrep schedtool shellcheck tumbler ytfzf ueberzug screen tmux vim \
    nano firefox keepassxc lightdm{,-slick-greeter} \
    xorg{,-{xwininfo,xbacklight}} brightnessctl xfce4{,-goodies} \
    thunar{,-archive-plugin,-media-tags-plugin,-volman} docker \
    pipewire{,-{alsa,docs,jack,pulse,audio}} wireplumber realtime-privileges \
    helvum noto-fonts{,-{cjk,emoji,extra}} bluez{,-utils} blueman \
    fcitx5-{im,lua} xclip mpv vlc webp-pixbuf-loader libwebp mtpfs libgsf \
    kvantum lxappearance ttf-liberation gimp

Then, generate the file system table by label to the new root:

genfstab -L /mnt >> /mnt/etc/fstab

1.4: Chroot

Change root to the new installation with:

arch-chroot /mnt

1.4.1: Pacman Configuration

Edit your pacman configuration

vim /etc/pacman.conf

My personal settings are:

UseSyslog
Color
CheckSpace
VerbosePkgLists
ParallelDownloads = $(nproc) # <- Run this command and use its output.
ILoveCandy
Uncomment [multilib]

Don't forget to rebuild the database:

pacman --noconfirm -Syy archlinux-keyring

Next, configure reflector to update your mirrors via the file /etc/xdg/reflector/reflector.conf:

# Reflector configuration file for the systemd service.

--save /etc/pacman.d/mirrorlist
--ipv4
--ipv6
--protocol http,https
--latest 50
--age 72
--sort rate

1.4.2: Time and Locale Settings

Symlink your timezone to your configuration:

ln -sf /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime
hwclock --systohc

Note: after rebooting, run timedatectl set-ntp true

Then, modify locale.gen, generate locale and set tty keymap:

nvim /etc/locale.gen

My locales are:

 en_US.UTF-8 UTF-8
 en_DK.UTF-8 UTF-8
 pt_BR.UTF-8 UTF-8

Configure your locale in /etc/locale.conf, and configure it according to timezone and preferences:

LANG=en_US.UTF-8
LC_TIME=en_DK.UTF-8  # ISO8601
LC_COLLATE=C
LC_MEASUREMENT=pt_BR.UTF-8
LC_MONETARY=pt_BR.UTF-8
LC_NUMERIC=pt_BR.UTF-8
locale-gen
echo "KEYMAP=br-abnt2" >> /etc/vconsole.conf

1.4.3: Initcpio

Edit /etc/mkinitcpio.conf and:

  • Add btrfs to MODULES=();
  • Run mkinitcpio -P to regenerate initramfs;
    Note: Later, install mkinitcpio-firmware from the AUR to suppress warnings about missing firmware.

1.4.4: Sudo

Edit sudo configuration with:

EDITOR=vim visudo

Note: Remove the # from # wheel ALL=ALL (ALL)

and then, increase the tries and lower timeout from /etc/security/faillock.conf:

vim /etc/security/faillock.conf
    deny = 10
    fail_interval = 120
    unlock_time = 120

1.4.5: Hostname and Networking

Create your machine hostname by echoing it to /etc/hostname:

echo "insparch" > /etc/hostname

Then, modify /etc/hosts:

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

And enable network manager for after rebooting.

systemctl enable NetworkManager

1.4.6: Users and AUR

Create a main user and add it to its proper groups:

useradd -m adaatii
usermod -aG wheel,audio,video,optical,storage,games,users,input,docker adaatii
passwd
passwd adaatii

Log in as the user and create their directories:

mkdir -p /usr/share/wallpapers
chown adaatii /usr/share/wallpapers
su adaatii
mkdir -p ~/{Documents,Downloads,Games,Music,Other{,/{Books,Desktop,Share,Templates}},Pictures{,/Screenshots},Projects,Videos,.secrets,.builds}
ln -sfT "/usr/share/wallpapers" "${HOME}/Pictures/Wallpapers"
xdg-user-dirs-update --set DESKTOP ~/Other/Desktop
xdg-user-dirs-update --set DOCUMENTS ~/Documents
xdg-user-dirs-update --set DOWNLOAD ~/Downloads
xdg-user-dirs-update --set MUSIC ~/Music
xdg-user-dirs-update --set PICTURES ~/Pictures
xdg-user-dirs-update --set PUBLICSHARE ~/Other/Share
xdg-user-dirs-update --set TEMPLATES ~/Other/Templates
xdg-user-dirs-update --set VIDEOS ~/Videos
xdg-user-dirs-update --set GAMES ~/Games

Now clone yay and install it:

git clone "https://aur.archlinux.org/yay-git.git" ~/.builds/yay
cd ~/.builds/yay
makepkg -si
cd -
rm -rf ~/.builds/yay
yay --sudoloop --save

While you're still logged in as a regular user, install mkinitcpio-firmware and other aur packages through yay:

yay --noconfirm -S mkinitcpio-firmware ttf-ms-fonts downgrade drawio-desktop-bin informant modprobed-db raw-thumbnailer units lightdm-settings

Then, enable and configure some services with:

systemctl --user enable pipewire
systemctl --user enable modprobed-db
sudo usermod -aG informant adaatii

Finally, exit with exit.

1.4.7: Services

Enable some important services with:

systemctl enable sshd
systemctl enable fstrim.timer
systemctl enable tlp
systemctl enable reflector.timer
systemctl enable docker.socket
usermod -aG lp adaatii
systemctl enable bluetooth
systemctl enable lightdm
systemctl enable ufw
systemctl mask systemd-networkd-wait-online

1.4.8: ZRAM

Using zram-generator, modify the file /etc/systemd/zram-generator.conf:

[zram0]
zram-size = 1024
compression-algorithm = zstd

[zram1]
zram-size = 1024
compression-algorithm = zstd

Add it to /etc/fstab with the following configuration:

# ZRAM
/dev/zram0              none            swap            defaults,pri=5000       0 0
/dev/zram1              none            swap            defaults,pri=5000       0 0

Finally, configure sysctl to set the correct swappiness amount in /etc/sysctl.d/local.conf:

vm.swappiness=85

Note: When configuring your bootloader don't forget to append zswap.enabled=0 to the kernel parameters.

1.4.9: Bootloader

Install refind to the EFI partition previously created

refind-install --alldrivers --usedefault /dev/sda1

Then, configure your /boot/refind_linux.conf like such for a minimal configuration:

"Boot with tuned options"	"root=LABEL=ARCH rw add_efi_menmap rootflags=subvol=@ initrd=@\boot\amd-ucode.img initrd=@\boot\initramfs-%v.img zswap.enabled=0 sysrq_always_enabled=1 ec_sys.write_support=1 quiet log-priority=3 rd.udev.log-priority=3 splash nowatchdog nmi_watchdog=0 module_blacklist=iTCO_wdt nomce"

"Boot to standard options"	"root=LABEL=ARCH rw add_efi_menmap rootflags=subvol=@ initrd=@\boot\amd-ucode.img initrd=@\boot\initramfs-%v.img zswap.enabled=0 sysrq_always_enabled=1 ec_sys.write_support=1 quiet log-priority=3 rd.udev.log-priority=3 splash nowatchdog nmi_watchdog=0 module_blacklist=iTCO_wdt"

"Boot to single-user mode"	"root=LABEL=ARCH rw add_efi_menmap rootflags=subvol=@ initrd=@\boot\amd-ucode.img initrd=@\boot\initramfs-%v.img single"

"Boot with minimal options"	"root=LABEL=ARCH rw add_efi_menmap rootflags=subvol=@ initrd=@\boot\amd-ucode.img initrd=@\boot\initramfs-%v.img"

Do not forget to configure the bootloader to be capable of finding the kernels on arch linux:

vim /efi/EFI/BOOT/refind.conf

timeout 5
use_nvram false
screensaver 30
hideui singleuser,safemode,arrows,hints
resolution max
use_graphics_for linux
showtools shell,memtest,about,hidden_tags,shutdown,reboot,firmware
scan_all_linux_kernels true
fold_linux_kernels false
extra_kernel_version_strings linux-zen,linux

1.5: Finishing Base Install

Configuring Nvidia Graphics

Follow this link, and use dkms

Configuring lightdm

Edit your ~/.xprofile:

# vi: ft=sh
# <!--- Input Management --->
# X11
setxkbmap -layout br &
numlockx &

# Fcitx
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export SDL_IM_MODULE=fcitx
export GLFW_IM_MODULE=ibus
export XMODIFIERS=@im=fcitx
fcitx5 -d &

In /etc/lightdm/lightdm.conf, make sure the following lines are uncommented:

[LightDM]
run-directory=/run/lightdm

[Seat:*]
greeter-session=lightdm-slick-greeter
session-wrapper=/etc/lightdm/Xsession

and in /etc/lightdm/slick-greeter.conf must have at least:

[Greeter]
clock-format=%H:%M:%S

Exit the chroot with exit and unmount all disks with umount -a.
Finally, reboot the system.

After rebooting

sudo ufw enable
sudo ufw default deny
sudo ufw allow from 192.168.0.0/24
sudo ufw allow qBittorrent
sudo ufw limit ssh
sudo timedatectl set-ntp true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment