sudo apt-get install apt-mirror
首先修改/etc/apt/mirror.list,使用cn.archive.ubuntu.com的源作鏡像,即在所有archive.ubuntu.com前加上cn.:gksu gedit /etc/apt/mirror.list,内容如下
############# config ##################
#
# set base_path /var/spool/apt-mirror
#
# set mirror_path $base_path/mirror
# set skel_path $base_path/skel
# set var_path $base_path/var
# set cleanscript $var_path/clean.sh
# set defaultarch <running host architecture>
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads 20
set _tilde 0
#
############# end config ##############
deb http://cn.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
#deb http://cn.archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
#deb http://cn.archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
#deb-src http://cn.archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
#deb-src http://cn.archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse
clean http://cn.archive.ubuntu.com/ubuntu
--------------------- 内容完 ------------------------
然後運作
apt-mirror
出錯:
~$ apt-mirror
flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror line 206.
apt-mirror is already running, exiting at /usr/bin/apt-mirror line 209.
ls -l 檢視/usr/bin/apt-mirror的權限: drwxr-xr-x 5 apt-mirror apt-mirror 4096 11\u6708 10 12:37 apt-mirror
權限是 apt-mirror:apt-mirror
修改為目前使用者權限 sudo chown <you>:<you> /usr/bin/apt-mirror
這裡<you>用目前使用者名替換
修改目錄權限:sudo chmod 777 -R /var/spool/apt-mirror
再運作 apt-mirror , 開始下載下傳鏡像:(如果沒有裁減,将下載下傳135G)
......
135.0 GiB will be downloaded into archive.
Downloading 119219 archive files using 20 threads...
======================================================================
下面是完整鏡像ubuntu14.04的mirror.list檔案設定
對于i386
############# config ##################
#
set base_path /var/spool/apt-mirror-i386
#
set mirror_path $base_path/mirror
set skel_path $base_path/skel
set var_path $base_path/var
set cleanscript $var_path/clean.sh
set defaultarch i386
set postmirror_script $var_path/postmirror.sh
set run_postmirror 0
set nthreads 20
set _tilde 0
#
############# end config ##############
deb http://cn.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu trusty-security main restricted
deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted
deb http://security.ubuntu.com/ubuntu trusty-security universe
deb-src http://security.ubuntu.com/ubuntu trusty-security universe
deb http://security.ubuntu.com/ubuntu trusty-security multiverse
deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse
deb http://extras.ubuntu.com/ubuntu trusty main
deb-src http://extras.ubuntu.com/ubuntu trusty main
clean http://cn.archive.ubuntu.com/ubuntu
對于amd64,将上面的i386都換成amd64即可。注意建立/var/spool/apt-mirror-amd64目錄及子目錄 mirror skel var 并設定權限。
==============================================
使用做好的鏡像源。有兩種方法:1 安裝web服務,類似網上鏡像;2 直接檔案通路,簡單,可放入移動硬碟
1, 安裝web服務
安裝apache網站伺服器
sudo apt-get install apache2
預設的網站主目錄為 /var/www/html
建立鏡像目錄軟連結
sudo ln -s /var/spool/apt-mirror-i386/mirror /var/www/html/ubuntu-mirror-i386
察看目錄
ls /var/www/html/ubuntu-mirror-i386
cn.archive.ubuntu.com extras.ubuntu.com security.ubuntu.com
察看本機ip位址
ifconfig
eth0 192.168.0.101
編輯源清單 gksu gedit /etc/apt/sources.list,在http://後面加上192.168.0.101/ubuntu-mirror-i386/,如下
#deb cdrom:[Ubuntu 14.04.3 LTS _Trusty Tahr_ - Beta i386 (20150805)]/ trusty main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty main restricted
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-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://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty universe
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty universe
deb http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-updates universe
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-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://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty multiverse
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty multiverse
deb http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-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://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb http://192.168.0.101/ubuntu-mirror-i386/security.ubuntu.com/ubuntu trusty-security main restricted
deb-src http://192.168.0.101/ubuntu-mirror-i386/security.ubuntu.com/ubuntu trusty-security main restricted
deb http://192.168.0.101/ubuntu-mirror-i386/security.ubuntu.com/ubuntu trusty-security universe
deb-src http://192.168.0.101/ubuntu-mirror-i386/security.ubuntu.com/ubuntu trusty-security universe
deb http://192.168.0.101/ubuntu-mirror-i386/security.ubuntu.com/ubuntu trusty-security multiverse
deb-src http://192.168.0.101/ubuntu-mirror-i386/security.ubuntu.com/ubuntu trusty-security 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 trusty partner
# deb-src http://archive.canonical.com/ubuntu trusty partner
## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://192.168.0.101/ubuntu-mirror-i386/extras.ubuntu.com/ubuntu trusty main
deb-src http://192.168.0.101/ubuntu-mirror-i386/extras.ubuntu.com/ubuntu trusty main
儲存,然後執行
sudo apt-get update 更新源清單
測試,安裝dia圖表制作軟體
sudo apt-get install dia
下載下傳7M多軟體包1秒完成。
2 直接檔案通路
如果不想安裝web服務,可以直接檔案通路鏡像。
修改 /etc/apt/sources.list
将http://192.168.0.101/ubuntu-mirror-i386/全部替換為file:///var/spool/apt-mirror-i386/mirror/即可
儲存,然後執行
sudo apt-get update 更新源清單
此方法可以不建立軟連接配接
如果鏡像在移動磁盤,路徑替換為移動磁盤鏡像就行了
==================================================================
apt-mirror可以随時ctrl+c退出,重新開始。利用空閑時間建立的ubuntu鏡像,顯著減少了安裝軟體包的下載下傳時間,提高了效率。
對于目前以T計的磁盤容量,存儲鏡像早已不是問題。