Avoid Pacman headaches on Arch Linux by Automating Mirror list updates

Configurare noua (How To)

Situatie

Mirrors are servers that replicate a Linux distribution’s repositories. Arch Linux has many mirrors situated around the globe. We show you two ways to select which mirrors your Arch Linux computer uses.

Solutie

Updating the Arch Mirror List Manually

By default, Arch doesn’t automatically update the mirrors list. It creates a mirror list at install time, but unless you take action yourself, that list is never changed. Updating the list manually works, but it’s not convenient. Automating the process is the best solution. But you can, if you want, update your mirror list by hand.

The place to start is the Arch Linux Pacman Mirrorlist Generator. Our objective is to get a list of the mirrors in your region and some from other regions for redundancy.

The Arch Linux mirror list generator web page

I’m selecting “United Kingdom” from the scrolling list and “HTTPS” and “IPV4” from the checkboxes. I’ve selected the “Use Mirror Status” checkbox, so only active mirrors are included in the results.

To see the results, click the “Generate List” button.

The matching mirrors are listed. Copy this text and paste it into your editor. Note that all lines start with a hash character “#”, meaning they are treated as comments. To activate a mirror, remove the hash from the start of its line.

A generated mirror list

You can repeat this process for other regions, pasting the results to your editor each time. I also selected mirrors in Germany and Sweden. That way, should the UK mirrors be down or inaccessible, pacman will try to use the mirrors from Sweden and Germany.

pacman reads its mirrors from a file called “/etc/pacman.d/mirrorlist.” You need to edit that file and replace its contents with the new list.

sudo gedit /etc/pacman.d/mirrorlist
Editing the mirrolist file

Replace “gedit” with your favorite editor. Copy and paste the list you’ve just created into the mirrorlist file, replacing the original contents. Save the file and close your editor.

pacman will now use our new list.

Reflector is a utility for generating mirror lists, and optionally updating the mirrorlist file. You can use it on the command line, or as a service. You can pass parameters to it to choose the regions you want to use mirrors from, and you can have the results ranked by, say, download speed.

In Arch Linux, Reflector isn’t installed by default, but in other Arch-based distributions, it might be.

Installing Reflector on Arch Linux

Installing Reflector is simple, as long as you have a working mirror list. If you don’t, pacman won’t work. If that’s the case, you’ll have to go through the steps above to manually create a working mirror list.

The pacman command is:

sudo pacman -S reflector
Installing Reflector on Arch Linux

Using Reflector on the Command Line

Using Reflector on the command line can overwrite your existing mirror list, so if you want to preserve your existing mirror list as a backup, make a copy of it before you start.

sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/old-mirrorlist
Making a copy of the mirrorlist file

This example doesn’t overwrite your mirror list.

reflector --verbose --ipv4 --protocol https --score 10 --sort rate
A mirror list generated by Reflector in a terminal window

The options we used were:

  • verbose: Give a more detailed output, where possible.
  • ipv4: Select mirrors that support the IPv4 protocol.
  • protocol: Select mirrors that support the specified protocol, such as HTTP, HTTPS, or FTP.
  • score: Select a number of mirrors that have the best scores. Each mirror gets a score, with lower scores being better than higher scores. This is calculated from connection delay times, average connection duration, and the percentage of successfully completed test connections. Note that the “10” in the command line refers to how many best-scored mirrors we want returned. It doesn’t refer to the score itself.
  • sort: Sorts the results. We have opted to sort by download rate. pacman tries the mirrors in the mirror list from top to bottom, until it finds one that is working, so it makes sense to have the fastest mirror first in the list.

Reflector supports a lot of command-line options. You won’t find them on Reflector’s man page though, you need to use its help option:

reflector --help
The Reflector help output in a terminal window

As we’ve seen, omitting the –save option lets you dry-run Reflector commands without putting your existing mirror list at risk. Let’s include the –save option so that we update our mirrorlist file. You need to use sudo when using this option.

sudo reflector --verbose --country DE,SE,GB --protocol https --sort rate --latest 20 --download-timeout 6 --save /etc/pacman.d/mirrorlist
Reflector generating a mirror list in a terminal window

Our new options are:

  • country: Select the regions we wish to include mirrors from. You can use country codes or country names.
  • latest: We want to use the 20 most recently updated mirrors.
  • download-timeout: Sets the duration in seconds before Reflector considers a repository offline.
  • save: The file the results should be written to. The default location on Arch is “/etc/pacman.d/mirrorlist.”

You can view your mirror list using the cat or less commands.

less /etc/pacman.d/mirrorlist
Using less to view the mirrorlist

Reflector writes a timestamped header, so you can see when the last update happened.

The contents of the mirrorlist file

Reflector provides a service and a timer. If you enable and start the reflector.service, it’ll update your mirror list whenever you boot your computer. The downside is slower boot times. A better solution is to enable and start the reflector.timer instead. It’ll run the reflector.service once a week for you.

sudo systemctl enable reflector.timer

sudo systemctl start reflector.timer

Enabling and starting the Reflector timer

To edit the Reflector configuration file, use your favorite editor in this command:

sudo gedit /etc/xdg/reflector/reflector.conf
Editing the Reflector configuration file

You can see that the command-line options are listed on separate lines.

The contents of the Reflector configuration file

You can change their values or add in the ones you want to use.

To edit the configuration file for the timer, use:

sudo gedit /usr/lib/systemd/system/reflector.timer
Editing the Reflector timer configuration file

Tip solutie

Permanent

Voteaza

(8 din 14 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?