Terminal cheat sheet: Difference between revisions
Undo revision 39746 by Doomfan345 (talk) Tag: Undo |
Add "Rebooting to fastboot" section |
||
(14 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
[[File:postmarketOS_cheatsheet.png|thumb|right|Another postmarketOS cheat sheet with similar content, in poster format.]] | [[File:postmarketOS_cheatsheet.png|thumb|right|Another postmarketOS cheat sheet with similar content, in poster format.]] | ||
Here's a small reference for working with postmarketOS/Alpine Linux. | Here's a small reference for working with postmarketOS/Alpine Linux. | ||
__TOC__ | __TOC__ | ||
== Package management == | == Package management == | ||
The package manager in postmarketOS is called <code>apk</code>, the Alpine Package Keeper. The list of packages can be found at [https://pkgs.alpinelinux.org/packages pkgs.alpinelinux.org] and [https://pkgs.postmarketos.org/packages pkgs.postmarketos.org]. | The package manager in postmarketOS is called <code>apk</code>, the Alpine Package Keeper. The list of packages can be found at [https://pkgs.alpinelinux.org/packages pkgs.alpinelinux.org] and [https://pkgs.postmarketos.org/packages pkgs.postmarketos.org]. | ||
The Alpine Linux wiki has a page '''[https://wiki.alpinelinux.org/wiki/Comparison_with_other_distros comparing apk to other popular package managers]''', with many helpful examples. | |||
< | === Installing a package === | ||
<syntaxhighlight lang="shell-session"> | |||
$ sudo apk add neovim | $ sudo apk add neovim | ||
</ | </syntaxhighlight> | ||
< | === Uninstalling a package === | ||
<syntaxhighlight lang="shell-session"> | |||
$ sudo apk del neovim | $ sudo apk del neovim | ||
</ | </syntaxhighlight> | ||
Upgrading the system | === Upgrading the system === | ||
The <code>-a</code> option allows downgrading packages to what's available in the repository. It is generally recommended to always use this option, especially on stable releases, to ensure that any package reverts make it to your device. | |||
< | <syntaxhighlight lang="shell-session"> | ||
$ sudo apk upgrade -a | $ sudo apk upgrade -a | ||
</ | </syntaxhighlight> | ||
=== Repairing packages === | |||
Run various package repair strategies, e.g. running failed installation scripts again: | Run various package repair strategies, e.g. running failed installation scripts again: | ||
< | <syntaxhighlight lang="shell-session"> | ||
$ sudo apk fix | $ sudo apk fix | ||
$ sudo apk fix name-of-package # will also reinstall name-of-package | $ sudo apk fix name-of-package # will also reinstall name-of-package | ||
</ | </syntaxhighlight> | ||
=== Listing installed packages === | |||
Listing installed package versions (add <code>| grep package-name</code> to filter for a specific package): | Listing installed package versions (add <code>| grep package-name</code> to filter for a specific package): | ||
< | <syntaxhighlight lang="shell-session"> | ||
$ apk info -vv | $ apk info -vv | ||
</ | $ apk info -vv | grep package-name | ||
</syntaxhighlight> | |||
< | === Installing build dependencies === | ||
<syntaxhighlight lang="shell-session"> | |||
$ sudo apk add build-base install-makedepends | $ sudo apk add build-base install-makedepends | ||
$ install-makedepends neovim | $ install-makedepends neovim | ||
</ | </syntaxhighlight> | ||
The repositories are stored in <code>/etc/apk/repositories</code> as one repository url per line. There's also <code>/etc/apk/world</code> which is a list of packages that are explicitly installed. It's possible to add/remove packages from this list and then running <code>apk fix</code> to apply those changes | === Config files === | ||
The repositories are stored in <code>/etc/apk/repositories</code> as one repository url per line. There's also <code>/etc/apk/world</code> which is a list of packages that are explicitly installed. It's possible to add/remove packages from this list and then running <code>apk fix</code> to apply those changes. | |||
New installations of postmarketOS let apk ask for confirmation by default. If you don't want this, delete <code>/etc/apk/interactive</code> ({{MR|3444|pmaports}}). | New installations of postmarketOS let apk ask for confirmation by default. If you don't want this, delete <code>/etc/apk/interactive</code> ({{MR|3444|pmaports}}). | ||
=== Logging with apk === | |||
A feature to log each apk action, especially which packages have been installed with an upgrade [https://gitlab.alpinelinux.org/alpine/apk-tools/-/merge_requests/55 will be available in apk3]. In the meantime, similar functionality can be achieved by installing <code>etckeeper</code>. It turns your <code>/etc</code> directory into a git repository, tracking changes to all files in there, and it also records package changes and related versions in the git log. | |||
<syntaxhighlight lang="shell-session"> | |||
$ sudo apk add etckeeper | |||
$ sudo apk add hello-world | |||
$ sudo git -C /etc log | |||
commit e8dc072cbe037eeaeec3adb8649680b2fcd10130 (HEAD -> master) | |||
Author: root <root@nokia-n900> | |||
Date: Tue Jan 9 15:43:28 2024 +0000 | |||
committing changes in /etc after apk run | |||
Package changes: | |||
+hello-world-1-r6 | |||
</syntaxhighlight> | |||
== Service management == | == Service management == | ||
=== systemd === | |||
systemd is the default service manager for GNOME (Desktop and Mobile), Plasma (Desktop and Mobile) and Phosh. | |||
Basic service management is done with <code>systemctl</code>. | |||
<syntaxhighlight lang="shell-session"> | |||
$ sudo systemctl status NetworkManager | |||
$ sudo systemctl start NetworkManager | |||
$ sudo systemctl stop NetworkManager | |||
$ sudo systemctl restart NetworkManager | |||
</syntaxhighlight> | |||
To enable or disable services on boot: | |||
<syntaxhighlight lang="shell-session"> | |||
$ sudo systemctl enable NetworkManager | |||
$ sudo systemctl disable NetworkManager | |||
</syntaxhighlight> | |||
=== OpenRC === | |||
OpenRC is the default service manager for all other UIs. | |||
The basic service management is done with the familiar <code>rc-service</code> command. | |||
{{note|Tip: <code>rc-service</code> is also symlinked to <code>service</code> which is shorter to type.}} | {{note|Tip: <code>rc-service</code> is also symlinked to <code>service</code> which is shorter to type.}} | ||
< | <syntaxhighlight lang="shell-session"> | ||
$ rc-service networkmanager status | $ rc-service networkmanager status | ||
$ sudo rc-service networkmanager start | $ sudo rc-service networkmanager start | ||
$ sudo rc-service networkmanager stop | $ sudo rc-service networkmanager stop | ||
$ sudo rc-service networkmanager restart | $ sudo rc-service networkmanager restart | ||
</ | </syntaxhighlight> | ||
To enable or disable services on boot you use the <code>rc-update</code> command. | To enable or disable services on boot you use the <code>rc-update</code> command. | ||
< | <syntaxhighlight lang="shell-session"> | ||
List the services that are added to a runlevel | List the services that are added to a runlevel | ||
$ rc-update | $ rc-update | ||
Line 86: | Line 130: | ||
Stop NetworkManager starting on boot | Stop NetworkManager starting on boot | ||
$ sudo rc-update del networkmanager default | $ sudo rc-update del networkmanager default | ||
</ | </syntaxhighlight> | ||
==== Log files ==== | |||
By default, postmarketOS with OpenRC uses [https://git.sr.ht/~martijnbraam/logbookd logbookd] for the syslog and it's configured to log to memory only. The <code>logread</code> command is used to read the in-memory log. Writing standard output and standard error of a system service to the filesystem can be achieved by setting <code>output_log</code> and <code>error_log</code> to file paths in its service script, as described in the manual page <code>openrc-run</code>. | |||
By default postmarketOS uses | |||
ModemManager logs to syslog by default as well, but prints almost nothing until manually increasing the log level with <code>sudo mmcli -G DEBUG</code>. Be aware that especially ModemManager logs a lot of sensitive information, such as phone numbers, text messages, IMEI, cell towers, etc! | ModemManager logs to syslog by default as well, but prints almost nothing until manually increasing the log level with <code>sudo mmcli -G DEBUG</code>. Be aware that especially ModemManager logs a lot of sensitive information, such as phone numbers, text messages, IMEI, cell towers, etc! | ||
Most user interfaces use [https://gitlab. | Most user interfaces use [https://gitlab.postmarketos.org/postmarketOS/tinydm tinydm] to start the session in postmarketOS, which logs to <code>~/.local/state/tinydm.log</code>. | ||
A discussion to possibly change logging defaults is in {{issue|1574|pmaports}}. | A discussion to possibly change logging defaults is in {{issue|1574|pmaports}}. | ||
Line 102: | Line 147: | ||
but installing the specific documentation subpackage. For example for vim documentation you can install <code>vim-doc</code> | but installing the specific documentation subpackage. For example for vim documentation you can install <code>vim-doc</code> | ||
< | <syntaxhighlight lang="shell-session"> | ||
the mandoc package is the man page reader itself | the mandoc package is the man page reader itself | ||
the man-apropos adds the apropos manpage search tool | the man-apropos adds the apropos manpage search tool | ||
Line 109: | Line 154: | ||
$ sudo apk add -i mandoc mandoc-apropos man-pages docs | $ sudo apk add -i mandoc mandoc-apropos man-pages docs | ||
$ man nvim | $ man nvim | ||
</ | </syntaxhighlight> | ||
== Changing your shell == | == Changing your shell == | ||
Line 115: | Line 160: | ||
Since the pmos installations are based on busybox the default shell is <code>ash</code>, which is comparable to <code>sh</code>. There are multiple shells packaged in Alpine if you want something better: | Since the pmos installations are based on busybox the default shell is <code>ash</code>, which is comparable to <code>sh</code>. There are multiple shells packaged in Alpine if you want something better: | ||
< | <syntaxhighlight lang="shell-session"> | ||
pick your favorite shell | pick your favorite shell | ||
$ sudo apk add -i bash zsh fish dash yash oksh elvish | $ sudo apk add -i bash zsh fish dash yash oksh elvish | ||
Line 124: | Line 169: | ||
some config distributions are packaged | some config distributions are packaged | ||
$ sudo apk add -i grml-zsh-config oh-my-zsh | $ sudo apk add -i grml-zsh-config oh-my-zsh | ||
</source> | </syntaxhighlight> | ||
== Getting session environment == | |||
When working on things like pipewire or other software that needs access to the user session, it can be frustrating to do over ssh. The following one-liner can be used to set up the environment | |||
<syntaxhighlight lang="shell-session"> | |||
# Replace with your DE (phosh, sway, etc) | |||
$ export TARGET="gnome-shell" | |||
$ eval $(cat /proc/$(pidof $TARGET)/environ | tr '\0' '\n' | grep -v '^TERM=' | awk '{ print "export \"" $0 "\"" }') | |||
</syntaxhighlight> | |||
This can be installed in your <code>~/.bashrc</code> or <code>~/.zshrc</code> as follows: | |||
<pre> | |||
yoinkenv () { | |||
TARGET=${1:-gnome-shell} | |||
echo "Yoinking environment from $APP" | |||
eval $(cat /proc/$(pidof $TARGET)/environ | tr '\0' '\n' | grep -v '^TERM=' | awk '{ print "export \"" $0 "\"" }') | |||
} | |||
</pre> | |||
Note that in order to have <code>~/.bashrc</code> being sourced in a ssh session, you need something like the following in your <code>~/.bash_profile</code>: | |||
<pre> | |||
if [ -f ~/.bashrc ]; then | |||
. ~/.bashrc | |||
fi | |||
</pre> | |||
== Pushing source changes to a target == | |||
For some development, it might be easiest to edit the source code on your laptop/PC but compile on the device. This can be made easy with a small one-liner you can run from your project checkout to sync changes to the device every time you save. You will need to create the target directory on the device manually. | |||
<syntaxhighlight lang="shell"> | |||
while true; do inotifywait -e modify src/**; rsync --exclude-from=.gitignore -a . pmos:projects/$(basename "$PWD")/; done | |||
</syntaxhighlight> | |||
Rsync will ignore all paths specified in the local <code>.gitignore</code>. | |||
This expects you to have a <code>pmos</code> entry in your SSH config, see [[SSH#Config]] for more info. | |||
== Rebooting to fastboot == | |||
<syntaxhighlight lang="shell-session"> | |||
On systemd installs: | |||
# systemctl reboot --reboot-argument=bootloader | |||
On OpenRC installs (this doesn't properly shutdown your device): | |||
# reboot-mode bootloader | |||
</syntaxhighlight> | |||
== See also == | == See also == |
Latest revision as of 12:51, 3 February 2025

Here's a small reference for working with postmarketOS/Alpine Linux.
Package management
The package manager in postmarketOS is called apk
, the Alpine Package Keeper. The list of packages can be found at pkgs.alpinelinux.org and pkgs.postmarketos.org.
The Alpine Linux wiki has a page comparing apk to other popular package managers, with many helpful examples.
Installing a package
$ sudo apk add neovim
Uninstalling a package
$ sudo apk del neovim
Upgrading the system
The -a
option allows downgrading packages to what's available in the repository. It is generally recommended to always use this option, especially on stable releases, to ensure that any package reverts make it to your device.
$ sudo apk upgrade -a
Repairing packages
Run various package repair strategies, e.g. running failed installation scripts again:
$ sudo apk fix
$ sudo apk fix name-of-package # will also reinstall name-of-package
Listing installed packages
Listing installed package versions (add | grep package-name
to filter for a specific package):
$ apk info -vv
$ apk info -vv | grep package-name
Installing build dependencies
$ sudo apk add build-base install-makedepends
$ install-makedepends neovim
Config files
The repositories are stored in /etc/apk/repositories
as one repository url per line. There's also /etc/apk/world
which is a list of packages that are explicitly installed. It's possible to add/remove packages from this list and then running apk fix
to apply those changes.
New installations of postmarketOS let apk ask for confirmation by default. If you don't want this, delete /etc/apk/interactive
(pmaports!3444).
Logging with apk
A feature to log each apk action, especially which packages have been installed with an upgrade will be available in apk3. In the meantime, similar functionality can be achieved by installing etckeeper
. It turns your /etc
directory into a git repository, tracking changes to all files in there, and it also records package changes and related versions in the git log.
$ sudo apk add etckeeper
$ sudo apk add hello-world
$ sudo git -C /etc log
commit e8dc072cbe037eeaeec3adb8649680b2fcd10130 (HEAD -> master)
Author: root <root@nokia-n900>
Date: Tue Jan 9 15:43:28 2024 +0000
committing changes in /etc after apk run
Package changes:
+hello-world-1-r6
Service management
systemd
systemd is the default service manager for GNOME (Desktop and Mobile), Plasma (Desktop and Mobile) and Phosh.
Basic service management is done with systemctl
.
$ sudo systemctl status NetworkManager
$ sudo systemctl start NetworkManager
$ sudo systemctl stop NetworkManager
$ sudo systemctl restart NetworkManager
To enable or disable services on boot:
$ sudo systemctl enable NetworkManager
$ sudo systemctl disable NetworkManager
OpenRC
OpenRC is the default service manager for all other UIs.
The basic service management is done with the familiar rc-service
command.
Tip: rc-service is also symlinked to service which is shorter to type. |
$ rc-service networkmanager status
$ sudo rc-service networkmanager start
$ sudo rc-service networkmanager stop
$ sudo rc-service networkmanager restart
To enable or disable services on boot you use the rc-update
command.
List the services that are added to a runlevel
$ rc-update
bootmisc | boot
chronyd | default
dbus | default
devfs | sysinit
dmesg | sysinit
gdm | default
haveged | default
hostname | boot
hwclock | boot
killprocs | shutdown
Start NetworkManager on boot (in the default runlevel)
$ sudo rc-update add networkmanager default
Stop NetworkManager starting on boot
$ sudo rc-update del networkmanager default
Log files
By default, postmarketOS with OpenRC uses logbookd for the syslog and it's configured to log to memory only. The logread
command is used to read the in-memory log. Writing standard output and standard error of a system service to the filesystem can be achieved by setting output_log
and error_log
to file paths in its service script, as described in the manual page openrc-run
.
ModemManager logs to syslog by default as well, but prints almost nothing until manually increasing the log level with sudo mmcli -G DEBUG
. Be aware that especially ModemManager logs a lot of sensitive information, such as phone numbers, text messages, IMEI, cell towers, etc!
Most user interfaces use tinydm to start the session in postmarketOS, which logs to ~/.local/state/tinydm.log
.
A discussion to possibly change logging defaults is in pmaports#1574.
Man pages
Man pages are not installed by default and are seperate from the normal packages. The docs
package is a metapackage that will pull in all the documentation for the software you have installed. You can also install only the documentation you need by not installing the docs
package
but installing the specific documentation subpackage. For example for vim documentation you can install vim-doc
the mandoc package is the man page reader itself
the man-apropos adds the apropos manpage search tool
the man-pages package will add the pages for core software like chmod but also linux headers
the docs package is a metapackage that pulls in the -doc package for everything you install
$ sudo apk add -i mandoc mandoc-apropos man-pages docs
$ man nvim
Changing your shell
Since the pmos installations are based on busybox the default shell is ash
, which is comparable to sh
. There are multiple shells packaged in Alpine if you want something better:
pick your favorite shell
$ sudo apk add -i bash zsh fish dash yash oksh elvish
set your login shell
$ chsh -s /bin/zsh
some config distributions are packaged
$ sudo apk add -i grml-zsh-config oh-my-zsh
Getting session environment
When working on things like pipewire or other software that needs access to the user session, it can be frustrating to do over ssh. The following one-liner can be used to set up the environment
# Replace with your DE (phosh, sway, etc)
$ export TARGET="gnome-shell"
$ eval $(cat /proc/$(pidof $TARGET)/environ | tr '\0' '\n' | grep -v '^TERM=' | awk '{ print "export \"" $0 "\"" }')
This can be installed in your ~/.bashrc
or ~/.zshrc
as follows:
yoinkenv () { TARGET=${1:-gnome-shell} echo "Yoinking environment from $APP" eval $(cat /proc/$(pidof $TARGET)/environ | tr '\0' '\n' | grep -v '^TERM=' | awk '{ print "export \"" $0 "\"" }') }
Note that in order to have ~/.bashrc
being sourced in a ssh session, you need something like the following in your ~/.bash_profile
:
if [ -f ~/.bashrc ]; then . ~/.bashrc fi
Pushing source changes to a target
For some development, it might be easiest to edit the source code on your laptop/PC but compile on the device. This can be made easy with a small one-liner you can run from your project checkout to sync changes to the device every time you save. You will need to create the target directory on the device manually.
while true; do inotifywait -e modify src/**; rsync --exclude-from=.gitignore -a . pmos:projects/$(basename "$PWD")/; done
Rsync will ignore all paths specified in the local .gitignore
.
This expects you to have a pmos
entry in your SSH config, see SSH#Config for more info.
Rebooting to fastboot
On systemd installs:
# systemctl reboot --reboot-argument=bootloader
On OpenRC installs (this doesn't properly shutdown your device):
# reboot-mode bootloader
See also
- pmaports#1574 Make logging consistent