Difference between revisions of "System maintenance"

From ArchWiki
Jump to: navigation, search
(Packages)
(Broken symlinks: This `find` call accomplishes the same)
 
(211 intermediate revisions by 26 users not shown)
Line 1: Line 1:
 
[[Category:System administration]]
 
[[Category:System administration]]
[[zh-cn:Arch Linux System Maintenance]]
+
[[ja:システムメンテナンス]]
== Read the News ==
+
[[ru:System maintenance]]
 +
[[zh-cn:System maintenance]]
 +
[[fa:نگهداشت سیستم]]
 +
{{Related articles start}}
 +
{{Related|General recommendations}}
 +
{{Related articles end}}
 +
Regular system maintenance is necessary for the proper function of Arch over a period of time.  Timely maintenance is a practice many users get accustomed to.
  
Often, the developers will provide important information about required configurations and modifications for known issues. The Arch Linux user is expected to consult these places before performing an upgrade.
+
== Check for errors ==
  
The Arch Linux News is posted here: [https://www.archlinux.org/news] You can subscribe to the rss feed by adding: [https://www.archlinux.org/feeds/news] to your favorite feed reading software. You can also get news by subscribing to the Arch Announce mailing list: [https://mailman.archlinux.org/mailman/listinfo/arch-announce].
+
=== Failed systemd services ===
  
Pay special attention to news items with "manual intervention required" in their header. You can avoid a lot of trouble and embarrassment by reading the instructions in these news announcements and following them.
+
Check if any systemd services have entered in a failed state:
  
== Update the system ==
+
$ systemctl --failed
  
{{Warning|1=System updates should be performed with care. It is very important to read and understand [https://bbs.archlinux.org/viewtopic.php?id=57205 this] before proceeding.}}
+
See [[Systemd#Analyzing the system state]] for more information.
  
Sync, refresh the package database, and upgrade your entire system with:
+
=== Logfiles ===
  
# pacman -Syu
+
Look for errors in the log files located at {{ic|/var/log}}, as well as high priority errors in the systemd journal:
  
Or, same thing:
+
# journalctl -p 3 -xb
  
# pacman --sync --refresh --sysupgrade
+
See [[Systemd#Journal]] for more information.
  
If you are prompted to upgrade pacman itself at this point, respond by pressing {{ic|Y}}, and then reissue the {{ic|pacman -Syu}} command when finished.
+
See [[Xorg#Troubleshooting]] for information on where and how [[Xorg]] logs errors.
  
{{Note|Occasionally, configuration changes may take place requiring user action during an update; read pacman's output for any pertinent information. See [[Pacnew and Pacsave Files]] for more details.}}
+
== Backup ==
  
Keep in mind that Arch is a '''rolling release''' distribution. This means the user doesn't have to reinstall or perform elaborate system rebuilds to upgrade to the newest version. Issuing {{ic|pacman -Syu}} periodically (and noting the above warning) keeps the entire system up-to-date and on the bleeding edge. At the end of this upgrade, the system will be completely current.
+
Create backups of important data at regular intervals. Those data include configuration files, installed packages and directories such as {{ic|/etc}}, {{ic|/home}}, {{ic|/var}} and for server installations, also {{ic|/srv}}.
  
See [[Pacman]] and [[FAQ#Package Management]] for answers regarding updating and managing packages. See [[Upgrade Path|this page]] if you have not update your system for a long time.
+
See [[Synchronization and backup programs]] for many alternative applications that may better suit your case. See [[:Category:System recovery]] for other articles of interest.
  
==Packages==
+
Backups may be automated with [[systemd/Timers]].
  
* When you update, check pacman output for instructions related to updated packages.
+
=== Configuration files ===
  
* Use {{ic|pacman -Qdt}} to find orphaned packages, and {{ic|pacman -Qo <file>}} to find out which package owns that particular file. Alternatively you can use the '''pkg-list_true_orphans''' command from {{aur|pkg_scripts}} to find only real orphans.
+
Before editing any configuration files, create a backup. This way, you can revert to a working version in case of problems. Editors like [[vim]] and [[emacs]] can do this automatically, as well as tools like [[etckeeper]] which keep {{ic|/etc}} in a version control system (VCS).
  
* Search for .pac* files and merge them with configuration files (see [[Pacnew and Pacsave Files]]).
+
=== List of installed packages ===
  
* Check for out-of-date or unmaintained [[Arch User Repository|AUR]] packages on your system. Sometimes these can cause problems when you update.
+
Maintain a list of all installed packages, so that if a complete re-installation is inevitable, it is easier to re-create the original environment.
  
* Check the size of {{ic|/var}} and clear pacman's cache once in a while. A useful tool to assist in this process is {{AUR|pkgcacheclean}}.
+
See [[Pacman tips#List of installed packages]] for details.
  
==Hardware==
+
=== Pacman database ===
  
* Check disk (use fstab options to check at boot)
+
See [[Pacman tips#Back-up the pacman database]].
  
* Search logs for errors (list scripts, tools to make this easier/more automated)
+
=== LUKS headers ===
  
* Look into errors as soon as possible - do not leave them unattended to.
+
It can make sense to periodically check and synchronize the backups of LUKS-encrypted partition headers, especially if passphrases have been revoked. See [[Dm-crypt/Device encryption#Backup and restore]].
  
==Bad Practices==
+
== Upgrading the system ==
  
* Linking random libraries together to get a program to work.
+
It is recommended to perform full system upgrades regularly, to enjoy both the latest bug fixes and security updates, and also to avoid having to deal with too many package upgrades that require manual intervention at once. See [[Pacman#Upgrading packages]] for details.
  
* Updating once a year.
+
Make sure to have the Arch install media or another Linux "live" CD/USB available so you can easily rescue your system if there is a problem after updating. If you are running Arch in a production environment, or cannot afford downtime for any reason, test changes to configuration files, as well as updates to software packages, on a non-critical duplicate system first. Then, if no problems arise, roll out the changes to the production system.  
  
* Copy-pasting commands into the terminal without at least reading man pages to understand what you are doing to your system.
+
If the system has packages from the [[AUR]], carefully upgrade all of them.  
  
* Clearing the entire package cache using {{ic|pacman -Scc}} - this removes the possibility to do package downgrades in cases of breakage.
+
=== Avoid certain pacman commands ===
  
==See also==
+
Avoid doing [[#Partial upgrades are unsupported|partial upgrades]], i.e. never run {{ic|pacman -Sy}} and instead use {{ic|pacman -Syu}}.
*[[General Recommendations#System administration]]
+
 
*[[:Category:System administration]]
+
Avoid using the {{ic|--force}} option with pacman, '''especially''' in commands such as {{Ic|pacman -Syu --force}} involving more than one package. The {{ic|--force}} option ignores file conflicts and can even cause file loss when files are relocated between different packages! In a properly maintained system, it should only be used when explicitly recommended by the Arch developers (see [[#Read before upgrading the system]]).
 +
 
 +
Avoid using the {{ic|-d}} option with pacman. {{Ic|pacman -Rdd package}} skips dependency checks during package removal. As a result, a package providing a critical dependency could be removed, resulting in a broken system.
 +
 
 +
=== Partial upgrades are unsupported ===
 +
 
 +
Arch Linux is a [[Wikipedia:rolling release|rolling release]] distribution. That means when new [[Wikipedia:Library (computing)|library]] versions are pushed to the repositories, the developers and Trusted Users rebuild all the packages in the repositories that need to be rebuilt against the libraries. For example, if two packages depend on the same library, upgrading only one package might also upgrade the library (as a dependency), which might then break the other package which depends on an older version of the library.
 +
 
 +
That is why partial upgrades are '''not supported'''. Do not use {{ic|pacman -Sy package}} or any equivalent such as {{ic|pacman -Sy}} followed by {{ic|pacman -S package}}, '''always''' upgrade (with {{ic|pacman -Syu}}) before installing a package. Be very careful when using {{ic|IgnorePkg}} and {{ic|IgnoreGroup}} for the same reason. If the system has locally installed packages (such as [[AUR]] packages), users will need to rebuild them when their dependencies receive a [[Wikipedia:soname|soname]] bump.
 +
 
 +
If a partial upgrade scenario has been created, and binaries are broken because they cannot find the libraries they are linked against, '''do not "fix" the problem simply by symlinking'''. Libraries receive [[Wikipedia:soname|soname]] bumps when they are '''not backwards compatible'''. A simple {{ic|pacman -Syu}} to a properly synced mirror will fix the problem as long as ''pacman'' is not broken.
 +
 
 +
The bash script ''checkupdates'', included with the pacman package, provides a safe way to check for upgrades to installed packages without running a system update at the same time. See also [https://bbs.archlinux.org/viewtopic.php?pid=1563725#p1563725 BBS##1563725].
 +
 
 +
=== Read before upgrading the system ===
 +
 
 +
Before upgrading Arch, always read the latest [https://www.archlinux.org/news/ Arch News] to find out if there are any major software or configuration changes with the latest packages. Before upgrading fundamental software (such as the [[kernel]], [[xorg]], [[systemd]], or {{Pkg|glibc}}) to a new version, look over the appropriate [https://bbs.archlinux.org/ forum] to see if there have been any reported problems.
 +
 
 +
=== Act on alerts during an upgrade ===
 +
 
 +
When upgrading the system, be sure to pay attention to the alert notices provided by [[pacman]]. If any additional actions are required by the user, be sure to take care of them right away. If a pacman alert is confusing, search the forums and the recent news posts for more detailed instructions.
 +
 
 +
=== Deal promptly with new configuration files ===
 +
 
 +
When pacman is invoked, {{ic|.pacnew}} and {{ic|.pacsave}} files can be created. Pacman provides notice when this happens and users must deal with these files promptly. Users are referred to the [[Pacnew and Pacsave files]] wiki page for detailed instructions.
 +
 
 +
Also, think about other configuration files you may have copied or created. If a package had an example configuration that you copied to your home directory, check to see if a new one has been created.
 +
 
 +
=== Revert broken updates ===
 +
 
 +
If a package update is expected/known to cause problems, packagers will ensure that pacman displays an appropriate message when the package is updated. If experiencing trouble after an update, double-check pacman's output by looking at {{ic|/var/log/pacman.log}}.
 +
 
 +
At this point, only after ensuring there is no information available through pacman, there is no relative news on https://www.archlinux.org/, and there are no forum posts regarding the update, consider seeking help on the [https://bbs.archlinux.org forum], over [[IRC]], or by [[downgrading]] the offending package.
 +
 
 +
== Use the package manager to install software ==
 +
 
 +
[[Pacman]] does a much better job than you at keeping track of files. If you install things manually you ''will'', sooner or later, forget what you did, forget where you installed to, install conflicting software, install to the wrong locations, etc. Instead, learn how to [[Creating packages|create a package]].
 +
 
 +
To clean up improperly installed files, use {{AUR|lostfiles}} or see [[Pacman/Tips and tricks#Identify files not owned by any package]].
 +
 
 +
=== Choose open-source drivers ===
 +
 
 +
Always try open source drivers before resorting to proprietary drivers. Most of the time, open source drivers are more stable and reliable than proprietary drivers. Open source driver bugs are fixed more easily and quickly. While proprietary drivers can offer more features and capabilities, this can come at the cost of stability. To avoid this dilemma, try to choose hardware components known to have mature open source driver support with full features. Information about hardware with open source Linux drivers is available at [http://www.linux-drivers.org/ linux-drivers.org].
 +
 
 +
=== Be careful with unofficial packages ===
 +
 
 +
Use precaution when using packages from the [[AUR]] or an [[unofficial user repository]]. Most are supplied by regular users and thus may not have the same standards as those in the official repositories. Be careful with [[AUR helpers]] which automate installation of AUR packages. '''Always''' check PKGBUILDs for sanity and signs of mistake or malicious code before building and/or installing the package.
 +
 
 +
To simplify maintenance, limit the amount of unofficial packages used. Make periodic checks on which are in actual use, and remove (or replace with their official counterparts) any others. See [[pacman/Tips and tricks#Maintenance]] for useful commands.
 +
 
 +
=== Update the mirrorlist ===
 +
 
 +
Update pacman's mirrorlist, as the quality of mirrors can vary over time, and some might go offline or their download rate might degrade.
 +
 
 +
See [[mirrors]] for details.
 +
 
 +
== Clean the filesystem ==
 +
 
 +
When looking for files to remove, it is important to find the files that take up the most disk space. Programs that help with this are found in:
 +
 
 +
* [[List of applications#Disk usage display]].
 +
* [[List of applications#Disk cleaning]].
 +
 
 +
=== Package cache ===
 +
 
 +
Remove unwanted {{ic|.pkg}} files from {{ic|/var/cache/pacman/pkg/}} to free up disk space.
 +
 
 +
See [[Pacman#Cleaning the package cache]] for more information.
 +
 
 +
=== Unused packages (orphans) ===
 +
 
 +
Remove unused packages from the system to free up disk space and simplify maintenance.
 +
 
 +
See [[Pacman/Tips and tricks#Removing unused packages (orphans)]] for details.
 +
 
 +
=== Old configuration files ===
 +
 
 +
Old configuration files may conflict with newer software versions, or corrupt over time. Remove unneeded configurations periodically, particularly in your home folder and {{ic|~/.config}}. For similar reasons, be careful when sharing home folders between installations.
 +
 
 +
Look for the following folders:
 +
 
 +
* {{ic|~/.config/}} -- where apps stores their configuration
 +
* {{ic|~/.cache/}} -- cache of some programs may grow in size
 +
* {{ic|~/.local/share/}} -- old files may be lying there
 +
 
 +
See [[XDG Base Directory support]] for more information.
 +
 
 +
To keep the home directory clean from temporary files created at the wrong place, it is a good idea to manage a list of unwanted files and remove them regularly, for example with [https://github.com/lahwaacz/Scripts/blob/master/rmshit.py rmshit.py].
 +
 
 +
{{Pkg|rmlint}} can be used to find and optionally remove duplicate files, empty files, recursive empty directories and broken symlinks.
 +
 
 +
=== Broken symlinks ===
 +
 
 +
Old, broken symbolic links might be sitting around your system; you should remove them. Examples on achieving this can be found [https://unix.stackexchange.com/questions/34248/how-can-i-find-broken-symlinks here] and [http://www.commandlinefu.com/commands/view/8260/find-broken-symlinks here].
 +
 
 +
To quickly list all the broken symlinks of your system, use:
 +
 
 +
  # find -xtype l -print
 +
 
 +
Then inspect and remove unnecessary entries from this list.
 +
 
 +
== Tips and tricks ==
 +
 
 +
The following tips are generally not required, but certain users may find them useful.
 +
 
 +
=== Use proven software packages ===
 +
 
 +
Arch's rolling releases can be a boon for users who want to try the latest features and get upstream updates as soon as possible, but they can also make system maintenance more difficult. To simplify maintenance and improve stability, try to avoid cutting edge software and install only mature and proven software. Such packages are less likely to receive difficult upgrades such as major configuration changes or feature removals. Prefer software that has a strong and active development community, as well as a high number of competent users, in order to simplify support in the event of a problem.
 +
 
 +
Avoid any use of the testing repository, even individual packages from testing. These packages are experimental and not suitable for a stable system. Similarly, avoid development packages which are built directly from upstream sources. These are usually found in the [[AUR]], with names including things like: "dev", "devel", "svn", "cvs", "git", etc.
 +
 
 +
=== Install the linux-lts package ===
 +
 
 +
The {{Pkg|linux-lts}} package is an alternative Arch kernel package, and is available in the [[Official repositories#core|core]] repository. This particular kernel version has long-term support (LTS) from upstream, including security fixes and some feature backports. It is useful if you prefer the stability of less-frequent kernel updates or if you want a fallback kernel in case a new kernel version causes problems.
 +
 
 +
To make it available as a boot option, you will need to update your [[bootloader]]'s configuration file to use the LTS kernel and ram disk: {{ic|vmlinuz-linux-lts}} and {{ic|initramfs-linux-lts.img}}.
 +
 
 +
== See Also ==
 +
* [https://bbs.archlinux.org/viewtopic.php?id=146850 Arch News Bash Script]

Latest revision as of 23:20, 19 November 2016

Related articles

Regular system maintenance is necessary for the proper function of Arch over a period of time. Timely maintenance is a practice many users get accustomed to.

Check for errors

Failed systemd services

Check if any systemd services have entered in a failed state:

$ systemctl --failed

See Systemd#Analyzing the system state for more information.

Logfiles

Look for errors in the log files located at /var/log, as well as high priority errors in the systemd journal:

# journalctl -p 3 -xb

See Systemd#Journal for more information.

See Xorg#Troubleshooting for information on where and how Xorg logs errors.

Backup

Create backups of important data at regular intervals. Those data include configuration files, installed packages and directories such as /etc, /home, /var and for server installations, also /srv.

See Synchronization and backup programs for many alternative applications that may better suit your case. See Category:System recovery for other articles of interest.

Backups may be automated with systemd/Timers.

Configuration files

Before editing any configuration files, create a backup. This way, you can revert to a working version in case of problems. Editors like vim and emacs can do this automatically, as well as tools like etckeeper which keep /etc in a version control system (VCS).

List of installed packages

Maintain a list of all installed packages, so that if a complete re-installation is inevitable, it is easier to re-create the original environment.

See Pacman tips#List of installed packages for details.

Pacman database

See Pacman tips#Back-up the pacman database.

LUKS headers

It can make sense to periodically check and synchronize the backups of LUKS-encrypted partition headers, especially if passphrases have been revoked. See Dm-crypt/Device encryption#Backup and restore.

Upgrading the system

It is recommended to perform full system upgrades regularly, to enjoy both the latest bug fixes and security updates, and also to avoid having to deal with too many package upgrades that require manual intervention at once. See Pacman#Upgrading packages for details.

Make sure to have the Arch install media or another Linux "live" CD/USB available so you can easily rescue your system if there is a problem after updating. If you are running Arch in a production environment, or cannot afford downtime for any reason, test changes to configuration files, as well as updates to software packages, on a non-critical duplicate system first. Then, if no problems arise, roll out the changes to the production system.

If the system has packages from the AUR, carefully upgrade all of them.

Avoid certain pacman commands

Avoid doing partial upgrades, i.e. never run pacman -Sy and instead use pacman -Syu.

Avoid using the --force option with pacman, especially in commands such as pacman -Syu --force involving more than one package. The --force option ignores file conflicts and can even cause file loss when files are relocated between different packages! In a properly maintained system, it should only be used when explicitly recommended by the Arch developers (see #Read before upgrading the system).

Avoid using the -d option with pacman. pacman -Rdd package skips dependency checks during package removal. As a result, a package providing a critical dependency could be removed, resulting in a broken system.

Partial upgrades are unsupported

Arch Linux is a rolling release distribution. That means when new library versions are pushed to the repositories, the developers and Trusted Users rebuild all the packages in the repositories that need to be rebuilt against the libraries. For example, if two packages depend on the same library, upgrading only one package might also upgrade the library (as a dependency), which might then break the other package which depends on an older version of the library.

That is why partial upgrades are not supported. Do not use pacman -Sy package or any equivalent such as pacman -Sy followed by pacman -S package, always upgrade (with pacman -Syu) before installing a package. Be very careful when using IgnorePkg and IgnoreGroup for the same reason. If the system has locally installed packages (such as AUR packages), users will need to rebuild them when their dependencies receive a soname bump.

If a partial upgrade scenario has been created, and binaries are broken because they cannot find the libraries they are linked against, do not "fix" the problem simply by symlinking. Libraries receive soname bumps when they are not backwards compatible. A simple pacman -Syu to a properly synced mirror will fix the problem as long as pacman is not broken.

The bash script checkupdates, included with the pacman package, provides a safe way to check for upgrades to installed packages without running a system update at the same time. See also BBS##1563725.

Read before upgrading the system

Before upgrading Arch, always read the latest Arch News to find out if there are any major software or configuration changes with the latest packages. Before upgrading fundamental software (such as the kernel, xorg, systemd, or glibc) to a new version, look over the appropriate forum to see if there have been any reported problems.

Act on alerts during an upgrade

When upgrading the system, be sure to pay attention to the alert notices provided by pacman. If any additional actions are required by the user, be sure to take care of them right away. If a pacman alert is confusing, search the forums and the recent news posts for more detailed instructions.

Deal promptly with new configuration files

When pacman is invoked, .pacnew and .pacsave files can be created. Pacman provides notice when this happens and users must deal with these files promptly. Users are referred to the Pacnew and Pacsave files wiki page for detailed instructions.

Also, think about other configuration files you may have copied or created. If a package had an example configuration that you copied to your home directory, check to see if a new one has been created.

Revert broken updates

If a package update is expected/known to cause problems, packagers will ensure that pacman displays an appropriate message when the package is updated. If experiencing trouble after an update, double-check pacman's output by looking at /var/log/pacman.log.

At this point, only after ensuring there is no information available through pacman, there is no relative news on https://www.archlinux.org/, and there are no forum posts regarding the update, consider seeking help on the forum, over IRC, or by downgrading the offending package.

Use the package manager to install software

Pacman does a much better job than you at keeping track of files. If you install things manually you will, sooner or later, forget what you did, forget where you installed to, install conflicting software, install to the wrong locations, etc. Instead, learn how to create a package.

To clean up improperly installed files, use lostfilesAUR or see Pacman/Tips and tricks#Identify files not owned by any package.

Choose open-source drivers

Always try open source drivers before resorting to proprietary drivers. Most of the time, open source drivers are more stable and reliable than proprietary drivers. Open source driver bugs are fixed more easily and quickly. While proprietary drivers can offer more features and capabilities, this can come at the cost of stability. To avoid this dilemma, try to choose hardware components known to have mature open source driver support with full features. Information about hardware with open source Linux drivers is available at linux-drivers.org.

Be careful with unofficial packages

Use precaution when using packages from the AUR or an unofficial user repository. Most are supplied by regular users and thus may not have the same standards as those in the official repositories. Be careful with AUR helpers which automate installation of AUR packages. Always check PKGBUILDs for sanity and signs of mistake or malicious code before building and/or installing the package.

To simplify maintenance, limit the amount of unofficial packages used. Make periodic checks on which are in actual use, and remove (or replace with their official counterparts) any others. See pacman/Tips and tricks#Maintenance for useful commands.

Update the mirrorlist

Update pacman's mirrorlist, as the quality of mirrors can vary over time, and some might go offline or their download rate might degrade.

See mirrors for details.

Clean the filesystem

When looking for files to remove, it is important to find the files that take up the most disk space. Programs that help with this are found in:

Package cache

Remove unwanted .pkg files from /var/cache/pacman/pkg/ to free up disk space.

See Pacman#Cleaning the package cache for more information.

Unused packages (orphans)

Remove unused packages from the system to free up disk space and simplify maintenance.

See Pacman/Tips and tricks#Removing unused packages (orphans) for details.

Old configuration files

Old configuration files may conflict with newer software versions, or corrupt over time. Remove unneeded configurations periodically, particularly in your home folder and ~/.config. For similar reasons, be careful when sharing home folders between installations.

Look for the following folders:

  • ~/.config/ -- where apps stores their configuration
  • ~/.cache/ -- cache of some programs may grow in size
  • ~/.local/share/ -- old files may be lying there

See XDG Base Directory support for more information.

To keep the home directory clean from temporary files created at the wrong place, it is a good idea to manage a list of unwanted files and remove them regularly, for example with rmshit.py.

rmlint can be used to find and optionally remove duplicate files, empty files, recursive empty directories and broken symlinks.

Broken symlinks

Old, broken symbolic links might be sitting around your system; you should remove them. Examples on achieving this can be found here and here.

To quickly list all the broken symlinks of your system, use:

 # find -xtype l -print

Then inspect and remove unnecessary entries from this list.

Tips and tricks

The following tips are generally not required, but certain users may find them useful.

Use proven software packages

Arch's rolling releases can be a boon for users who want to try the latest features and get upstream updates as soon as possible, but they can also make system maintenance more difficult. To simplify maintenance and improve stability, try to avoid cutting edge software and install only mature and proven software. Such packages are less likely to receive difficult upgrades such as major configuration changes or feature removals. Prefer software that has a strong and active development community, as well as a high number of competent users, in order to simplify support in the event of a problem.

Avoid any use of the testing repository, even individual packages from testing. These packages are experimental and not suitable for a stable system. Similarly, avoid development packages which are built directly from upstream sources. These are usually found in the AUR, with names including things like: "dev", "devel", "svn", "cvs", "git", etc.

Install the linux-lts package

The linux-lts package is an alternative Arch kernel package, and is available in the core repository. This particular kernel version has long-term support (LTS) from upstream, including security fixes and some feature backports. It is useful if you prefer the stability of less-frequent kernel updates or if you want a fallback kernel in case a new kernel version causes problems.

To make it available as a boot option, you will need to update your bootloader's configuration file to use the LTS kernel and ram disk: vmlinuz-linux-lts and initramfs-linux-lts.img.

See Also