Jump to content

# Ghostmirror

From ArchWiki

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Reason: Multiple minor issues to fix. (Discuss in Talk:Ghostmirror)

Related articles

- Mirrors
- Pacman
- Reflector

GhostMirror It can generate a mirrorlist from the most recent Mirrors, compare them with the local mirror, and indicate whether they are outdated, identical, or more up-to-date than the current local mirror in use.
It can perform speed tests using ping and download methods.
It can analyze a non-working mirror to identify potential issues, a feature particularly useful for mirror maintainers.
It can also function as a systemd service, automatically determining when mirrors need to be rechecked.
The main difference with Reflector is that Reflector uses the mirror list status to check the state of each mirror, particularly the lastsync, and uses ping as a measure of speed.
Ghostmirror does not consider lastsync reliable, so it downloads the mirror databases and compares them, showing the actual state of a mirror.
For speed, in addition to ping, Ghostmirror downloads packages to detect the actual speed of the mirror; the result is therefore more accurate.

## Installation

Install the ghostmirrorAUR package.

## Usage

To see all of the available options, run the following command:

    $ ghostmirror --help

### Best Mirror

If your mirrorlist already contains a good number of mirrors that you consider valid, you can skip this step.
From my experience, a good number is more than 20. Feel free to have anywhere from 1 to 100+ mirrors.
One of the first things you'll definitely want to do is search for reliable mirrors to include in your list.
To achieve this goal, you'll need several options at your disposal.
`-Po` show a progress and show a colorful table.
`-c` select country, to find good mirrors, it is recommended to search within your own country and neighboring ones.
The more mirrors you add, the slower the search might become, but this operation doesn't need to be done periodically—it's just an initial sift through the countless mirrors available.
for example Italy,Germany,France
`-l` the path where you want to save the new mirrorlist.
`-L` max numbers of output mirror in list.
`-S` sort mode, we need remove error mirror and for this add state as first sortmode, after you can add outofdate in this mode display first the mirror sync, can also add morerecent to ensure you never go out of sync, and at the end, you can add ping to try to prioritize the closest ones.

    $ ghostmirror -Po -c Italy,Germany,France -l ./mirrorlist.new -L 30 -S state,outofdate,morerecent,ping

The estimated field won't provide an optimal value without a speed test, but for finding a stable mirror, it's not necessary.
If the operation is particularly slow, you can try increasing the number of simultaneous downloads with `-d`

### Sort Mirror

Once you have a good mirrorlist, you can perform periodic checks to reorganize it and continue using the best mirrors based on your usage patterns.
Let's keep the options `-Pol` of previous command.
`-mu` set path mirrorlist and use only uncommented mirror.
`-s` apply test for mirror speed.
We need to change the sorting method. While we were previously looking for the closest mirrors, now we will focus on finding the most stable and fastest ones.

    $ ghostmirror -Po -mu ./mirrorlist.new -l ./mirrorlist.new -s light -S state,outofdate,morerecent,estimated,speed

now you can copy to apply modify to pacman

    # cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
    # cp ./mirrorlist.new /etc/pacman.d/mirrorlist

### Direct replace mirrorlist

Instead of running the command as a user, you can execute it as root to work directly on the /etc/pacman.d/mirrorlist

## Automation

The process I previously referred to as "Sort Mirror" can be automated using systemd timers, specifically, use the `linger` functionality for automation.
You won’t need to worry about anything, as linger will be automatically activated along with its configuration files—you’ll just need to run the appropriate command.

### Prepare

you need manual make dir for a new location of mirrorlist, need location where user can edit this without root privilege

    $ mkdir ~/.config/ghostmirror

inform pacman where you have stored mirrorlist.
edit file /etc/pacman.conf, search and replace this line and change <username> with your username.

    [core]
    Include = /home/<username>/.config/ghostmirror/mirrorlist

    [extra]
    Include = /home/<username>/.config/ghostmirror/mirrorlist

### Activate

create a mirrorlist in `~/.config/ghostmirror` in the same mode "Best Mirror" or simple copy from `/etc/pacman.d/mirrorlist`
The command we will run will with `-D` enable linger if it's not already enabled, create a new mirrorlist, start the timer, and use the command for subsequent automatic mirror checks.

    $ ghostmirror -DPo -mul ~/.config/ghostmirror/mirrorlist ~/.config/ghostmirror/mirrorlist -s light -S state,outofdate,morerecent,estimated,speed

By default, it uses the first element of the estimated time to determine when the service should run again.
You can choose to add a time in the format `-t hh:mm:ss`, default `00:00:00`.
If you don't want to use the estimated time but a fixed period to refresh the mirrors, you can use a fixed date with `-f`.
Before using these parameters, check if the values are correct with

    $ systemd-analyze calendar <date to check>

### systemd

can check running timer

    $ systemctl --user list-timers

force refresh mirrorlist

    $ systemctl --user start ghostmirror.service

## Analyzer

To analyze mirrors, simply add the -i option to check if the mirror redirects to another server, verify if the URLs are correct, the errors reported by the mirror, and optionally the package names that have not been synchronized.
example for exexute investigation only in specific mirrorlist

    $ ghostmirror -Pomui ./mirrorlist.mantainer all

## See also

- GitHub page

Category:

- Package management

Hidden category:

- Pages or sections flagged with Template:Style

Ghostmirror
Add topic