1
0
src/homepage/knowledge/linux.html

395 lines
19 KiB
HTML

<!DOCTYPE html>
<HTML LANG="en">
<HEAD>
<LINK HREF="http://www.trinity.moe/knowledge/alpine" REL="canonical" />
<LINK HREF="https://raw.githubusercontent.com/devenblake/homepage/main/favicon.ico" REL="shortcut icon" TYPE="image/x-icon" />
<LINK HREF="/css/blank.css" ID="styling" REL="stylesheet" />
<META CHARSET="UTF-8" />
<META CONTENT="noindex" NAME="googlebot" /> <!-- FUCK GOOGLE -->
<META CONTENT="interest-cohort=()" HTTP-EQUIV="Permissions-Policy" /> <!-- FUCK GOOGLE -->
<META NAME="viewport" CONTENT="width=device-width, initial-scale=1" />
<TITLE>knowledge/linux</TITLE>
</HEAD>
<BODY>
<P><A HREF="/">~ Return to the rest of the site</A></P>
<SCRIPT SRC="/js/cookies.js" TYPE="application/javascript"></SCRIPT>
<SCRIPT SRC="/js/sheets.js" TYPE="application/javascript"></SCRIPT>
<SCRIPT TYPE="application/javascript">window.onload = window.initializesheets;</SCRIPT>
<H1>linux</H1>
<H3>updated 2022-05-17</H3>
<HR ALIGN="left" SIZE="1" WIDTH="25%" />
<H2>ACPI client</H2>
<P>
An ACPI client is a program that displays computer ACPI information, typically power and thermal statuses.
The usual text program used is <CODE>acpi(1)</CODE>.
</P>
<H2>Alpine</H2>
<UL>
<LI><A HREF="https://pkgs.alpinelinux.org/contents">Alpine repositories content search</A></LI>
</UL>
<H3>Always install manual pages</H3>
<P>
Alpine doesn't include man pages in program packages to save on space, instead keeping them in <CODE>[<I>package</I>]-doc</CODE> sibling packages.
To always install doc packages with program packages, <CODE>apk add docs</CODE>.
</P>
<H2>Arch and Artix</H2>
<H3>Bootstrapping: Installing essential packages</H3>
<P>
On Artix, use <CODE>basestrap(8)</CODE>.
On Arch, use <CODE>pacstrap(8)</CODE>.
</P>
<P>
At a minimum you need <CODE>base</CODE> on both Arch and Artix.
On Artix, you need to select the initialization you want to use: <CODE>66</CODE>, <CODE>dinit</CODE>, <CODE>openrc</CODE>, <CODE>runit</CODE>, or <CODE>s6-base</CODE>.
On both Arch and Artix, select a kernel; <CODE>linux</CODE>, <CODE>linux-lts</CODE>, or another Linux configuration or fork.
Arch says you need to install <CODE>linux-firmware</CODE>, technically you don't need to do so but you should.
Artix says you need to install the appropriate elogind package (<CODE>elogind-$(<B>INIT_SYSTEM</B>)</CODE>; e.g. <CODE>elogind-66</CODE>).
This isn't necessary if you aren't using elogind, but you <I>most likely</I> want elogind.
Install <CODE>base-devel</CODE> if you plan on using the AUR or if you don't know what the AUR is yet.
</P>
<P>
It's also a good idea to install any utilities you'll need on the bootstrapped system.
Text editors, network managers or utilities, and other administration tools, for example.
Manual utilities such as <CODE>man-db</CODE> and others would also be useful.
</P>
<H3>Ubiquitous packages missing</H3>
<P>From the anals of my notes, 2021-06-04:</P>
<PRE>
Had an issue with pacman missing some ubiquitous packages (esr's `ascii`, xorg-xev, etc).
This fixed it. I don't really know why - maybe some issues with my repos?
This was cleanly installed artix-openrc.
[5:46 PM] Bassman Leyla: So what I did is I went into /etc/pacman.d/mirrorlist-arch and uncommented a local mirror
[5:46 PM] Bassman Leyla: Then I appended a config block a package maintainer gave me onto /etc/pacman.conf
[5:46 PM] Bassman Leyla: I'll paste it in
[5:47 PM] Bassman Leyla:
```
#
# ARCHLINUX
#
#[testing]
#Include = /etc/pacman.d/mirrorlist-arch
[extra]
Include = /etc/pacman.d/mirrorlist-arch
#[community-testing]
#Include = /etc/pacman.d/mirrorlist-arch
[community]
Include = /etc/pacman.d/mirrorlist-arch
#[multilib-testing]
#Include = /etc/pacman.d/mirrorlist-arch
#[multilib]
#Include = /etc/pacman.d/mirrorlist-arch
```
</PRE>
<H2>C Language</H2>
<P>
For compilation, <CODE>tcc(1)</CODE>, <CODE>gcc(1)</CODE>, and <CODE>clang(1)</CODE> are all reasonable choices depending on your needs.
</P>
<P>
On Alpine Linux, the standard library headers are in the <CODE>musl-dev</CODE> package.
</P>
<P>
In most system package managers, standard library documentation can be found in the <CODE>man-pages</CODE> and <CODE>man-pages-posix</CODE> packages.
</P>
<P>
Many Linux software distributions' system package managers have meta-packages that pull all necessities for C development as dependencies.
Alpine has <CODE>build-base</CODE> and Debian has <CODE>build-essential</CODE>.
</P>
<H2>Debian</H2>
<P>
Debian is a Linux software distribution known for its stability and longevity.
Debian uses SystemD as its initialization system, the GNU core utilities, and dpkg and apt for package management.
</P>
<H2 ID="fonts">Fonts</H2>
<H2 ID="fstab">fstab</H2>
<P>See <CODE>fstab(5).</CODE></P>
<P>postmarketOS requires that the <CODE>localmount</CODE> OpenRC service be enabled for the system to read <CODE>fstab(5)</CODE>.
<P>Arch and Artix have fstab generators at <CODE>genfstab(8)</CODE> and <CODE>fstabgen(8)</CODE> respectively in their installation scripts.</P>
<H2 ID="login_manager">Login manager</H2>
<P>Use <CODE>elogind</CODE>.</P>
<H2>Make utility</H2>
<P>
<CODE>make(1)</CODE> in modern times is fragmented into the GNU version (in context, <I><CODE>gmake</CODE></I>) and the {Free,Open,Net}BSD version (<I><CODE>bmake</CODE></I>).
Complex Makefiles may not be useable in both.
It's custom for Linux systems to have <CODE>make(1)</CODE> as GNU Make and <CODE>bmake(1)</CODE> as BSD Make, and BSD-based systems to have <CODE>make(1)</CODE> as BSD Make and <CODE>gmake(1)</CODE> as GNU Make.
</P>
<H2>On-line manual</H2>
<P>
In the context of POSIX and UNIX-like systems, an "on-line" manual is a manual that is accessible via the computer system it documents.
Particularly, the <CODE>man(1)</CODE> utility and the manual "pages" it references.
</P>
<P>
Alpine by default uses <CODE>mandoc</CODE>.
</P>
<H2>Paging</H2>
<P>
<CODE>less(1)</CODE> is <CODE>more(1)</CODE>; more or less.
</P>
<H2 ID="partitioning">Partitions and filesystems</H2>
<UL>
<LI><A HREF="https://wiki.archlinux.org/title/EFI_system_partition">EFI system partition (Arch Wiki)</A></LI>
<LI><A HREF="https://wiki.artixlinux.org/Main/Installation#Partition_your_disk_.28BIOS.29">Installation#Partition your disk - Artix wiki</A></LI>
<LI><A HREF="https://wiki.archlinux.org/title/Installation_guide#Partition_the_disks">Installation guide#Partition the disks - Arch wiki</A></LI>
</UL>
<P>
Don't use partitioners included with OS media where the same job can be done by <A HREF="https://gparted.org/">GParted</A> (which has live media available) or another good general-purpose partitioner.
BSDs and Plan 9 are exceptions to this rule due to their exotic partitioning systems.
Using utilities from a shell or TUIs does not make you "cooler" than someone who needs a GUI for partitioning; in some cases, messing up partitioning can have serious consequences, so it's always nice to have some idiot-proofing.
I always partition my disks with the GParted live media.
</P>
<P>
You should do your own research on how you should partition your disks.
I personally use separate partitions for /boot, /home, /, and swap.
Your needs will vary.
</P>
<P>
<B>Please note that a separate boot partition is mandatory if you intend to boot via (U)EFI.</B>
Check out the linked pages in the "See also" section.
</P>
<P>
Use <CODE>mkfs(8)</CODE> for creating filesystems and <CODE>mount(8)</CODE> for mounting partitions' filesystems.
</P>
<H3 ID="luks">LUKS</H3>
<UL>
<LI><A HREF="https://www.howtoforge.com/automatically-unlock-luks-encrypted-drives-with-a-keyfile/">Automatically Unlock LUKS Encrypted Drives With A Keyfile</A></LI>
<LI><A HREF="https://wiki.gentoo.org/wiki/Dm-crypt">Dm-crypt</A> (Gentoo Wiki)</LI>
<LI><A HREF="https://www.cyberciti.biz/security/how-to-backup-and-restore-luks-header-on-linux/">How to backup and restore LUKS header on Linux</A></LI>
<LI><A HREF="https://devconnected.com/how-to-encrypt-partition-on-linux/">How To Encrypt Partition on Linux</A></LI>
<LI><A HREF="https://unixfuntime.wordpress.com/2012/08/20/luks-passphrases-changing-adding-removing/">LUKS passphrases: Changing, adding, removing</A></LI>
<LI><A HREF="https://wiki.alpinelinux.org/wiki/LVM_on_LUKS">LVM on LUKS</A> (Alpine Wiki)</LI>
</UL>
<P>
<CODE>e2fsprogs</CODE> is needed for the <CODE>dm_mod</CODE> kernel module used for LUKS partition decryption.
</P>
<P>
To format a partition to a LUKS volume, determine the physical block device location for that partition and run <CODE>cryptsetup luksFormat [<I>partition</I>]</CODE>.
The passphrase used can be changed or removed after creation.
</P>
<P>
To open a LUKS volume, use <CODE>cryptsetup luksOpen [<I>partition</I>] [<I>name</I>]</CODE>.
This <I>name</I> is the name the <I>decrypted block device</I> location will take in <CODE>/dev/mapper/</CODE>.
</P>
<P>
Before the decrypted block device has a filesystem it'll just be cleared space - format as normal but use the decrypted block device location.
</P>
<P>
To mount a partition in an opened LUKS volume, use <CODE>mount(8)</CODE> as normal, just with the decrypted block device location.
</P>
<P>
To close an open LUKS volume, <CODE>umount(8)</CODE> any mapped and mounted partitions from the volume and <CODE>cryptsetup luksClose [<I>name</I>]</CODE>.
</P>
<P>
To make the LUKS partition openable via keyfile, first make a keyfile (<CODE>dd if=/dev/urandom of=/root/keyfile bs=1024 count=4</CODE> seems to work), and optionally make it readable by root only (<CODE>chmod 0400 [<I>keyfile</I>]</CODE>).
Then add the keyfile to the partition's LUKS header with <CODE>cryptsetup luksAddKey [<I>physical partition block device</I>] [<I>keyfile</I>]</CODE>.
</P>
<H4>dm-crypt</H4>
<P>
<CODE>dm-crypt</CODE> is a service that automatically mounts LUKS volumes at boot.
</P>
<P>
On most OpenRC-initialized distributions, the <CODE>cryptsetup-openrc</CODE> package provides <CODE>dmcrypt</CODE>.
Make sure that service is added to runlevel boot.
</P>
<P>
Configuration is in <CODE>/etc/conf.d/dmcrypt</CODE> and further configuration should be done in <CODE><A HREF="#fstab">fstab</A></CODE>.
<CODE>dm-crypt</CODE> will need the UUID of the <I>physical</I> block device while fstab (if being configured with UUIDs will need the UUID of the decrypted block device in the device mapper.
</P>
<H2>postmarketOS</H2>
<P>
postmarketOS is an Alpine-based Linux software distribution that makes configuring and using Linux easy on mobile devices.
It uses OpenRC for initialization, busybox for core utilities, and can come with any of multiple windowing systems and window managers.
</P>
<H3>Random MAC address generation on Wifi</H3>
<P>
By default, postmarketOS will generate a random software MAC address when connecting to a new WLAN network.
You can disable this by adding a NetworkManager rule.
In <CODE>/etc/NetworkManager/conf.d/</CODE> you can make a file with any name that has the following:
</P>
<PRE><CODE>
[device]
wifi.scan-rand-mac-address=no
</CODE></PRE>
<P>
On a live system you can then <CODE>rc-service networkmanager restart</CODE> to restart NetworkManager and have it load the new configuration.
</P>
<H2 ID="power">Power</H2>
<P>Much of this can be configured in the ACPI settings in your <A HREF="#login_manager">login manager</A>, provided you have one running that can do this.</P>
<P>Check out <CODE>tlp</CODE> for Thinkpads and some other Lenovo devices.</P>
<H2>SSH keys</H2>
<UL>
<LI><A HREF="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account">Adding a new SSH key to your GitHub account</A> (GitHub Docs)</LI>
<LI><A HREF="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/checking-for-existing-ssh-keys">Checking for existing SSH keys</A> (GitHub Docs)</LI>
<LI><A HREF="Generating a new SSH key and adding it to the ssh-agent">Generating a new SSH key and adding it to the ssh-agent</A> (GitHub Docs)</LI>
</UL>
<P>SSH keys are typically stored in <CODE>$HOME/.ssh</CODE>.</P>
<P>Typically, the public key's filename will be suffixed with <CODE>.pub</CODE>, while the private key will not.</P>
<P>You can generate an SSH key with <CODE>ssh-keygen(1)</CODE>. Currently the preferred implementation is <CODE>openssh-keygen</CODE>, part of the OpenSSH suite.</P>
<P>
Microsoft GitHub documentation suggests a user create a key with <CODE>ssh-keygen -t ed25519 -C "[<I>e-mail address</I>]"</CODE>.
This generates an <A HREF="https://en.wikipedia.org/wiki/EdDSA#Ed25519">Ed25519</A> SSH key with an e-mail address in the key comment.
</P>
<H2>Task management</H2>
<P><CODE>top(1)</CODE> comes with busybox, otherwise use <CODE>htop</CODE>.</P>
<H2 ID="text_editing">Text editing</H2>
<P>
<CODE>nano(1)</CODE> is a text editor that's usually recommended for beginners because its controls are more intuitive.
<CODE>ne(1)</CODE> is like <CODE>nano(1)</CODE> but with different superpowers. Not yet in pkgsrc.
</P>
<H3>ed</H3>
<P>
A particularly shoddy attempt at <CODE>ed(1)</CODE> is provided by <CODE>busybox</CODE>.
A traditional <CODE>ed(1)</CODE> implementation is in plan9ports.
I'm pretty sure some later UNIX-based OSes doubled the <CODE>ed(1)</CODE> buffers, there's pretty much no downside to doing so in the modern era but it should be very easy to do yourself if it hasn't already been done (just double some of the array sizes in the beginning of <CODE>ed.c</CODE>).
</P>
<H3>vi</H3>
<P>
Unlike <CODE>busybox</CODE>'s <CODE>ed(1)</CODE> implementation, its <CODE>vi(1)</CODE> is very useable.
<CODE>vim(1)</CODE> is a popular re-implementation of <CODE>vi(1)</CODE>.
</P>
<H3>emacs</H3>
<P>
Emacs ("editor macros") is a text editor with a very powerful Lisp interpreter included.
Lisp is mostly antiquated due to its undeserved lack of popularity.
Linus Torvalds uses his own fork of uEmacs ("micro Emacs"), an Emacs without the Lisp interpreter(?).
</P>
<H3>cat</H3>
<P>
Technically <CODE>cat(1)</CODE> and other UNIX utilities can be used in a hacky way for text editing functions.
You'd be better off using <CODE>ed(1)</CODE>; the UX is very similar.
</P>
<H2>util-linux</H2>
<UL>
<LI><A HREF="https://en.wikipedia.org/wiki/Util-linux">util-linux - Wikipedia</A></LI>
</UL>
<P>
<CODE>util-linux</CODE> is distributed on all popular Linux distributions and contains utilities users may expect to be already present on their systems, like <CODE>more(1)</CODE> or <CODE>hexdump(1)</CODE>.
</P>
<H2>WiFi</H2>
<P>
I use <CODE>iwd(8)</CODE> and <CODE>iwctl(8)</CODE>.
Some prefer NetworkManager and I believe that's the default on Debian.
The Artix wiki suggests connman.
</P>
<H3>wpa_supplicant</H3>
<P>
<CODE>wpa_supplicant(1)</CODE> is often used by insane people without any helper scripts.
I haven't had good luck with it but Alpine set it up automatically.
</P>
<H2>X</H2>
<UL>
<LI><A HREF="https://wiki.archlinux.org/title/Xorg">Xorg</A> (Arch Wiki)</LI>
</UL>
<P>
X is a graphical windowing system that can be used on Linux, FreeBSD, OpenBSD, NetBSD, and some proprietary operating systems as well.
X is not the only windowing system; <CODE>twin(1)</CODE> exists for windowed multitasking within a framebuffer and Wayland is another windowing system intended to replace X.
</P>
<P>
Xorg requires the user to be a member of the <CODE>input</CODE> and <CODE>video</CODE> groups (or superuser), otherwise it won't be able to access the relevent device files.
These errors look like <CODE>Failed to open /dev/input/event[<I>number</I>] (Permission denied)</CODE> when not in the <CODE>input</CODE> group
and <CODE>Failed to open /dev/tty[<I>number</I>] (Permission denied)</CODE> when not in the <CODE>video</CODE> group.
</P>
<P>
Some Linux software distributions have included scripts to automatically fetch and install an X server.
Alpine has <CODE>setup-xorg-base</CODE>, which adds the packages <CODE>xorg-server</CODE>, <CODE>xf86-input-libinput</CODE>, <CODE>eudev</CODE>, and <CODE>mesa</CODE>, and then enables the OpenRC services for udev.
</P>
<P>
<CODE>startx(1)</CODE> is provided as part of xinit.
</P>
<P>
Arch has the <CODE><A HREF="https://archlinux.org/groups/x86_64/xorg/">xorg</A></CODE> and <CODE><A HREF="https://archlinux.org/groups/x86_64/xorg-apps/">xorg-apps</A></CODE> package groups.
Documentation can be found within <CODE>xorg-docs</CODE>,
drivers within the <CODE><A HREF="https://archlinux.org/groups/x86_64/xorg-drivers/">xorg-drivers</A></CODE> package group,
the server itself as <CODE>xorg-server</CODE>,
the X event monitor as <CODE>xorg-xev</CODE>,
xinit as <CODE>xorg-xinit</CODE>,
xinput as <CODE>xorg-xinput</CODE>,
XRandR as <CODE>xorg-xrandr</CODE>,
the X resource database manager as <CODE>xorg-xrdb</CODE>,
xset as <CODE>xorg-xset</CODE>,
and xsetroot as <CODE>xorg-xsetroot</CODE>.
</P>
<P>Alpine has xinput as <CODE>xinput</CODE>.</P>
<H3>Audio</H3>
<P>
Most audio servers recommend that they be run in userspace with user privileges, with PulseAudio going so far as to exiting when run as root without additional configuration.
The Alpine wiki currently recommends <CODE>pipewire(1)</CODE>, with postmarketOS, which is based on Alpine, coming pre-configured with PipeWire.
PipeWire is relatively new and the typical audio server used is PulseAudio; Debian and many popular Debian-based distributions come pre-configured with PulseAudio.
</P>
<H4>ALSA</H4>
<UL>
<LI><A HREF="https://wiki.alpinelinux.org/wiki/Main_Page/Adding_sound">Adding sound</A> (Alpine Linux Wiki)</LI>
</UL>
<P>
The Alpine wiki ("Adding sound") says to install <CODE>alsa-conf</CODE>, <CODE>alsa-lib</CODE>, and <CODE>alsa-utils</CODE>,
add yourself to the <CODE>audio</CODE> group, and then do some more configuration that I've never needed to do:
Use <CODE>alsamixer(1)</CODE> to find a working sound card (press <CODE>F6</CODE> from the first screen ALSAMixer presents)
and edit <CODE>/usr/share/alsa/alsa.conf</CODE> and change <CODE>defaults.ctl.card</CODE> and <CODE>defaults.pcm.card</CODE> to the sound card that works.
</P>
<P>
The Alpine wiki doesn't mention this but you'll need to enable the <CODE>alsa</CODE> OpenRC service and either start it or reboot.
I also installed <CODE>gstreamer</CODE> but I don't know why.
</P>
<P>
ALSA is clunky, many people prefer to use a frontend such as Pipewire or PulseAudio that exposes its own interface while remaining compatible with ALSA.
</P>
<H4>OSS</H4>
<P>
Deprecated, unfortunately.
</P>
<H4>PipeWire</H4>
<UL>
<LI><A HREF="https://wiki.alpinelinux.org/wiki/PipeWire">PipeWire</A> (Alpine Linux Wiki)</LI>
<LI><A HREF="https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/home">PipeWire</A> (FreeDesktop Wiki)</LI>
</UL>
<P>
Provided by the <CODE>pipewire</CODE> package on Alpine.
</P>
<PRE>
RTKit error: org.freedesktop.DBus.Error.ServiceUnknown
</PRE>
<P>
This means you need <CODE>rtkit</CODE> installed and running through your initialization system.
</P>
<H4>PulseAudio</H4>
<P>
On Alpine you'll need the <CODE>pulseaudio</CODE>, <CODE>pulseaudio-alsa</CODE>, and <CODE>alsa-plugins-pulse</CODE> packages for PulseAudio with ALSA compatibility.
Start <CODE>pulseaudio(1)</CODE> when you want audio, ideally in your <CODE>.xinitrc</CODE>.
</P>
<H3>Media</H3>
<P>
<CODE>mpv(1)</CODE> and <CODE>vlc(1)</CODE> are good options.
</P>
</BODY>
</HTML>
</BODY>
</HTML>