当在计算机上安装Ubuntu时,通常会通过安装ISO来引导,然后在众多选项中选择自己的地理位置。所以,这就意味着你可以连接到离你所在位置最近的镜像以便实时更新。
但是对于我们在Arm SBD’s 烧录Ubuntu镜像的人来说,镜像通常是由开发者设计的,无论是中国还是斯洛伐克,或者是默认的美国镜像,它虽然是可以工作的,但是速度可能比较慢。
但其实,在现在的计算机中是可以改变这种情况的。我发现一种将其从 Ubuntu 桌面更改为启动软件和更新程序并将下载字段更改为你所在国家/地区或邻国镜像的简单方法,具体如下所示。
一般来说,我自己主要是通过ssh连接到板子上因为这样进行评测很方便。更改镜像的其中一种方法是通过编辑/etc/apt/sources.list 文件。但是今天我认为应该有更好的解决方案。
因为,我通过 AskUbuntu发现了一个带有apt-mirror-updater的工具。
我在运行 NanoPi M4V2 SBC 的 FriendlyCore Desktop 中对其进行了测试。以下是固件中默认sources.list的内容:
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 |
我运行apt-update命令,它以125kb/s的速度运行,速度着实有点慢。
1 |
86% [56 Contents-arm64 15.6 MB/39.9 MB 39%] 125 kB/s 3min 31s |
运行apt-update 耗时了25分钟, 接着我用pip安装了apt-mirror-updated:
1 |
sudo pip3 install apt-mirror-updater |
然后运行以下命令将自动将镜像更改为最佳镜像:
1 |
sudo apt-mirror-updater --auto-change-mirror |
输出的时间相当长,因为它测试了多个服务器,然后才运行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] .... |
尽管我的总部设在泰国,但是它选择的镜像是卢森堡的,但是这个的升级要快很多,只有一个小问题有404的错误。
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. |
然而,它在失败之后也不会停止,而是使用了同一个镜像重试 10 次,直到几分钟后才失败的。
所以我尝试了另一种方法,使用该工具对 50 个镜像的下载速度进行了排名:
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 | -------------------------------------------------------------------------------------------------------------------------------- |
我的 Ubuntu 笔记本电脑是配置了“http://th.archive.ubuntu.com/ubuntu/”的,但不知什么原因上面没有列出来。 这部分是因为该实用程序只会测试前 50 个镜像,如果我们想测试所有镜像(一共 411 个),我们需要运行以下命令,这需要 1 分 30 秒才能完成:
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 | ... |
我截断了结果,但不知道为什么还是没有泰国镜像可以选择。
理论上,你应该从上面的列表中选择第一台服务器。但最终我还是决定使用与笔记本电脑上相同的服务器:
1 |
sudo apt-mirror-updater -c http://th.archive.ubuntu.com/ubuntu/ |
还是有与 404 错误相同的问题,结果证明大多数镜像仅托管 x86 或 x86_64,而不是 arm64 或 armhf。有人写了一个脚本来帮助找到用户所追求的架构和 Ubuntu 版本的镜像,具体如下:
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 |
我将其保存为find-mirrors.sh,并更改了权限:
1 |
chmod +x find-mirrors.sh |
在运行命令以查找服务器镜像 arm64 仿生包部分主存储库之前:
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:~# |
那只是数百个服务器中的 9 个 arm64 镜像。但是脚本或某些服务器的返回码肯定存在一些问题,因为只有http://ftp.tu-chemnitz.de/pub/linux/ubuntu-ports/是真正包含dists/bionic/main/binary-arm64目录的。
所以我使用了以下命令手动设置镜像:
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. |
运行 apt update 所需的时间不到 8 分钟。
通过上述的评测,我得出的结论是 apt-mirror-updater 在 32 位 / 64 位 x86 平台上可以运行得很好,但它不适合 Arm SBC,因为几乎没有镜像托管 arm64 或 armhf 文件。我切换到德国的服务器之后,情况有所改善,但显然这还是取决于你的位置,我想获得快速 apt 镜像的唯一可靠方法是在本地找到你自己的镜像。
文章翻译者:Nicholas,技术支持工程师、瑞科慧联(RAK)高级工程师,深耕嵌入式开发技术、物联网行业多年,拥有丰富的行业经验和新颖独到的眼光!