建立自己的 apt 倉庫,這算是一篇很久以前我就有紀錄的文章了,不過是在 evernote 裡面。因為本質上也都 google 的到,所以就沒想說記下來了。但自從開始用 Ubuntu 20.04 以後,就發現 mirror 下來的東西有問題,在執行 apt-get update 時會有錯誤。所以就把以前的文章,加上找到的解決辦法,一起記下來了。
apt-mirror
要把一個 apt server 完整的 mirror 下來,可以利用 apt-mirror 這個程式。直接以 apt 安裝即可
1 |
apt-get install apt-mirror |
接著修改位於 /etc/apt/mirror.list 的設定檔. 基本上分為二部份,上半部是設定倉庫位置與併行下載數,下半部則是要下載的倉庫源。
上部份的參數只要變更目錄就可以了,下部份的參數則是要依據你要下載的Ubuntu distribution 來修改。從 14.04 ~ 22.04 的來源設定範例如下。
14.04 Trusty
1 2 3 4 5 6 7 8 9 10 |
set base_path /mnt/14.04 set nthreads 20 set _tilde 0 deb-i386 http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse |
18.04 Bionic
1 2 3 4 5 6 7 8 9 10 |
set base_path /mnt/18.04 set nthreads 20 set _tilde 0 deb-i386 http://archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse |
20.04 Focal
1 2 3 4 5 6 7 8 9 10 |
set base_path /mnt/20.04 set nthreads 20 set _tilde 0 deb-i386 http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse |
22.04 Jammy
1 2 3 4 5 6 7 8 9 10 |
set base_path /mnt/22.04 set nthreads 20 set _tilde 0 deb-i386 http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse |
程式修正
由於 apt-mirror 這個程式已經很久了,如前述在下載 20.04 後的部份,會缺東西。我參考這篇文章,依上面做了修改後,下載的東西才可以正確使用。到 22.04 都還沒問題。修改 apt-mirror 的原始檔 /usr/bin/apt-mirror,依下列修改。這邊就直接引用作者的圖了,Credit 歸原作者。
運行服務
apt server 本質上就是 http server 而已,進階使用者可以 apache virtualserver 來作。這邊我們直接用 busybox 的 http 來架設,再用不同 port 來作區分。
1 2 3 4 |
http -p 2204 -h /mnt/22.04/mirror/archive.ubuntu.com/ http -p 2004 -h /mnt/20.04/mirror/archive.ubuntu.com/ http -p 1804 -h /mnt/18.04/mirror/archive.ubuntu.com/ http -p 1404 -h /mnt/14.04/mirror/archive.ubuntu.com/ |
Client 進行下載
當 server 架設完成後,就可以修改Client端的 /etc/apt/sources.list 來指定來源倉庫了。
1 2 3 |
deb http://127.0.0.1:1804/ubuntu/ bionic main restricted universe multiverse deb http://127.0.0.1:1804/ubuntu/ bionic-security main restricted universe multiverse deb http://127.0.0.1:1804/ubuntu/ bionic-updates main restricted universe multiverse |
這裡我們是指到本地端的 http://127.0.0.1:1804,也就是剛剛 busybox 指定的位置。這邊請依據自己實際的架設狀況來修改。