如何在没有网络访问和手动分配IP地址的计算机上使`apt-get update`工作?

我已经在一台可以访问互联网的机器上成功设置了apt-mirror并下载了最新的Ubuntu软件包。目标是在无法访问互联网的目标机器上执行apt-get update时,使用这台机器作为存储库。两台机器都已经设置了手动IP地址,并且都运行着Ubuntu 16.04操作系统。目标机器的/etc/apt/sources.list文件只有1行内容。
deb http://<local_repo_IP>/ubuntu/ xenial main restricted multiverse universe

但是当我在目标机器上执行sudo apt-get update时,我会得到以下错误:

Ign:1 http://<local_repo_IP>/ubuntu/dists/xenial main InRelease
Ign:2 http://<local_repo_IP>/ubuntu/dists/xenial main Release
Ign:3 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted amd64 Packages
Ign:4 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted i386 Packages
Ign:5 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted all Packages
Ign:6 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted Translation-en_HK
Ign:7 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted Translation-en
Ign:8 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse amd64 Packages
Ign:9 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse i386 Packages
Ign:10 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse all Packages
Ign:11 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse Translation-en_HK
Ign:12 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse Translation-en
Ign:13 http://<local_repo_IP>/ubuntu/dists/xenial main/universe amd64 Packages
Ign:14 http://<local_repo_IP>/ubuntu/dists/xenial main/universe i386 Packages
Ign:15 http://<local_repo_IP>/ubuntu/dists/xenial main/universe all Packages
Ign:16 http://<local_repo_IP>/ubuntu/dists/xenial main/universe Translation-en_HK
Ign:17 http://<local_repo_IP>/ubuntu/dists/xenial main/universe Translation-en
Ign:3 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted amd64 Packages
Ign:4 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted i386 Packages
Ign:5 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted all Packages
Ign:6 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted Translation-en_HK
Ign:7 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted Translation-en
Ign:8 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse amd64 Packages
Ign:9 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse i386 Packages
Ign:10 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse all Packages
Ign:11 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse Translation-en_HK
Ign:12 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse Translation-en
Ign:13 http://<local_repo_IP>/ubuntu/dists/xenial main/universe amd64 Packages
Ign:14 http://<local_repo_IP>/ubuntu/dists/xenial main/universe i386 Packages
Ign:15 http://<local_repo_IP>/ubuntu/dists/xenial main/universe all Packages
Ign:16 http://<local_repo_IP>/ubuntu/dists/xenial main/universe Translation-en_HK
Ign:17 http://<local_repo_IP>/ubuntu/dists/xenial main/universe Translation-en
Ign:3 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted amd64 Packages
Ign:4 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted i386 Packages
Ign:5 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted all Packages
Ign:6 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted Translation-en_HK
Ign:7 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted Translation-en
Ign:8 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse amd64 Packages
Ign:9 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse i386 Packages
Ign:10 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse all Packages
Ign:11 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse Translation-en_HK
Ign:12 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse Translation-en
Ign:13 http://<local_repo_IP>/ubuntu/dists/xenial main/universe amd64 Packages
Ign:14 http://<local_repo_IP>/ubuntu/dists/xenial main/universe i386 Packages
Ign:15 http://<local_repo_IP>/ubuntu/dists/xenial main/universe all Packages
Ign:16 http://<local_repo_IP>/ubuntu/dists/xenial main/universe Translation-en_HK
Ign:17 http://<local_repo_IP>/ubuntu/dists/xenial main/universe Translation-en
Ign:3 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted amd64 Packages
Ign:4 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted i386 Packages
Ign:5 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted all Packages
Ign:6 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted Translation-en_HK
Ign:7 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted Translation-en
Ign:8 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse amd64 Packages
Ign:9 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse i386 Packages
Ign:10 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse all Packages
Ign:11 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse Translation-en_HK
Ign:12 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse Translation-en
Ign:13 http://<local_repo_IP>/ubuntu/dists/xenial main/universe amd64 Packages
Ign:14 http://<local_repo_IP>/ubuntu/dists/xenial main/universe i386 Packages
Ign:15 http://<local_repo_IP>/ubuntu/dists/xenial main/universe all Packages
Ign:16 http://<local_repo_IP>/ubuntu/dists/xenial main/universe Translation-en_HK
Ign:17 http://<local_repo_IP>/ubuntu/dists/xenial main/universe Translation-en
Ign:3 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted amd64 Packages
Ign:4 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted i386 Packages
Ign:5 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted all Packages
Ign:6 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted Translation-en_HK
Ign:7 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted Translation-en
Ign:8 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse amd64 Packages
Ign:9 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse i386 Packages
Ign:10 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse all Packages
Ign:11 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse Translation-en_HK
Ign:12 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse Translation-en
Ign:13 http://<local_repo_IP>/ubuntu/dists/xenial main/universe amd64 Packages
Ign:14 http://<local_repo_IP>/ubuntu/dists/xenial main/universe i386 Packages
Ign:15 http://<local_repo_IP>/ubuntu/dists/xenial main/universe all Packages
Ign:16 http://<local_repo_IP>/ubuntu/dists/xenial main/universe Translation-en_HK
Ign:17 http://<local_repo_IP>/ubuntu/dists/xenial main/universe Translation-en
Err:3 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted amd64 Packages
  404  Not Found
