已复制
全屏展示
复制代码

ubuntu 离线仓库制作详解


· 3 min read

制作离线仓库的目的,是当有些Ubuntu机器不能访问外网,需要在能访问网络的机器上制作好离线仓库,然后拷贝到不能访问网络的机器上安装。

一. 工具准备

首先准备一个 ubuntu18.04.3 的 server 版操作系统,确保能正常上网,在该操作系统上进行制作离线包。apt-rdepends 命令能找出指定工具的所有依赖,包括依赖的依赖。

vim /etc/apt/sources.list

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

安装工具

apt-get update
apt-get install -y apt-rdepends dpkg-dev

二. 下载安装包及依赖

即下载待安装包及其所有依赖,制作过程使用 root 用户操作,其他的方法和前面一样,只不过下载包的方式变化了,下面是下载脚本,下面的例子是制作 ansible apache2 chrony 三个包的离线安装包。安装包被下载到了 /opt/ubuntu18.04.3-repo-data

vim ubuntu_get_depends.sh

#!/bin/bash

mkdir -p /opt/ubuntu18.04.3-repo-data
chown -R _apt /opt/ubuntu18.04.3-repo-data
cd /opt/ubuntu18.04.3-repo-data

apt-get install \
    --download-only \
    --reinstall \
    -y \
    -o Dir::Cache::Archives=/opt/ubuntu18.04.3-repo-data\
        $(apt-rdepends -f Depends,PreDepends,Recommends \
        ansible \
        | grep -v "^ " \
        | grep -Ev "python-winrm" \
        | sed 's/perlapi-5.26.0/perl-base/g' \
        | sed 's/python-cffi-backend-api-max/python-cffi-backend/g' \
        | sed 's/python-cffi-backend-api-min/python-cffi-backend/g' \
        | sed 's/perl-openssl-abi-1.1/perl-openssl-defaults/g' \
        | sed 's/libnet-perl/perl-modules-5.26/g' \
        | sed 's/debconf-2.0/debconf/g' \
        | sed 's/perlapi-5.26.1/perl-base/g' \
        )

错误1:出现类型如下的错误(is referred to by another package),使用 grep -Ev 过滤掉即可。

Package python-winrm is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'python-winrm' has no installation candidate

错误2:出现如下错误的话,使用sed替换掉为指定的即可 sed 's/perlapi-5.26.0/perl-base/g'

Note, selecting 'perl-base' instead of 'perlapi-5.26.0'

三. 制作离线安装包

# 生成 Packages 文件
cd /opt/ubuntu18.04.3-repo-data
dpkg-scanpackages -m  .  >  Packages

# 打包然后传到其他机器A
cd /opt/
tar -zcf ubuntu18.04.3-repo-data.tar.gz ubuntu18.04.3-repo-data

四. 使用离线安装包

# 机器A上解压到 /home/work/ 目录下。
tar -zxf ubuntu18.04.3-repo-data.tar.gz

# 修改 /etc/apt/sources.list 为如下内容
deb [arch=amd64 trusted=yes] file:///home/work/ubuntu18.04.3-repo-data /

# 使用
apt update
apt install lrzsz ansible apache2 chrony

# 使用apache2共享:1、将解压的目录移动到apache2默认访问目录
mv ubuntu18.04.3-repo-data /var/www/html/

# 使用apache2共享:2、在 /etc/apt/sources.list 中,也可以使用 apache2 提供的 http 服务对外发布,比如。
deb [arch=amd64 trusted=yes] http://hostname/ubuntu18.04.3-repo-data /
🔗

文章推荐