Changing Ubuntu Apt Mirror from the Command Line, and the Lack of Arm64 Mirrors

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:


I ran apt-update command and it was fairly slow at 125 KB/s:


Running apt-update took over 25 minutes. So I installed apt-mirror-updated with pip3:


Then ran the following command to automatically change the mirror to the best one:


The output is fairly long since it tests several servers, and then runs apt-update:


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:


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:


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:


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:


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:


I saved it as find-mirrors.sh, and changed the permissions:


before running the command to find server mirroring arm64 Bionic packages part the main repository:


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:


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.

Support CNX Software - Donate via PayPal or become a Patron on Patreon
Subscribe
Notify of
guest
1 Comment
oldest
newest most voted
adampiontek
3 months ago

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 »

Advertisements