When you install Ubuntu on a computer, you’d normally go through the installation ISO which guides you through a wizard where you select your location among other things, and that means you get connected to the mirror closest to your location allowing timely updates.
But for those of us who flash Ubuntu images on Arm SBC’s, the mirror is normally fixed to the one set by the developer be it in China or Slovakia, or defaults to the US mirror. It still works, but it can be slower than necessary.
In a computer, an easy way to change that from Ubuntu desktop to launch Software & Update program and change the download from field to a mirror in your country or neighboring country as shown below.
But I’ve found myself mostly connecting to boards over SSH since it’s easier that way for reviews. One way to change the mirror would be to edit /etc/apt/sources.list manually, or just not bother, but today I thought there must be a better solution.
And indeed there appears to be one with apt-mirror-updater which I discovered through AskUbuntu.
I tested it in FriendlyCore Desktop running in NanoPi M4V2 SBC. Here’s the content of the default sources.list in the firmware:
1 2 3 4 5 6 7 8 9 10 |
deb http://ports.ubuntu.com/ bionic main multiverse restricted universe deb http://ports.ubuntu.com/ bionic-backports main multiverse restricted universe deb http://ports.ubuntu.com/ bionic-proposed main multiverse restricted universe deb http://ports.ubuntu.com/ bionic-security main multiverse restricted universe deb http://ports.ubuntu.com/ bionic-updates main multiverse restricted universe deb-src http://ports.ubuntu.com/ bionic main multiverse restricted universe deb-src http://ports.ubuntu.com/ bionic-backports main multiverse restricted universe deb-src http://ports.ubuntu.com/ bionic-proposed main multiverse restricted universe deb-src http://ports.ubuntu.com/ bionic-security main multiverse restricted universe deb-src http://ports.ubuntu.com/ bionic-updates main multiverse restricted universe |
I ran apt-update command and it was fairly slow at 125 KB/s:
1 |
86% [56 Contents-arm64 15.6 MB/39.9 MB 39%] 125 kB/s 3min 31s |
Running apt-update took over 25 minutes. So I installed apt-mirror-updated with pip3:
1 |
sudo pip3 install apt-mirror-updater |
Then ran the following command to automatically change the mirror to the best one:
1 |
sudo apt-mirror-updater --auto-change-mirror |
The output is fairly long since it tests several servers, and then runs apt-update:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
sudo apt-mirror-updater --auto-change-mirror 2019-10-26 07:49:58 NanoPi-M4v2 apt_mirror_updater[3590] INFO Changing mirror of local system (NanoPi-M4v2) to best available mirror .. 2019-10-26 07:49:58 NanoPi-M4v2 apt_mirror_updater.backends.ubuntu[3590] INFO Discovering Ubuntu mirrors at https://launchpad.net/ubuntu/+archivemirrors .. 2019-10-26 07:50:04 NanoPi-M4v2 apt_mirror_updater.backends.ubuntu[3590] INFO Identifying fast Ubuntu mirrors using http://mirrors.ubuntu.com/mirrors.txt .. 2019-10-26 07:50:05 NanoPi-M4v2 apt_mirror_updater.backends.ubuntu[3590] INFO Discovered 411 Ubuntu mirrors in 6.33 seconds. 2019-10-26 07:50:05 NanoPi-M4v2 apt_mirror_updater[3590] INFO Checking 50 mirrors for availability and performance .. 2019-10-26 07:50:20 NanoPi-M4v2 apt_mirror_updater[3590] INFO Checking 46 mirrors for Archive-Update-in-Progress marker .. 2019-10-26 07:50:31 NanoPi-M4v2 apt_mirror_updater[3590] INFO Finished checking 50 mirrors (took 32.64 seconds). 2019-10-26 07:50:31 NanoPi-M4v2 apt_mirror_updater[3590] INFO Selected mirror: http://ubuntu.mirror.root.lu/ubuntu 2019-10-26 07:50:31 NanoPi-M4v2 apt_mirror_updater[3590] INFO Installing new /etc/apt/sources.list .. 2019-10-26 07:50:31 NanoPi-M4v2 apt_mirror_updater[3590] INFO Backing up contents of /etc/apt/sources.list to /etc/apt/sources.list.save.1572076231 .. 2019-10-26 07:50:31 NanoPi-M4v2 apt_mirror_updater[3590] INFO Clearing package list cache of local system (NanoPi-M4v2) .. 2019-10-26 07:50:31 NanoPi-M4v2 apt_mirror_updater[3590] INFO Successfully cleared package list cache of local system (NanoPi-M4v2) in 0.19 seconds. 2019-10-26 07:50:31 NanoPi-M4v2 apt_mirror_updater[3590] INFO Updating package lists of local system (NanoPi-M4v2) .. Get:1 http://ubuntu.mirror.root.lu/ubuntu bionic InRelease [242 kB] Get:2 http://ubuntu.mirror.root.lu/ubuntu bionic-backports InRelease [74.6 kB] Get:3 http://ubuntu.mirror.root.lu/ubuntu bionic-proposed InRelease [242 kB] Get:4 http://ubuntu.mirror.root.lu/ubuntu bionic-security InRelease [88.7 kB] Get:5 http://ubuntu.mirror.root.lu/ubuntu bionic-updates InRelease [88.7 kB] Get:6 http://ubuntu.mirror.root.lu/ubuntu bionic/main Sources [829 kB] .... |
Although I’m based in Thailand, it selected a mirror in Luxembourg, but the updates were nevertheless much faster. Just a small problem though with 404 error:
1 2 3 4 5 6 |
E: Failed to fetch http://ubuntu.mirror.root.lu/ubuntu/dists/bionic/main/binary-arm64/Packages 404 Not Found [IP: 94.242.192.42 80] E: Failed to fetch http://ubuntu.mirror.root.lu/ubuntu/dists/bionic-backports/main/binary-arm64/Packages 404 Not Found [IP: 94.242.192.42 80] E: Failed to fetch http://ubuntu.mirror.root.lu/ubuntu/dists/bionic-proposed/main/binary-arm64/Packages 404 Not Found [IP: 94.242.192.42 80] E: Failed to fetch http://ubuntu.mirror.root.lu/ubuntu/dists/bionic-security/main/binary-arm64/Packages 404 Not Found [IP: 94.242.192.42 80] E: Failed to fetch http://ubuntu.mirror.root.lu/ubuntu/dists/bionic-updates/main/binary-armhf/Packages 404 Not Found [IP: 94.242.192.42 80] E: Some index files failed to download. They have been ignored, or old ones used instead. |
It does not stop after failure however, and instead retries with the same mirror 10 times until failing several minutes later.
So I tried another method using the tool to rank 50 mirrors with their download speed:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
apt-mirror-updater --list-mirrors 2019-10-26 07:57:20 NanoPi-M4v2 apt_mirror_updater.backends.ubuntu[5273] INFO Discovering Ubuntu mirrors at https://launchpad.net/ubuntu/+archivemirrors .. 2019-10-26 07:57:26 NanoPi-M4v2 apt_mirror_updater.backends.ubuntu[5273] INFO Identifying fast Ubuntu mirrors using http://mirrors.ubuntu.com/mirrors.txt .. 2019-10-26 07:57:27 NanoPi-M4v2 apt_mirror_updater.backends.ubuntu[5273] INFO Discovered 411 Ubuntu mirrors in 6.69 seconds. 2019-10-26 07:57:27 NanoPi-M4v2 apt_mirror_updater[5273] INFO Checking 50 mirrors for availability and performance .. 2019-10-26 07:57:38 NanoPi-M4v2 apt_mirror_updater[5273] INFO Checking 48 mirrors for Archive-Update-in-Progress marker .. 2019-10-26 07:57:50 NanoPi-M4v2 apt_mirror_updater[5273] INFO Finished checking 50 mirrors (took 30.03 seconds). -------------------------------------------------------------------------------------------------------------------------------- | Rank | Mirror URL | Available? | Updating? | Last updated | Bandwidth | -------------------------------------------------------------------------------------------------------------------------------- | 1 | http://download.nus.edu.sg/mirror/ubuntu | Yes | No | Up to date | 3.98 KB/s | | 2 | http://kr.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 2.64 KB/s | | 3 | http://fr.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 2.39 KB/s | | 4 | http://mirror2.tuxinator.org/ubuntu | Yes | No | Up to date | 2.34 KB/s | | 5 | http://ubuntu.mirror.root.lu/ubuntu | Yes | No | Up to date | 2.27 KB/s | | 6 | http://mirror.transip.net/ubuntu/ubuntu | Yes | No | Up to date | 2.1 KB/s | | 7 | http://mirror.sov.uk.goscomb.net/ubuntu | Yes | No | Up to date | 2.08 KB/s | | 8 | http://mirror.bytemark.co.uk/ubuntu | Yes | No | Up to date | 2.05 KB/s | | 9 | http://ubuntu.mirror.lrz.de/ubuntu | Yes | No | Up to date | 2.04 KB/s | | 10 | http://ftp.lanet.kr/ubuntu | Yes | No | Up to date | 2 KB/s | | 11 | http://mirror.niif.hu/ubuntu | Yes | No | Up to date | 1.95 KB/s | | 12 | http://ubuntutym.u-toyama.ac.jp/ubuntu | Yes | No | Up to date | 1.89 KB/s | | 13 | http://ftp.vectranet.pl/ubuntu | Yes | No | Up to date | 1.88 KB/s | | 14 | http://mirror.nl.leaseweb.net/ubuntu | Yes | No | Up to date | 1.86 KB/s | | 15 | http://cz.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 1.84 KB/s | | 16 | http://mirror.easyspeedy.com/ubuntu | Yes | No | Up to date | 1.81 KB/s | | 17 | http://ftp.sh.cvut.cz/ubuntu | Yes | No | Up to date | 1.7 KB/s | | 18 | http://mirror.i3d.net/pub/ubuntu | Yes | No | Up to date | 1.57 KB/s | | 19 | http://ftp.harukasan.org/ubuntu | Yes | No | Up to date | 1.48 KB/s | | 20 | http://mirror.tocici.com/ubuntu | Yes | No | Up to date | 1.35 KB/s | | 21 | http://ubuntu.mirror.true.nl/ubuntu | Yes | No | Up to date | 1.32 KB/s | | 22 | http://aze.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 1.31 KB/s | | 23 | http://mirrors.dotsrc.org/ubuntu | Yes | No | Up to date | 1.28 KB/s | | 24 | http://mirrors.vcea.wsu.edu/ubuntu | Yes | No | Up to date | 1.27 KB/s | | 25 | http://ubuntu.cybertips.info/ubuntu | Yes | No | Up to date | 1.2 KB/s | | 26 | http://hr.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 1.19 KB/s | | 27 | http://mirror.nodesdirect.com/ubuntu | Yes | No | Up to date | 1.08 KB/s | | 28 | http://mirrors.bloomu.edu/ubuntu | Yes | No | Up to date | 1.03 KB/s | | 29 | http://ftp.iinet.net.au/pub/ubuntu | Yes | No | Up to date | 1.03 KB/s | | 30 | http://mirror.hoster.kz/ubuntu | Yes | No | Up to date | 1.03 KB/s | | 31 | http://ftp.estpak.ee/ubuntu | Yes | No | Up to date | 1 KB/s | | 32 | http://muug.ca/mirror/ubuntu | Yes | No | Up to date | 995.11 bytes/s | | 33 | http://www.mirrorservice.org/sites/archive.ubuntu.com/ubuntu | Yes | No | Up to date | 980.85 bytes/s | | 34 | http://ftp.uni-stuttgart.de/ubuntu | Yes | No | Up to date | 882.9 bytes/s | | 35 | http://repo.miserver.it.umich.edu/ubuntu | Yes | No | Up to date | 781.71 bytes/s | | 36 | http://mirrors.coreix.net/ubuntu | Yes | No | Up to date | 729.93 bytes/s | | 37 | http://pf.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 650.27 bytes/s | | 38 | http://mirror.cs.jmu.edu/pub/ubuntu | Yes | No | Up to date | 602.44 bytes/s | | 39 | http://mirror.lcsee.wvu.edu/ubuntu | Yes | No | Up to date | 587.97 bytes/s | | 40 | http://mirror.docker.ru/ubuntu | Yes | No | Up to date | 538.2 bytes/s | | 41 | http://archive.ubuntu.nautile.nc/ubuntu | Yes | No | Up to date | 528.24 bytes/s | | 42 | http://mirrors.cqu.edu.cn/ubuntu | Yes | No | Up to date | 526.18 bytes/s | | 43 | http://mirror.sax.uk.as61049.net/ubuntu | Yes | No | Up to date | 484.33 bytes/s | | 44 | http://ucmirror.canterbury.ac.nz/ubuntu | Yes | No | Up to date | 457.7 bytes/s | | 45 | http://mirror.muvhost.com/ubuntu | Yes | No | Up to date | 378.4 bytes/s | | 46 | http://download.nust.na/pub/ubuntu/ubuntu | Yes | No | Up to date | 312.37 bytes/s | | 47 | http://giano.com.dist.unige.it/ubuntu | Yes | Yes | Up to date | 1.18 KB/s | | 48 | http://mirror.csclub.uwaterloo.ca/ubuntu | Yes | Yes | Up to date | 943.4 bytes/s | | 49 | http://mirror.wff-gaming.de/ubuntu | No | No | Up to date | Unknown | | 50 | http://ubuntu.saglayici.com/ubuntu | No | No | Up to date | Unknown | -------------------------------------------------------------------------------------------------------------------------------- |
My Ubuntu laptop is configured with “http://th.archive.ubuntu.com/ubuntu/”, but somehow it’s not listed above. That’s partially because the utility will only test the first 50 mirrors, if we want to test all mirrors (411 of them) we need to run the following command instead which took one minute and 30 seconds to complete:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
apt-mirror-updater -m 0 --list-mirrors 2019-10-26 09:06:29 NanoPi-M4v2 apt_mirror_updater.backends.ubuntu[11248] INFO Discovering Ubuntu mirrors at https://launchpad.net/ubuntu/+archivemirrors .. 2019-10-26 09:06:32 NanoPi-M4v2 apt_mirror_updater.backends.ubuntu[11248] INFO Identifying fast Ubuntu mirrors using http://mirrors.ubuntu.com/mirrors.txt .. 2019-10-26 09:06:32 NanoPi-M4v2 apt_mirror_updater.backends.ubuntu[11248] INFO Discovered 411 Ubuntu mirrors in 3.46 seconds. 2019-10-26 09:06:33 NanoPi-M4v2 apt_mirror_updater[11248] INFO Checking 412 mirrors for availability and performance .. 2019-10-26 09:07:30 NanoPi-M4v2 apt_mirror_updater[11248] INFO Checking 385 mirrors for Archive-Update-in-Progress marker .. 2019-10-26 09:08:02 NanoPi-M4v2 apt_mirror_updater[11248] INFO Finished checking 412 mirrors (took 1 minute and 33.34 seconds). ---------------------------------------------------------------------------------------------------------------------------------- | Rank | Mirror URL | Available? | Updating? | Last updated | Bandwidth | ---------------------------------------------------------------------------------------------------------------------------------- | 1 | http://download.nus.edu.sg/mirror/ubuntu | Yes | No | Up to date | 7.31 KB/s | | 2 | http://ubuntutym.u-toyama.ac.jp/ubuntu | Yes | No | Up to date | 3.65 KB/s | | 3 | http://mirror.cse.iitk.ac.in/ubuntu | Yes | No | Up to date | 2.73 KB/s | | 4 | http://fr.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 2.5 KB/s | | 5 | http://ubuntu.mirror.root.lu/ubuntu | Yes | No | Up to date | 2.28 KB/s | | 6 | http://aze.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 2.27 KB/s | | 7 | http://mirror.transip.net/ubuntu/ubuntu | Yes | No | Up to date | 2.26 KB/s | | 8 | http://mirror.i3d.net/pub/ubuntu | Yes | No | Up to date | 2.25 KB/s | | 9 | http://mirror.tocici.com/ubuntu | Yes | No | Up to date | 2.12 KB/s | |10 | http://ftp.lanet.kr/ubuntu | Yes | No | Up to date | 2.1 KB/s | ... |
I truncated the results, but somehow there’s still no Thai mirror.
In theory, you’d select the first server from the list above, namely, but instead I decided to use the same server as on my laptop:
1 |
sudo apt-mirror-updater -c http://th.archive.ubuntu.com/ubuntu/ |
Same problems with 404 errors, and it turns out most mirrors only host x86 or x86_64, and not arm64 nor armhf. Somebody wrote a script to help people find the mirrors with the architecture and Ubuntu version you are after:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#!/bin/bash # URL of the Launchpad mirror list MIRROR_LIST=https://launchpad.net/ubuntu/+archivemirrors # Set to the architecture you're looking for (e.g., amd64, i386, arm64, armhf, armel, powerpc, ...). # See https://wiki.ubuntu.com/UbuntuDevelopment/PackageArchive#Architectures ARCH=$1 # Set to the Ubuntu distribution you need (e.g., precise, saucy, trusty, ...) # See https://wiki.ubuntu.com/DevelopmentCodeNames DIST=$2 # Set to the repository you're looking for (main, restricted, universe, multiverse) # See https://help.ubuntu.com/community/Repositories/Ubuntu REPO=$3 # First, we retrieve the Launchpad mirror list, and massage it to obtain a newline-separated list of HTTP mirrors for url in $(curl -s $MIRROR_LIST | grep -Po 'http://.*(?=">http</a>)'); do # If you like some output while the script is running (feel free to comment out the following line) echo "Processing $url..." # retrieve the header for the URL $url/dists/$DIST/$REPO/binary-$ARCH/; check if status code is of the form 2.. or 3.. curl -s --head $url/dists/$DIST/$REPO/binary-$ARCH/ | head -n 1 | grep -q "HTTP/1.[01] [23].." # if successful, output the URL [ $? -eq "0" ] && echo "FOUND: $url" done |
I saved it as find-mirrors.sh, and changed the permissions:
1 |
chmod +x find-mirrors.sh |
before running the command to find server mirroring arm64 Bionic packages part the main repository:
1 2 3 4 5 6 7 8 9 10 11 |
./find-mirrors.sh arm64 bionic main | grep FOUND FOUND: http://mirror.exid.us/ubuntu-archive/ FOUND: http://mirror.ubuntu.ikoula.com/ubuntu/ FOUND: http://ftp.tu-chemnitz.de/pub/linux/ubuntu-ports/ FOUND: http://mirror.onet.pl/pub/mirrors/ubuntu/ FOUND: http://mirrors.coreix.net/ubuntu/ FOUND: http://mirrors.us.kernel.org/ubuntu/ FOUND: http://lug.mtu.edu/ubuntu/ FOUND: http://mirror.lcsee.wvu.edu/ubuntu/ FOUND: http://mirror.vcu.edu/pub/gnu+linux/ubuntu/ root@NanoPi-M4v2:~# |
That’s only 9 arm64 mirrors out of hundreds of servers. But there must be some issues with the script or the return code from some servers, as only http://ftp.tu-chemnitz.de/pub/linux/ubuntu-ports/ really contains dists/bionic/main/binary-arm64 directory.
So I manually set the mirror with the command:
1 2 3 4 5 6 7 8 9 |
apt-mirror-updater -c http://ftp.tu-chemnitz.de/pub/linux/ubuntu-ports 2019-10-27 05:25:44 NanoPi-M4v2 apt_mirror_updater[6312] INFO Changing mirror of local system (NanoPi-M4v2) to http://ftp.tu-chemnitz.de/pub/linux/ubuntu-ports .. 2019-10-27 05:25:45 NanoPi-M4v2 apt_mirror_updater[6312] INFO Installing new /etc/apt/sources.list .. ... Get:85 http://ftp.tu-chemnitz.de/pub/linux/ubuntu-ports bionic-updates/universe Translation-en [313 kB] Fetched 266 MB in 7min 50s (567 kB/s) Reading package lists... Done 2019-10-27 05:33:39 NanoPi-M4v2 apt_mirror_updater[6312] INFO Finished updating package lists of local system (NanoPi-M4v2) in 7 minutes and 54.34 seconds. 2019-10-27 05:33:39 NanoPi-M4v2 apt_mirror_updater[6312] INFO Finished changing mirror of local system (NanoPi-M4v2) in 7 minutes and 55.09 seconds. |
It took less than 8 minutes mostly to run apt update.
The conclusion is that apt-mirror-updater should work great on 32-bit / 64-bit x86 platforms, but it’s not suitable for Arm SBC’s since there are virtually no mirrors hosting arm64 or armhf files. The switch to the German server improved things a bit more me, but obviously it would depend on your location, and the only reliable to get a fast apt mirror would be to roll your own locally.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress
Part of the problem is that arm64 and other architectures are usually mirrored separately: for example, mirrors.mit.edu/ubuntu/ vs mirrors.mit.edu/ubuntu-ports/ And that script pulls a mirror list from Launchpad that doesn’t include, for example, the ubuntu-ports mirror for mit.edu, only the regular ubuntu mirror. So finding and discovering arm64 or other ports architechture mirrors is even harder. The script above also gives false positives for servers that don’t respond with an HTTP error code, and several do not for various reasons. A modification that isn’t perfect but will find some more actual mirrors is to add this line in the for… Read more »