( linux )


Contents

  1. Arch Linux
  2. Debian
  3. Raspberry Pi

Sun, Mar 03, 2024

ARCH LINUX

Keyboard

$ loadkeys us

Partition

# List block devices
$ lsblk

# To partition /dev/nvme0n1
$ gdisk /dev/nvme0n1

# Either new or start over
$ o

# Accept
$ y

# Create new partition
$ n

# Accept default partition number
$ Enter

# Accept default first sector
$ Enter

# Allocated 512MB for boot partition
$ +512M

# Set type of partition or L to list
$ EF00

# Create new partition
$ n

# Accept default partition number
$ Enter

# Accept default first sector
$ Enter

# Accept default last sector
$ Enter

# Set partition type to LVM
$ 8300

# Write change
$ w

# Accept
$ y

# Create encrypted container
$ cryptsetup luksFormat --type luks2 /dev/nvme0n1p2

# Open container
$ cryptsetup open /dev/nvme0n1p2 cryptolvm

# Create physical volume
$ pvcreate /dev/mapper/cryptolvm

# Create MyVol volume group
$ vgcreate MyVol /dev/mapper/cryptolvm

# Allocated 2GB for swap
$ lvcreate -L 2G MyVol -n swap

# Allocated remaining for root
$ lvcreate -l 100%FREE MyVol -n root

# Format swap
$ mkswap /dev/mapper/MyVol-swap

# Format root
$ mkfs.ext4 /dev/mapper/MyVol-root

# Mount swap
$ swapon /dev/mapper/MyVol-swap

# Mount root
$ mount /dev/mapper/MyVol-root /mnt

# Format boot
$ mkfs.vfat -F32 /dev/nvme0n1p1

# Create boot directory
$ mkdir	/mnt/boot

# Mount boot
$ mount /dev/nvme0n1p1 /mnt/boot

Dual Boot Option

# Mac's EFI partition; shared with Linux
sda1 EFI /boot
sad2 Mac

# Left blank
sda3 EFI
sda4 LUKS
|-MyVol
  |- MyVol-swap [SWAP]
  |- MyVol-root /

Wireless

Use Ethernet or with Ethernet, install netctl

$ pacman -S netctl
$ wifi-menu

Install Base System

$ pacstrap /mnt base base-devel

Edit /etc/pacman.d/mirrorlist so that the preferred mirror is on top of the list

$ pacstrap /mnt base base-devel linux linux-firmware mkinitcpio lvm2 netctl dhcpcd

Configure System

# Generate fstab
$ genfstab -pU /mnt >> /mnt/etc/fstab

Edit /mnt/etc/fstab; change relatime to noatime for non-boot partitions

# chroot
$ arch-chroot /mnt

Add hostname to /etc/hostname and /etc/hosts

127.0.0.1	localhost
127.0.0.1	hostname.subdomain.domain	hostname

Set time zone

$ ln -s /usr/share/zoneinfo/Pacific/Auckland /etc/localtime

Uncomment locale in /etc/locale.gen

$ locale-gen

Set locale preference by adding LANG=”en_NZ.UTF-8” to /etc/locale.conf

Configure mkinitcpio

Add ext4 to MODULES and encrypt lvm2 resume hooks to /etc/mkinitcpio.conf before filesystems and after udev

HOOKS=(base udev autodetect modconf block encrypt lvm2 resume filesystems keyboard fsck)

mkinitcpio and set root password

$ mkinitcpio -p linux
$ passwd

Install Boot Loader

$ bootctl --path=/boot install

Edit /boot/loader/loader.conf

default lts.conf
timeout 5
editor 0

Use blkid to find the UUID for /dev/nvme0n1p2 and replace the <UUID> below without the bracket

Edit /boot/loader/entries/arch.conf

title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options cryptdevice=UUID=<UUID>:MyVol root=/dev/mapper/MyVol-root resume=/dev/mapper/MyVol-swap rw

Edit /boot/loader/entries/lts.conf

title LTS
linux /vmlinuz-linux-lts
initrd /initramfs-linux-lts.img
options cryptdevice=UUID=<UUID>:MyVol root=/dev/mapper/MyVol-root resume=/dev/mapper/MyVol-swap rw

Wireless

$ pacman -S dialog wpa_supplicant

Umount and Reboot

# Exit from chroot environment
$ exit

$ umount -R /mnt
$ reboot

Create New User

Creates a new user with home directory, change password and add user to additional groups

$ useradd -m -G wheel -s /bin/bash daniel
$ passwd daniel
$ usermod -a -G audio,network,power,scanner,storage,systemd-journal,video daniel

Wireless

$ wifi-menu

# Find the wifi profile
$ ls /etc/netctl/

# profile-name as obtained above
$ netctl enable profile-name

A better approach is as follows rather than enabling profile

# Wired
$ sudo pacman -S ifplugd

# substitute interface with the value obtained from ip a
$ sudo systemctl enable netctl-ifplugd@interface.service

# substitute interface with the value obtained from ip a
$ sudo systemctl enable netctl-auto@interface.service

Sudo

$ pacman -S sudo

Run visudo, edit it to restrict sudo to specific group or user

Additional Install / Extra Configuration

Yay

Install yay from AUR

Download

Extract; run makepkg -s followed by pacman -U against the generated pkg.tar.xz package to install it

