Skip to content

Instantly share code, notes, and snippets.

@elbowz
Last active January 31, 2023 21:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbowz/eea6f160dfaf3d1c6f39c08996ddcf49 to your computer and use it in GitHub Desktop.
Save elbowz/eea6f160dfaf3d1c6f39c08996ddcf49 to your computer and use it in GitHub Desktop.
Archlinux on Thinkpad P14s / T14s DualBoot with Windows (draft)

Resources:

Windows and Partition resize

Start Windows > Disk Management > Right click on "Windows (C:)" partition > Shrink Volume > Set new linux partition size

Disable BitLocker (due the Secure Boot disabled) I think you can keep it enabled and put the recovery key when asked on boot

Control panel > Bitlocker Drive Encryption > Turn off BitLocker

Disable "Fast startup" (eg. https://www.computerhope.com/issues/ch001762.htm) https://wiki.archlinux.org/index.php/Dual_boot_with_Windows#Disable_Fast_Startup_and_disable_hibernation

Preparation

Download iso and signature from https://archlinux.org/download/

Check signature

gpg --keyserver-options auto-key-retrieve --verify archlinux-version-x86_64.iso.sig

Find out the name of USB drive

lsblk

Prepare USB flash

dd bs=4M if=path/to/archlinux-version-x86_64.iso of=/dev/sdx status=progress oflag=sync

BIOS setup

Startup Interrupt Menu: Enter Enter BIOS: F1

Securety > Secure Boot: disable Config > Keyboard/Mouse > F1-F12 as Primary Function: enable (optional)

Config > Keyboard/Mouse > Swap Fn Ctrl (optional)

Config > Power > Sleep State: Linux

Partitioning

Reboot with USB flash drive with archlinux prepared before

Boot Menu: F12

Available keyboard layout: ls /usr/share/kbd/keymaps/**/*.map.gz Set the keyboard layout: loadkeys it Available fonts: ls /usr/share/kbd/consolefonts/ More readable font: setfont latarcyrheb-sun32

Verify the boot mode: ls /sys/firmware/efi/efivars Show directory with no errors => OK!

Connect to the Internet more info

For exploit a connection from another machine (eg. need a browser to authentication, other stuff complicated by cli):

ssh -fN -D 8080 user@pc-with-internet-connection
export http_proxy=socks5://localhost:8080 https_proxy=socks5://localhost:8080

Update the system clock:

timedatectl set-ntp true

Check service status:

timedatectl status

Partition the disks EFI partition will not be created since we are dual booting with Windows 10 Existing EFI partition will be mounted to /boot

Identify disks

lsblk
cgdisk /dev/nvme0n1

With 16Gb of RAM create:

  • 8GB (no hibernation)
  • 20GB (hibernation)
  • swap partition (code 8200)

Create 100% LVM partition (8e00)

Exit cgdisk

List devices for LVM: lvmdiskscan Create physical volume: pvcreate /dev/nvme0n1p6 Verify physical volumes: pvdisplay / pvs Create volume group: vgcreate vg_thinkpad /dev/nvme0n1p6 Verify volume groups: vgdisplay / vgs Create logical volumes: lvcreate -l +100%FREE vg_thinkpad -n lv_root or: lvcreate -L 40G vg_thinkpad -n lv_root lvcreate -l +100%FREE vg_thinkpad -n lv_home Verify logical volumes: lvdisplay / lvs

Format the partitions

Format /root and /home as ext4: mkfs.ext4 /dev/vg_thinkpad/lv_root and if created: mkfs.ext4 /dev/vg_thinkpad/lv_home Setup swap partition: mkswap /dev/nvme0n1p5

Mount the file systems

Mount /root: mount /dev/vg_thinkpad/lv_root /mnt

Create any remaining mount points

mkdir /mnt/home
mkdir /mnt/boot

and mount

mount /dev/vg_thinkpad/lv_home /mnt/home (if created)
mount /dev/nvme0n1p1 /mnt/boot

and enable swap

swapon /dev/nvme0n1p5

Installation

Select the mirrors, placing on top of file the higher priority (should be already ordered by Reflector, use it otherwise): vim /etc/pacman.d/mirrorlist

Install essential packages: pacstrap /mnt base linux linux-firmware lvm2 vim

Configure the system

Fstab: genfstab -U /mnt >> /mnt/etc/fstab Check the resulting /mnt/etc/fstab file, and edit it in case of errors: vim /mnt/etc/fstab

Chroot Change root into the new system arch-chroot /mnt

Time zone Set the time zone: ln -sf /usr/share/zoneinfo/Europe/Rome /etc/localtime Generate /etc/adjtime: hwclock --systohc

Localization Edit /etc/locale.gen and uncomment en_US.UTF-8 UTF-8 and other needed locales vim /etc/locale.gen Generate the locales locale-gen Set the LANG variable in /etc/locale.conf echo 'LANG=en_US.UTF-8' > /etc/locale.conf Set virtual console font echo 'FONT=latarcyrheb-sun32' > /etc/vconsole.conf

or install: pacman -S terminus-font and use echo 'FONT=ter-124n' > /etc/vconsole.conf Set keyboard layout echo 'KEYMAP=it' >> /etc/vconsole.conf

Network configuration echo 'thinkpad-arch' > /etc/hostname vim /etc/hosts

127.0.0.1	localhost
::1			localhost
127.0.1.1	thinkpad-arch

Optional: pacman -S openssh networkmanager to allow network connection and proxy socks on first start. You can also choose systemd-networkd.service instead of networkmanager for a for a lighter footprint.

systemctl enable NetworkManager.service systemd-resolved.service sshd.service

note: if have any issue with dns see systemd/systemd#19118 and remove [!UNAVAIL=return] from /etc/nsswitch.conf

systemctl enable fstrim.timer evaluate to set issue_discards=1 in /etc/lvm/lvm.conf (https://wiki.archlinux.org/title/Solid_state_drive#LVM)

Initramfs vim /etc/mkinitcpio.conf Update HOOKS=(...) with: systemd lvm2 s/udev/systemd/ and insert lvm2 between block and filesystems like so: HOOKS=(base systemd ... block lvm2 filesystems)

recreate the initramfs image: mkinitcpio -P

Set the root password: passwd

Boot loader Setup systemd-boot bootctl install

Set default bootloader entry vim /boot/loader/loader.conf

default arch.conf 
timeout 3 
console-mode max 
editor  no

Enable AMD microcode updates: pacman -S amd-ucode

Create bootloader entry vim /boot/loader/entries/arch.conf

title   Arch Linux
linux   /vmlinuz-linux
initrd  /amd-ucode.img
initrd  /initramfs-linux.img
options root=/dev/vg_thinkpad/lv_root rw

exit or Ctrl+d

note: to enable globally systemd-resolved see https://wiki.archlinux.org/index.php/Systemd-resolved#DNS (ie. ln -sf /run/systemd/resolve/stub-resolv.conf /mnt/etc/resolv.conf when exited from chroot!)

umount -R /mnt (allows noticing any "busy" partitions) reboot

Personalize your distribution

re-enable proxy socks if you need

pacman -Syu

pacman -S zsh zsh-completions grml-zsh-config

Set default shell for root chsh -s /usr/bin/zsh

touch $HOME/.zshrc

vim /etc/zsh/zshenv

typeset -U PATH path
path=("$HOME/.local/bin" /other/things/in/path "$path[@]")
export PATH

Display battery charge in the top right corner echo 'GRML_DISPLAY_BATTERY=1' >> $HOME/.zshrc.pre

more info: https://grml.org/zsh/

User and Privilege elevation pacman -S sudo useradd -m -g users -G wheel -s /usr/bin/zsh <username>

Set password passwd <username> Enable wheel group as sudoers EDITOR=/usr/bin/vim visudo Uncomment %wheel ALL=(ALL) ALL Disable root user passwd -l root vim /etc/passwd root:x:0:0::/root:/usr/bin/zsh vim /etc/shadow root:!:18733::::::

exit or Ctrl+d

(re-enable proxy socks if you need, and use sudo -E pacman)

pacman -S man-db man-pages

https://wiki.archlinux.org/index.php/Mirrors#Ranking_an_existing_mirror_list

sudo pacman -S pacman-contrib
# if you want the vanilla/updated mirrorlist
curl -o /etc/pacman.d/mirrorlist https://archlinux.org/mirrorlist/all/
cd /etc/pacman.d/
mv mirrorlist mirrorlist.bak
# filter by country
awk '/^## Worldwide$/{f=1; next}f==0{next}/^$/{exit}{print substr($0, 1);}' mirrorlist.bak >> mirrorlist-selected
awk '/^## Italy$/{f=1; next}f==0{next}/^$/{exit}{print substr($0, 1);}' mirrorlist.bak >> mirrorlist-selected
awk '/^## Austria$/{f=1; next}f==0{next}/^$/{exit}{print substr($0, 1);}' mirrorlist.bak >> mirrorlist-selected
awk '/^## Germany$/{f=1; next}f==0{next}/^$/{exit}{print substr($0, 1);}' mirrorlist.bak >> mirrorlist-selected
# uncomment
sed -i 's/^#Server/Server/' mirrorlist-selected
rankmirrors -n 6 mirrorlist-selected > mirrorlist

AUR Helper (paru) pacman -S --needed base-devel git

https://wiki.archlinux.org/index.php/Makepkg#Building_optimized_binaries

git clone https://aur.archlinux.org/paru.git
cd paru
makepkg -si

AMDGPU

pacman -S mesa xf86-video-amdgpu vulkan-radeon mesa-vdpau libva-mesa-driver

for 32 bit application support enable multilib (https://wiki.archlinux.org/title/Official_repositories#multilib) and also install lib32-mesa lib32-vulkan-radeon lib32-libva-mesa-driver lib32-mesa-vdpau

Check failed services systemctl --failed if get the above failed service, mask it: systemctl mask systemd-backlight@backlight:acpi_video0.service

To Solve some dmesg fail(ed) msg (eg. "amdgpu: Unsupported power profile mode 0 on RENOIR") vim /etc/mkinitcpio.conf add amdgpu to modules: MODULES=(amdgpu) mkinitcpio -P notes: I'm not sure it really solve the issue, but the error doesn't throw on TTY login screen...maybe only put ahead the module load (https://gitlab.freedesktop.org/drm/amd/-/issues/1488)

pacman -S xorg-server xorg-xrandr
pacman -S plasma-meta kde-applications-meta
sudo systemctl enable sddm.service
sudo systemctl enable bluetooth.service

Discard pacman unused packages weekly

systemctl enable --now paccache.timer

Pacman hook to upgrade systemd-boot after systemd upgrade paru -S systemd-boot-pacman-hook

zsh shell plugin manager (https://getantibody.github.io/) paru -S antibody vim ~/.zsh_plugins.txt

zsh-users/zsh-autosuggestions
zsh-users/zsh-syntax-highlighting
Tarrasch/zsh-autoenv

antibody bundle < ~/.zsh_plugins.txt > ~/.zsh_plugins.sh vim ~/.zshrc source ~/.zsh_plugins.sh

Platform Profiles(https://wiki.archlinux.org/title/Lenovo_ThinkPad_T14_(AMD)_Gen_1#Platform_Profiles) pacman -S acpi_call add to /etc/zsh/zshenv or ~/.zshrc

_thinkpad-profile-base() {
        echo "\_SB.PCI0.LPC0.EC0.HKEY.DYTC $1" | sudo tee /proc/acpi/call
}

alias thinkpad-profile-low='_thinkpad-profile-base 0x12d001'
alias thinkpad-profile-balanced='_thinkpad-profile-base 0x15d001'
alias thinkpad-profile-performance='_thinkpad-profile-base 0x17d001'
# spell checker and dictionary for kde, libreoffice, etc...
pacman -S hunspell hunspell-it hunspell-en_us
pacman -S libreoffice-fresh 
paru -S google-chrome
pacman -S firefox-developer-edition
# install java runtime enviroment openjdk (add "jre" for orcle bundle)
paru -S jre8-openjdk jre-openjdk
# kde/kwin tiling window managers (https://github.com/Bismuth-Forge/bismuth)
paru -S kwin-bismuth-bin
# clipboard manager (add Command: 'Ignore *"Password"* window' adding KeeWeb)
pacman -S copyq
# install syncthing 
pacman -S syncthing
systemctl enable --now syncthing@muttley.service
# adding one remote device and use "sharing/introducer"
# install extra fonts (emoji, chinese/japan/korean, extra)
# ttf-liberation and noto-fonts should be already installed
pacman -S noto-fonts-emoji noto-fonts-cjk noto-fonts-extra
# printer setup (use https://www.openprinting.org/ to find ppd)
pacman -S cups cups-pdf
# keeps your system fully functional after a kernel upgrade (eg. modprobe: FATAL: Module smth not found in directory /lib/modules/new-kernel)
pacman -S kernel-modules-hook
# desktop password manager compatible with KeePass databases
paru -S keeweb (TODO)
# ls with steroid (https://github.com/Canop/broot)
pacman -S broot
# grep with steroid, interactive filter for command-line (https://github.com/junegunn/fzf, https://wiki.archlinux.org/title/fzf)
pacman -S fzf
# generate and copy ssh key
ssh-keygen -t ed25519
ssh-copy-id -i ~/.ssh/id_ed25519.pub username@remote-server.org
# plasmoid gmail checker (stop working?!)
paru -S kdeplasma-applets-gmailfeed
# advanced multitouch events like swipe and pinch gestures (edit /etc/libinput-gestures.conf)
paru -S libinput-gestures wmctrl xdotool
gpasswd -a $USER input
libinput-gestures-setup autostart
# mixing
paru -S usbutils wget

TODO/INSPIRATION:

ntfs-3g dosfstools exfat-utils nfs-utils nvme-cli sshfs smartmontools fwupd calibre clion clion-cmake clion-jre cura filezilla krename masterpdfeditor-free mplayer vlc mysql-workbench platformio spotify-adblock syncthingtray tor-browser typora virtualbox virtualbox-ext-oracle virtualbox-guest-iso visual-studio-code-bin wine rclone python-pip (install by pacman/paru or at lest with "pip install --user") python-pipx (package in the archiso installer, for inspiration: https://gitlab.archlinux.org/archlinux/archiso/-/blob/master/configs/releng/packages.x86_64)

cat chrome-flags.conf  
--enable-features=WebUIDarkMode 
--force-dark-mode

https://wiki.archlinux.org/title/Lenovo_ThinkPad_T14_(AMD)_Gen_1#Fingerprint_sensor https://wiki.archlinux.org/index.php/Synchronization_and_backup_programs https://wiki.archlinux.org/index.php/Vim https://wiki.archlinux.org/index.php/Official_repositories#multilib https://wiki.archlinux.org/index.php/Systemd-resolved#DNS https://wiki.archlinux.org/index.php/Laptop https://wiki.archlinux.org/title/Power_management https://wiki.archlinux.org/index.php/Fwupd https://wiki.archlinux.org/index.php/Libinput#libinput-gestures https://forums.lenovo.com/t5/Other-Linux-Discussions/T14-T14s-X13-P14s-AMD-based-various-issues/m-p/5076798

ANY FEEDBACK OR SUGGESTIONS ARE WELCOME !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment