all repos — birabittoh.github.io @ f09a92b0d1e07d2e76237b5d2961ecd61e501f18

My current website, built with Zola.

content/blog/reflector.md (view raw)

 1+++
 2title = "Update your mirrors!"
 3date = 2023-01-29
 4template = "blog-page.html"
 5[taxonomies]
 6tags = [ "advice", "foss" ]
 7+++
 8
 9Nah, 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.
10
11## Suspicion
12I 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.
13
14Another 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.
15
16## Problem
17
18At 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.
19
20I 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.
21
22Pacman's mirrorlist is located in `/etc/pacman.d/mirrorlist`. You can filter out uncommented lines with this command:
23
24```
25grep -v "^#" /etc/pacman.d/mirrorlist
26```
27
28And check the actual status of your mirror(s) on the Mirror Status page linked above.
29
30## Solution
31
32This will overwrite your mirrorlist, so you're advised to make a backup before proceeding:
33
34```
35sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
36```
37
38I 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.
39
40First, install it.
41
42```
43sudo pacman -S reflector
44```
45
46Then, 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`.
47
48```
49--save /etc/pacman.d/mirrorlist
50--protocol https
51--country Italy,Switzerland,France,Germany,Austria
52--latest 5
53--sort age
54```
55
56Finally, start the service and check if it worked.
57```
58sudo systemctl start reflector.service
59cat /etc/pacman.d/mirrorlist
60```
61
62If everything went smoothly, enable reflector's timer so it runs weekly.
63```
64sudo systemctl enable reflector.timer
65```
66
67Done!
68
69Now, 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 uncommenting and setting `NoExtract` in `/etc/pacman.conf`:
70
71```
72...
73NoExtract = /etc/pacman.d/mirrorlist
74
75# Misc options
76Color
77ILoveCandy
78ParallelDownloads = 3
79...
80```