all repos — website-hugo @ f0aceb8e1d09e9426fd8ccfbe58ebdde8b17a725

My personal blog, built with Hugo!

content/articles/reflector.md (view raw)

 1---
 2title: "Update your mirrors!"
 3date: 2023-01-29T12:48:40+01:00
 4tags: [foss,advice]
 5---
 6
 7Nah, I'm not talking about [bluetooth mirrors](https://www.bathshack.com/blog/bluetooth-mirrors-everything-you-need-to-know-before-you-buy/). Mirrors are what powers all distros: they're a (de)centralized solution for downloading pre-compiled binaries and scripts for your operating system.
 8
 9## Suspicion
10I like always having the most current version of packages, so I usually update my system several times a day. When, after a day, I ran `sudo pacman -Syu` and it reported the system being up to date, I was pretty weirded out.
11
12Another day passed, and the system was still up to date. It was not a connection problem, I was connecting to my mirrors and they were reporting absolutely zero updates for my system.
13
14## Problem
15
16At the third day of stagnation, I was sure something was up. I looked up the [Mirror Status](https://archlinux.org/mirrors/status/) page on ArchLinux's website and saw that loads of mirrors were out of sync.
17
18I had never touched my mirrorlist before, it was just generated by the  [archinstall](https://github.com/archlinux/archinstall) script a few months ago; a lot of Arch-based distros by default ship tools to update your mirrorlist, but I honestly thought I'd never need that.
19
20Pacman's mirrorlist is located in `/etc/pacman.d/mirrorlist`. You can filter out uncommented lines with this command:
21
22```
23grep -v "^#" /etc/pacman.d/mirrorlist
24```
25
26And check the actual status of your mirror(s) on the Mirror Status page linked above.
27
28## Solution
29
30This will overwrite your mirrorlist, so you're advised to make a backup before proceeding:
31
32```
33sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
34```
35
36I decided to use [reflector](https://xyne.dev/projects/reflector/) to fix this problem. I didn't want to have to deal with this again, so I enabled the provided systemd timer.
37
38First, install it.
39
40```
41sudo pacman -S reflector
42```
43
44Then, edit `/etc/xdg/reflector/reflector.conf`. I only needed to edit the `--country` parameter and select countries next to the one where I reside; you can list available countries by running `reflector --list-countries`.
45
46```
47--save /etc/pacman.d/mirrorlist
48--protocol https
49--country Italy,Switzerland,France,Germany,Austria
50--latest 5
51--sort age
52```
53
54Finally, start the service and check if it worked.
55```
56sudo systemctl start reflector.service
57cat /etc/pacman.d/mirrorlist
58```
59
60If everything went smoothly, enable reflector's timer so it runs weekly.
61```
62sudo systemctl enable reflector.timer
63```
64
65Done!
66
67Now, by default pacman _does_ update its mirrorlist. It creates a file called `mirrorlist.pacnew` and it expects you to pick your favorite mirrors each time its generated. You can disable this (now unneeded) behavior by adding `NoExtract` under "# Misc options" in `/etc/pacman.conf`:
68
69```
70# Misc options
71NoExtract
72Color
73ILoveCandy
74CheckSpace
75ParallelDownloads = 3
76```