Audio

$ sudo pacman -S alsa-utils

# ALSA comes muted by default
$ amixer sset Master unmute

Create /etc/modprobe.d/disablePower.conf

options snd_hda_intel power_save=0

Mesa

Edit /etc/enviroment

MESA_LOADER_DRIVER_OVERRIDE=i965

Restore

Restore home from GFS backup; SYS backup is available for configuration reference if needed but do not restore straight from it since that will wipe newer configurations for fresh build

# Install all packages from backup list
$ sudo pacman -S - < pkglist.txt

Do the same for AUR packages with yay

Bluetooth

Edit /etc/bluetooth/main.conf and add the following line

AutoEnable=true
$ sudo systemctl enable bluetooth.service

Enable bluetooth service then pair devices

CUPS

Install, enable and start CUPS

$ sudo pacman -S cups
$ sudo systemctl enable org.cups.cupsd.service
$ sudo systemctl start org.cups.cupsd.service

Run sudo usermod -a -G lp daniel to add to lp group Run sudo usermod -a -G cups daniel to add to cups group

Append wheel to SystemGroup sys root in /etc/cups/cups-files.conf

At this point, re-logon for the permission to be effective

$ yay -S brother-mfc-l2713dw
$ yay -S brscan4

Install printer and scanner drivers

Browse to http://localhost:631, go to Administration -> Add Printer Select LPD/LPR Host or Printer Enter lpd://(Your printer’s IP address)/binary_p1 Select Brother Select the CUPS printer driver version (if not already automatically selected) Name the printer

Then go to Printers Select the printer Drop down Administration Select Set Default Options Set to the following A4 Plain Paper 600dpi Tray1 DuplexNoTumble Toner Save to Off

Drop down Administration Select Set As Server Default

For scanning

$ brsaneconfig4 -a name=(name your device) model=(model name) ip=xx.xx.xx.xx

Use gscan2pdf

Untick OCR scanned pages Select All pages Leave Mode as default Change Geometry from Manual to A4

gscan2pdf will need yay -S pdftk-bin

Even though org.cups.cupsd.service has been enabled, it won’t auto start on boot Just do a test print, that will activate the auto start on boot

NTP

$ sudo systemctl enable ntpd.service

Power Management

power-profile-daemon simplifies power management

$ pacman -S thermald power-profiles-daemon upower
$ sudo systemctl enable thermald.service
$ sudo systemctl enable power-profiles-daemon.service
$ sudo systemctl enable upower.service

Nvidia

$ pacman -S nvidia nvidia-lts nvidia-utils nvidia-settings nvidia-prime mesa-utils virtualgl

Use nvidia-smi to check offloading and wattage Use prime-run if need to explicitly use nvidia Some programs will do that automatically such as mpv Otherwise, they default to the integrated GPU For Intel, that’s i915

Slock

Lock on suspend

Create /etc/systemd/system/slock@.service

[Unit]
Description=Lock X session using slock for user %i
Before=sleep.target

[Service]
User=%i
Environment=DISPLAY=:0
ExecStartPre=/usr/bin/xset dpms force suspend
ExecStart=/usr/local/bin/slock

[Install]
WantedBy=sleep.target
$ sudo systemctl enable slock@user.service

Substitute user with value from echo $USER

Macbook Air Mid-2013

It has BCM4360 wireless network adapter

For Arch LInux, install broadcom-wl-dkms and linux-headers Then reboot before trying wifi-menu

For Debian, follow installation instruction for wl

Deprecated

Section kept for reference only

PulseAudio (Replaced by PipeWire)

Edit /etc/pulse/system.pa and add the following lines

load-module module-bluetooth-policy
load-module module-bluetooth-discover

Edit /etc/pulse/default.pa and add the following line

load-module module-switch-on-connect

If cookie not found then cp ~/.pulse-cookie ~/.config/pulse/cookie

iOS

$ usbmuxd -f -v
$ idevice_id -l
$ ideviceinfo
$ ideviceinstaller -l
$ ifuse ~/iPhone
$ umount ~/iPhone

Reference

Broadcom wireless Mid 2013 Suspend WiFi netctl: Enabling a profile netctl: Special systemd units: wired / wireless


DEBIAN

Network Setup

Edit /etc/network/interfaces

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto wlan0
iface wlan0 inet static
# iface wlan0 inet dhcp
# Omit the following 5 lines if using dhcp; or 7 lines if using eno1
        address <address>
        netmask <netmask>
        network <network>
        broadcast <broadcast>
        gateway <gateway>
        wpa-ssid <wpa-ssid>
        wpa-psk <wpa-psk>

To get wpa-psk

$ wpa_passphrase Your-WiFi-Name-SSID <passphrase>


RASPBERRY PI

Backup

# Backup
$ sudo dd bs=4M if=/dev/sde of=raspbian.img
# Or with compression
$ sudo dd bs=4M if=/dev/sde | gzip > rasbian.img.gz

# Restore
$ sudo dd bs=4M if=raspbian.img of=/dev/sde
# Or with compression
$ gunzip --stdout rasbian.img.gz | sudo dd bs=4M of=/dev/sde

Consistency Check

$ lsblk
$ sudo fdisk -l
$ sudo fsck -a /dev/sde2
$ sudo dosfsck -a /dev/sde1