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計的磁盤容量,存儲鏡像早已不是問題。