Maintenance and peripherals
System maintenance and troubleshooting is a reoccurring task to take care of your system and be able to analyze and solve technical issues. In addition, peripherals1 sometimes require some tinkering, which supports in the process of learning the details and quirks of your system. For this reason, the sections in this guide focus on the following tasks:
- General #Maintenance tasks and automation
- Setting up #Peripherals
- #Bluetooth controller
- #Printer and scanner
- Additional encrypted #Storage
- #Hardware monitoring
Maintenance
Ensure the intended system functionality over a period of time: constantly check for errors by using the following command to identify failed systemd services:
sudo systemctl --failedUse the Systemd journal to read logfiles as follows:
sudo journalctl -p 3 -bXorg troubleshooting
also starts by checking the Systemd journal. Its own logfiles are created in
case of any errors inside your user directory. The filename scheme is in the
form of Xorg.n.log with n designating the display number. Search your user
directory for such files by using this command:
grep -e Log -e tty Xorg.0.logSearch the forums and ask questions, lookup terms in the ArchWiki, and consult a search engine of your choice for debugging errors and interpreting warnings.
Examples
The following examples are some issues that I encountered.
A failed service
In my case pkgfile-update.service fails due to missing internet connectivity. This is a typical situation on a notebook with no constant internet connection. A solution is to adapt the service unit by using a drop-in file to run the service after nss-lookup.target is reached.
The drop-in file is created using the command:
sudo systemctl edit pkgfile-update.service --drop-in=nss-lookup.confAnd its content is:
[Unit]
After=nss-lookup.targetTo force a re-run of the service use:
sudo systemctl --now start pkgfile-update.serviceAs I will be using a #Package update notifier, I can remove pkgfile and its dependecies using:
sudo pacman -Rns pkgfileNotice that its cache directory /var/cache/pkgfile is not removed automatically. You must run:
sudo rm -rf /var/cache/pkgfileto remove it.
Backup
Most important is to maintain a backup2 of your system. Filesystem level
backup can be done via rsync and
disk cloning is
a task for the ddrescue copmmand. It supports block devices including
(optical) disks and SD cards. Install the following packages:
sudo pacman -S ddrescue rsyncFull system backup
from $SRC to $DST excluding directory contents of devices and typical mount
points is achieved using this command:
sudo rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} $SRC/ $DST/Note that the trailing slash is mandatory for synchronizing the folder contents! You probably want to write a backup script for automation. I like to backup my the filesystems of my machines into a directory named after the hostname on a physical HDD3 and clean the filesystem in advance to save space:
#!/bin/bash
#
# Full system backup using rsync with deletion of non-existent files in $DST
# https://wiki.archlinux.org/title/Rsync#Full_system_backup
SRC=/
HST=$(hostnamectl hostname)
DST=$(pwd)/$HST
# Remove old local packages to save space
sudo pacman -Scc
# Clean user data cache
rm -rf ~/.cache/*
# Synchronize
sudo rsync \
-aAXHv \
--delete \
--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} \
$SRC \
$DSTLogfile limit
I like to keep Systemd’s journal size limit below 200 MB. For this setting, I
uncomment and adapt a line in the /etc/systemd/journald.conf file to match:
SystemMaxUse=200MAfterwards I need to restart the Journald service:
sudo systemctl restart systemd-journald.serviceFilesystem cleanup
Files which are not owned by any package can be listed and written to a text file with lostfiles. Additionally, the rmlint tool finds (and optionally removes) duplicate files. I install both packages as follows:
sudo pacman -S lostfiles rmlintLostfiles command is executed via #sudo:
sudo lostfiles > ~/lostfiles.txtAnd in addition, The following command finds broken symlinks4 and writes them
into another .txt file for easier post-processing:
sudo find / -xtype l -print | sudo tee broken_symlinks.txtAdditionally, I ocasionally create a list of installed packages to investigate potentionally unused or legacy applications by invoking the following command:
sudo pacman -Qqe | sudo tee /etc/pkglist.txtIf you are curious which package occupies how much disk space (and you may decide to remove it), you can run this command to scroll through a list using the less pager5:
pacman -Qi | grep -E '^(Name|Installed)' | cut -f2 -d':' | paste - - | column -t | sort -nrk 2 | grep MiB | lessKeep in mind that you may need to adapt the strings for the grep search pattern as pacman uses localization in its output. In my case I run:
pacman -Qi | grep -E '^(Name|Installationsgröße)' | cut -f2 -d':' | paste - - | column -t | sort -nrk 2 | grep MiB | lessIf there is no output, run pacman -Qi base first to identify the wording of the package name and installation size descriptors for the base package, for example.
Automation
You may want to automate some of the aforementioned tasks to happen on a regular basis.
Job scheduler
The cronie package is a cron functionality provider on a per-user crontab file and can be installed using:
sudo pacman -S croniePeripherals
Bluetooth
Before continuing, ensure that the bluetooth device is not blocked by rfkill.
I issue the following command and identify the SOFT and HARD state:
sudo rfkillThere is an increasing amount of peripherals for short-range wireless connection via bluetooth. The basic bluetooth capabilities are provided by bluez and bluez-utils. These packages are installed as follows:
sudo pacman -S bluez bluez-utilsAfterwards I enable and start bluetooth.service:
sudo systemctl enable bluetooth.service
sudo systemctl start bluetooth.serviceFollow pairing instructions in the ArchWiki to setup bluetooth devices.
Headset
Connecting a headset via PipeWire, as configured in #Sound system, requires the pipewire-pulse package. Proceed with the section Configuration via CLI similar to pairing other bluetooth devices. Or to ease this process, a full- featured management GUI is Blueman. I install the package via:
sudo pacman -S bluemanStart the application by invoking blueman-applet & and configure bluetooth
devices according to the usage
documentation.
Known bugs
If the controller is not available or bluetooth seems to crash regularly,
disable USB autosuspend to prevent reloading of the btusb module. Create a
/etc/modprobe.d/btusb.conf file with the following content to achieve this
behavior:
options btusb enable_autosuspend=nPrinter and scanner
CUPS
Printing is realized with CUPS. After installing the package cups:
sudo pacman -S cupsI start and enable its service:
sudo systemctl enable cups.service
sudo systemctl start cups.serviceAny further configuration of printers can be done graphically via the web
interface available at http://localhost:631. One
exception is setting the default paper size. However, appending it to the file
/etc/papersize solves this issue due to CUPS’s support lipaper. In Germany the
ISO 216 (DIN A4) paper size defines the
standard. To set a4 for lipaper I execute the following command:
sudo echo "a4" | sudo tee -a /etc/papersizeSANE
For scanning, I install the SANE library and use the provided scanimage command. As a graphical frontend, I recommend NAPS2, which is provided by the AUR package naps2. I install the sane package by executing:
sudo pacman -S saneAfterward installation I run:
sudo scanimage -LI use the provided <scanner-device-name> of my hardware to be substituted in a bash script I create as e.g. ~/scripts/scan1page:
#!/bin/bash
#
# scan via command line
# check if scanimage is installed
hash scanimage 2>/dev/null || { echo >&2 "scanimage is required, but not installed. Aborting."; exit 1; }
# check if argument is provided
if [ $# -gt 3 ]
then
echo "Usage: $0 <format> <resolution> <output-file> or $0 without options to use defaults"
exit 1
fi
DEV="<scanner-device-name>"
FMT=$1 # supported formats are pnm, tiff, png, jpeg
RES=$2
OUT=$3
if [ -z $FMT ]
then
FMT=tiff
fi
if [ -z $RES ]
then
RES=300
fi
if [ -z $OUT ]
then
OUT=scan_$RES.$FMT
fi
echo "Using $FMT format with $RES PPI and saving to $OUT"
scanimage --device $DEV --format=$FMT --output-file=$OUT --progress --resolution $RES
exit 0After making it executable via chmod +x ~/scripts/scan1page I can use it like this:
~/scripts/scan1page tiff 150 first_scan_150.tiffYou may need to create a udev rule to fix a permission problem. I found out the USB <vendorID> and <productID> via:
sudo sane-find-scannerand created the file /etc/udev/rules.d/65-sane-missing-scanner.rules with the following content:
ATTRS{idVendor}=="<vendorID>", ATTRS{idProduct}=="<productID>", MODE="0664", GROUP="lp", ENV{libsane_matched}="yes"Remember to substitute <vendorID> and <productID> with your values from the output of the sane-find-scanner command and reload udev rules using:
sudo udevadm control --reload-rules && sudo udevadm triggerStorage
Additional removable storage such as an USB flash drive6 or an external HDD/ SSD may be necessary for archiving data at rest. While I tend to use data at rest encryption such filesystems can be mounted automatically by using a key stored in and read from the root filesystem for convenience.
Device identification
First, I identify the disk device using:
sudo fdisk -lEncryption and opening
Assuming that your disk is /dev/sda the next steps are straightforward and
similar to #Encryption and LVM as
documented in the System preparation guide.
I encrypt and open the block device as follows:
sudo cryptsetup luksFormat /dev/sda
sudo cryptsetup open /dev/sda csd
Be careful not to use the disk of your installed system if this disk is at
/dev/sda! Double check the mount point of your root filesystem by invoking:
df | grep -w '/'Filesystem creation
Other than in the System preparation a single ext4 filesystem inside the LUKS container is sufficient and will be formatted using the command:
sudo mkfs.ext4 /dev/mapper/csdTuning and labeling
Reserved blocks (for
root) are not necessary on a removable device. For this reason, I use tune2fs
and set a label using the e2label utility before closing the mapper device:
sudo tune2fs -m 0 /dev/mapper/csd
sudo e2label /dev/mapper/csd csd
sudo cryptsetup close csdUnlock and mount automation
I use unlocking with a keyfile to automatically mount the device at boot. A
keyfile
is created and added to slot 1 of my block device (/dev/sda in this example):
sudo mkdir /etc/cryptsetup-keys.d
sudo dd if=/dev/urandom of=/etc/cryptsetup-keys.d/csd.key bs=512 skip=4 count=8
sudo cryptsetup luksAddKey /dev/sda /etc/cryptsetup-keys.d/csd.key --key-slot 1Next, I identify and save the UUIDs of /dev/sda and /dev/mapper/csd in order
to append it to the /etc/crypttab file using the following commands:
DevUuid=$(sudo blkid | grep /dev/sda | cut --delimiter=' ' --field=2 | sed 's/[^a-z0-9\\-]//g')
echo "csd UUID=$DevUuid /etc/cryptsetup-keys.d/csd.key noauto" | sudo tee -a /etc/crypttabnoauto parameter prevents Systemd trying to automatically mounting the
encrypted file system at boot leading to a long timeout, if the device is not
plugged in. If you are working with non-removable media you must also edit
/etc/fstab and create mountpoints as necessary.Finally, I reload the Systemd daemon using:
sudo systemctl daemon-reloadAnd I re-plug my storage device to proceed as usual in Thunar using removable media.
Hardware monitoring
A crucial task is to monitor the health of your hardware to prevent data loss and guarantee system performance. For example, hard disk drives and solid state disks unnoticely wear off over time and can fail. Depending on your usage and product quality, this may happen sooner or later. However, there are tools to query health information for planning and aquiring substitutes.
Disk health
Modern storage devices provide S.M.A.R.T. (Self-Monitoring, Analysis, and Reporting Technology)7 to query the health of their operation. I install the smartmontools package including some tools for interaction:
sudo pacman -S smartmontoolsAssuming that the disk to test is /dev/sda, I check for SMART support using the command:
sudo smartctl --info /dev/sda | grep 'SMART support is:'Some USB bridges of external drives are blacklisted since they are known to use a buggy firmware. If the aforementioned command does not show SMART support, follow instructions in this forum post.
In step 6, instead of the update-initramfs command use the following command for manual generation of the initial ramdisk:
sudo mkinitcpio -PHowever, be aware that there are reasons that your USB bridge may be an unsupported USB-devices.
If SMART is available but not enabled, I can turn it on using:
sudo smartctl --smart=on /dev/sdaRun a test
The smartctl command can run four different tests (all are safe to user data). Refer to the smartctl man page to learn more about their characteristics. In general, I run a short test invoked by:
sudo smartctl --test=short /dev/sdaIn addition, a conveyance test may identify damages due to transportation:
sudo smartctl --test=conveyance /dev/sdaThe test results can be viewed by running:
sudo smartctl --log=selftest /dev/sdaAnd with further information, such as temperature, power cycles, etc., by invoking:
sudo smartctl --xall /dev/sdaThe value for the overall-health self-assessment test result should be PASSED and is shown via:
smartctl --health /dev/sdaProceed with the configuration of basic multimedia and web capabilities or go back to the overview and follow instructions for specific use cases.
-
Peripheral in the Wikipedia ↩︎
-
Hard disk drive in the Wikipedia ↩︎
-
Symbolic link in the Wikipedia ↩︎
-
Forum post discussing the command ↩︎
-
USB flash drive in the Wikipedia ↩︎
-
Self-Monitoring, Analysis and Reporting Technology in the Wikipedia ↩︎