Ubuntu20.10でapt-mirrorに失敗する為debmirrorを使うことにする

Dockerを使ってdebmirrorを構築します。

#ミラーサーバの構築
##Dockerのインストール

```
sudo apt update
sudo apt install docker.io -y
sudo apt install docker-compose -y
```

##githubから取得
↓こちらのdockerfileを利用させてもらいました。
https://github.com/flavienbwk/debmirror

```
git clone https://github.com/flavienbwk/debmirror.git 
cd debmirror
```

##mirrorbuild.shを変更
Ubuntu20.10の日本語環境に動作する設定に変更します。
変更箇所は４箇所

```
#arch=i386,amd64　→　arch=i386,amd64
arch=amd64 →　#arch=amd64

release=bionic,bionic-security,bionic-updates,bionic-backports
↓
release=focal,focal-security,focal-updates,focal-backports

debmirrorの引数に--i18n を追加
```

変更後のファイル

```
#### Start script to automate building of Ubuntu mirror #####
## THE NEXT LINE IS NEEDED THE REST OF THE LINES STARTING WITH A # CAN BE DELETED

#!/bin/bash

## Setting variables with explanations.

#
# Don't touch the user's keyring, have our own instead
#
export GNUPGHOME=/mirrorkeyring

# Arch=         -a      # Architecture. For Ubuntu can be i386, powerpc or amd64.
# sparc, only starts in dapper, it is only the later models of sparc.
#
arch=i386,amd64
#arch=amd64

# Minimum Ubuntu system requires main, restricted
# Section=      -s      # Section (One of the following - main/restricted/universe/multiverse).
# You can add extra file with $Section/debian-installer. ex: main/debian-installer,universe/debian-installer,multiverse/debian-installer,restricted/debian-installer
#
section=main,restricted,universe,multiverse

# Release=      -d      # Release of the system (...Hardy, Intrepid... Lucid, Precise, Quantal, Saucy, Trusty ), and the -updates and -security ( -backports can be added if desired)
# List of updated releases in: https://wiki.ubuntu.com/Releases
#

release=focal,focal-security,focal-updates,focal-backports

# Server=       -h      # Server name, minus the protocol and the path at the end
# CHANGE "*" to equal the mirror you want to create your mirror from. au. in Australia  ca. in Canada.
# This can be found in your own /etc/apt/sources.list file, assuming you have Ubuntu installed.
#
server=archive.ubuntu.com

# Dir=          -r      # Path from the main server, so http://my.web.server/$dir, Server dependant
#
inPath=/ubuntu

# Proto=        --method=       # Protocol to use for transfer (http, ftp, hftp, rsync)
# Choose one - http is most usual the service, and the service must be available on the server you point at.
#
proto=http

# Outpath=              # Directory to store the mirror in
# Make this a full path to where you want to mirror the material.
#
outPath=/mirror/mirror/$server/ubuntu

# The --nosource option only downloads debs and not deb-src's
# The --progress option shows files as they are downloaded
# --source \ in the place of --no-source \ if you want sources also.
# --nocleanup  Do not clean up the local mirror after mirroring is complete. Use this option to keep older repository
# Start script
#
debmirror       -a $arch \
                --no-source \
                -s $section \
                -h $server \
                -d $release \
                -r $inPath \
                --progress \
                --method=$proto \
                --i18n \
                $outPath

#### End script to automate building of Ubuntu mirror ####
```

##docker-composeでbuild
```
sudo docker-compose build
```

##debmirrorを実行
```
docker-compose up mirror
```
私の環境では12時間ぐらいかかりました。
mirrorディレクトリが作成され100GB以上の容量があります。

##Webサーバを実行
```
docker-compose up mirror
```
これでmirrorサーバの構築は完了です。

#クライアントの設定

##/etc/hostsを管理者権限で変更
例 構築したミラーサーバのipアドレスが192.168.22.1の場合
下記を追加

```
192.168.22.1    apt
```
##/etc/apt/sources.listを管理者権限で変更

deb http://から始まるURLを
http://apt:8080/archive.ubuntu.com/ubuntu/
に置き換えます。


```
#deb cdrom:[Ubuntu 20.10 _Groovy Gorilla_ - Release amd64 (20201022)]/ groovy main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://apt:8080/archive.ubuntu.com/ubuntu/ groovy main restricted
# deb-src http://apt:8080/archive.ubuntu.com/ubuntu/ groovy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://apt:8080/archive.ubuntu.com/ubuntu/ groovy-updates main restricted
# deb-src http://apt:8080/archive.ubuntu.com/ubuntu/ groovy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://apt:8080/archive.ubuntu.com/ubuntu/ groovy universe
# deb-src http://apt:8080/archive.ubuntu.com/ubuntu/ groovy universe
deb http://apt:8080/archive.ubuntu.com/ubuntu/ groovy-updates universe
# deb-src http://apt:8080/archive.ubuntu.com/ubuntu/ groovy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://apt:8080/archive.ubuntu.com/ubuntu/ groovy multiverse
# deb-src http://apt:8080.archive.ubuntu.com/ubuntu/ groovy multiverse
deb http://apt:8080/archive.ubuntu.com/ubuntu/ groovy-updates multiverse
# deb-src http://apt:8080/archive.ubuntu.com/ubuntu/ groovy-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://apt:8080/archive.ubuntu.com/ubuntu/ groovy-backports main restricted universe multiverse
# deb-src http://apt:8080/archive.ubuntu.com/ubuntu/ groovy-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu groovy partner
# deb-src http://apt:8080/ubuntu groovy partner

deb http://apt:8080/archive.ubuntu.com/ubuntu groovy-security main restricted
# deb-src http://security.ubuntu.com/ubuntu groovy-security main restricted
deb http://apt:8080/archive.ubuntu.com/ubuntu groovy-security universe
# deb-src http://security.ubuntu.com/ubuntu groovy-security universe
deb http://apt:8080/archive.ubuntu.com/ubuntu groovy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu groovy-security multiverse

# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.
```

設定はこれで完了です。

今まで通り、 sudo apt update を実行しエラーが出なければ成功です。