Ign:4 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted i386 Packages
Ign:5 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted all Packages
Ign:6 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted Translation-en_HK
Ign:7 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted Translation-en
Ign:8 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse amd64 Packages
Ign:9 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse i386 Packages
Ign:10 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse all Packages
Ign:11 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse Translation-en_HK
Ign:12 http://<local_repo_IP>/ubuntu/dists/xenial main/multiverse Translation-en
Ign:13 http://<local_repo_IP>/ubuntu/dists/xenial main/universe amd64 Packages
Reading package lists... Done
W: The repository 'http://<local_repo_IP>/ubuntu/dists/xenial main Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Failed to fetch http://<local_repo_IP>/ubuntu/dists/xenial/dists/main/restricted/binary-amd64/Packages  404  Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.

在目标机器上:

/etc/resolve.conf文件包含以下内容:
# 由resolvconf(8)生成的用于glibc resolver(3)的动态resolv.conf(5)文件 # 请勿手动编辑此文件,您的更改将被覆盖 nameserver 127.0.1.1
/etc/network/interfaces文件包含以下内容:
# ifup(8)和ifdown(8)使用的interfaces(5)文件 auto lo iface lo inet loopback
此外,由于在apt-get update的输出中,唯一明确显示错误的行是Err:3 http://<local_repo_IP>/ubuntu/dists/xenial main/restricted amd64 Packages,我在目标机器上执行了以下操作来检查文件是否存在: wget http://<local_repo_IP>/ubuntu/dists/xenial/restricted/binary-amd64/Packages 我发现该文件确实存在,因为我得到了以下输出:
--2017-12-21 17:23:24--  http://<local_repo_IP>/ubuntu/dists/xenial/restricted/binary-amd64/Packages
Connecting to <local_repo_IP>:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 127112 (124K)
Saving to: ‘Packages’

Packages                100%[============================>] 124.13K  --.-KB/s    in 0s      

2017-12-21 17:23:24 (469 MB/s) - ‘Packages’ saved [127112/127112]

我还检查了一下,看看从目标机器到仓库机器是否能够成功进行ping测试。这也是可以的。
PING <local_repo_IP> (<local_repo_IP>) 56(84) bytes of data.
64 bytes from <local_repo_IP>: icmp_seq=1 ttl=64 time=0.169 ms
64 bytes from <local_repo_IP>: icmp_seq=2 ttl=64 time=0.671 ms
64 bytes from <local_repo_IP>: icmp_seq=3 ttl=64 time=0.186 ms
64 bytes from <local_repo_IP>: icmp_seq=4 ttl=64 time=0.190 ms
64 bytes from <local_repo_IP>: icmp_seq=5 ttl=64 time=0.315 ms
^C
--- <local_repo_IP> ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4047ms
rtt min/avg/max/mdev = 0.169/0.306/0.671/0.190 ms

那么,apt-get update出了什么问题?我该如何修复它并使其正常工作?

P.S. 我刚刚注意到错误信息中写着http://<local_repo_IP>/ubuntu/dists/xenial/dists/main/restricted/binary-amd64/Packages。为什么它要在main里面寻找restricted包?它不应该在http://<local_repo_IP>/ubuntu/dists/xenial/restricted/binary-amd64/Packages中查找吗?实际上,当我执行wget http://<local_repo_IP>/ubuntu/dists/xenial/dists/main/restricted/binary-amd64/Packages时,会出现以下错误:

--2017-12-21 17:26:06--  http://<local_repo_IP>/ubuntu/dists/xenial/dists/main/restricted/binary-amd64/Packages
Connecting to <local_repo_IP>:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-12-21 17:26:06 ERROR 404: Not Found.

这里发生了什么?为什么它要检查一个不存在的目录?我该如何让apt-get update指向正确的路径?
2个回答

我发现解决方法是编辑etc/apt/sources.list文件,只包含系统架构的文件: deb [arch=amd64] http://192.168.12.61/ubuntu/ xenial main restricted multiverse universe 现在当我进行更新时,不再出现任何错误。
$ sudo apt update
Hit:1 http://192.168.12.61/ubuntu xenial InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.

刚想着把这个作为一个可能的解决方案发出来,以供遇到相同问题的人参考。

7发布自己的问题答案绝对是正确的做法。代表将来会找到这个答案的人,谢谢! - Alex
1您也可以将此标记为解决方案。 - topher
4我不认为这是实际解决您问题的方法,因为您遇到错误的是一个amd64文件,而限制*为amd64*几乎不会使其消失。这是您对sources.list或其他相关配置所做的唯一更改吗?在进行此更改之前,您是否重新同步了镜像? - muru
我同意@topher的观点。你应该将这个标记为解决方案。 - rockower
@muru 是的,这是我唯一做出的更改,并且在此之后没有出现任何错误。是的,我同意你的观点,它应该不能解决问题。那么,对于为什么它起作用有什么想法吗?另外,我注意到它试图搜索的路径(在错误中)是错误的 - 它应该在 http://192.168.12.61/ubuntu/dists/xenial/restricted/binary-amd64/Packages 中搜索,但它正在搜索 http://192.168.12.61/ubuntu/dists/xenial/dists/main/restricted/binary-amd64/Packages。为什么会这样呢?指定架构是如何解决这个问题的? - Kristada673

我的看法是关于[amd-64]...假设,举个例子,在你的/etc/apt/sources.list文件中启用了谷歌浏览器的更新 deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main
你可以看到这是唯一一个带有[amd-64]的条目,并且它来自谷歌的源。
在你首次提到"deb http://192..."时,也许你的更新在到达sources.list中的chrome更新时停滞了,因为没有明确指出。
或者,查看sudo apt-cache policy,sources.list和sources.list.d
最终,我可能会冒险在自己的实验室中复制这个问题,然后再进一步回答。