Reflector
Reflector is a script which can retrieve the latest mirror list from the MirrorStatus page, filter the most up-to-date mirrors, sort them by speed and overwrite the file /etc/pacman.d/mirrorlist
.
Contents
Installation
Install reflector from the official repositories.
Usage
To see all of the available commands, run the following command:
# reflector --help
Examples
Example 1
The following command will filter the first five mirrors, sort them by speed and overwrite the file /etc/pacman.d/mirrorlist
:
# reflector --verbose -l 5 --sort rate --save /etc/pacman.d/mirrorlist
Example 2
The following command will verbosely rate the 200 most recently synchronized HTTP servers, sort them by download rate, and overwrite the file /etc/pacman.d/mirrorlist
:
# reflector --verbose -l 200 -p http --sort rate --save /etc/pacman.d/mirrorlist
Example 3
This command will verbosely rate the 200 most recently synchronized HTTP servers located in the US, sort them by download rate speed, and overwrite the file /etc/pacman.d/mirrorlist
:
# reflector --verbose --country 'United States' -l 200 -p http --sort rate --save /etc/pacman.d/mirrorlist
Example 4
Make an automated script, run the script each time you want to refresh your mirrors. Using example 2 from above in this script;
cd /usr/local/bin vim reflect_mirrors
Add the following content to the script
#!/bin/bash
#This will run reflector on mirrorlist, copying from backup first, overwriting
wget -O /etc/pacman.d/mirrorlist.backup https://www.archlinux.org/mirrorlist/all/ && cp /etc/pacman.d/mirrorlist.backup /etc/pacman.d/mirrorlist && reflector --verbose -l 200 -p http --sort rate --save /etc/pacman.d/mirrorlist
Save and exit vim
Now set the proper permissions on the script.
chown root:users reflect_mirrors chmod ug+wx reflect_mirrors
Run the script everytime you want to refresh your mirror list
./reflect_mirrors
Systemd Service
/etc/systemd/system/reflector.service
[Unit] Description=Pacman mirrorlist update [Service] Type=oneshot ExecStart=/usr/bin/reflector --protocol http --latest 30 --number 20 --sort rate --save /etc/pacman.d/mirrorlist
Then # systemctl start reflector
will update your mirrorlist.
To update your mirrorlist every time your computer boots you can enable the following service definition.
/etc/systemd/system/reflector.service
[Unit] Description=Pacman mirrorlist update Requires=network.target After=network.target [Service] Type=oneshot ExecStart=/usr/bin/reflector --protocol http --latest 30 --number 20 --sort rate --save /etc/pacman.d/mirrorlist [Install] RequiredBy=network.target
Make sure you activate the appropriate services so that network.target
really reflects your network status.
Systemd Timer
If you want to run reflector.service
on a weekly basis:
/etc/systemd/system/reflector.timer
[Unit] Description=Run reflector weekly [Timer] OnCalendar=weekly AccuracySec=12h Persistent=true [Install] WantedBy=timers.target
And then just start the timer:
# systemctl enable reflector.timer