Jul 152012
 

本地的源,可以为你节省大量的时间,尤其在我们这种网络不是太好的环境下。现在很多朋友遇到的无法找到某个包,这种问题基本都是网络造成的。

对于服务器来说,其实只需要64bit就可以,不过你会发现,如果你运行 apt-get update 的话,默认源的设置,还是需要下载i386.

所以未来避免那种错误的提示,你需要把ubuntu 12.04源里所有的东西都下载回来。包括64bit,32bit,源码包。

这个脚本运行环境,需要debmirror. 这是老外写的脚本,我改了一下,加上一个参数:–ignore-release-gpg

http://ubuntuforums.org/showpost.php?p=7367273&postcount=237

http://www.gtkdb.de/index_7_1670.html

###########################################################################
##                                                                       ##
##                         Ubuntu Mirror Script                          ##
##                                                                       ##
## Creation:    06.07.2008                                               ##
## Last Update: 02.06.2012                                               ##
##                                                                       ##
## Copyright (c) 2008-2012 by Georg Kainzbauer <georgkainzbauer@gmx.net> ##
##                                                                       ##
## This program is free software; you can redistribute it and/or modify  ##
## it under the terms of the GNU General Public License as published by  ##
## the Free Software Foundation; either version 2 of the License, or     ##
## (at your option) any later version.                                   ##
##                                                                       ##
###########################################################################
#!/bin/sh

# Ubuntu mirror server and mirror directory
#SOURCE_SRV=cn.archive.ubuntu.com
#SOURCE_SRV=archive.ubuntu.com
SOURCE_SRV=mirrors.163.com
SOURCE_DIR=/ubuntu

# Distribution, section and architecture list
DIST=precise,precise-security,precise-updates,precise-backports,precise-proposed
SECTION=main,main/debian-installer,restricted,restricted/debian-installer,universe,universe/debian-installer,multiverse,multiverse/debian-installer
ARCH=i386,amd64

# Local mirror directory
#MIRRORDIR=/var/ftp/pub/linux/ubuntu/
MIRRORDIR=/home/ubuntu/

# Log file
LOGFILE=/var/log/ubuntu_mirror.log

# Debug file (if you do not want to debug the download process set this option to "/dev/null")
DEBUGFILE=/var/log/ubuntu_mirror.debug

# Who will be informed in case if anything goes wrong (if you do not want to be informed via mail, set this option to "")
#MAILNOTIFY="root@localhost"

# Lock file
LOCK=/var/tmp/ubuntu_mirror.lock

##################################################################
# NORMALY THERE IS NO NEED TO CHANGE ANYTHING BELOW THIS COMMENT #
##################################################################

function log()
  {
    echo `date +%d.%m.%Y%t%H:%M:%S` "    LOG:" $1 >>${LOGFILE}
  }

function error()
  {
    echo `date +%d.%m.%Y%t%H:%M:%S` "    ERROR:" $1 >>${LOGFILE}
    if [ -n "$MAILNOTIFY" ] ; then
      echo `date +%d.%m.%Y%t%H:%M:%S` "    ERROR:" $1 | mail -s "ERROR while synchronizing Ubuntu" $MAILNOTIFY
    fi
       echo $1 | grep "Lockfile" >/dev/null
    if [ $? = 1 ] ; then
      rm -f ${LOCK}
    fi
    exit 1
  }

function status()
  {
    case "$1" in
      0)
        log "Synchronization completed."
        ;;
      1)
        error "DEBMIRROR: Connection closed"
        ;;
      2)
        error "DEBMIRROR: Timeout"
        ;;
      *)
        error "DEBMIRROR: Unknown error $1"
        ;;
    esac
  }

if [ -f ${LOCK} ] ; then
  error "Lockfile ${LOCK} exists."
fi

touch ${LOCK}

# Create local mirror directory if not exists
if [ ! -d ${MIRRORDIR} ] ; then
  log "Creating local mirror directory."
  mkdir -p ${MIRRORDIR}
fi

log "Starting Ubuntu download process."
debmirror -v -e http -h ${SOURCE_SRV} -r ${SOURCE_DIR} --ignore-release-gpg --dist=${DIST} --section=${SECTION} --arch=${ARCH} ${MIRRORDIR} >> ${DEBUGFILE} 2>&1
status $?

rm -f ${LOCK}

exit 0                                                         

设置log

/etc/logrotate.d/ubuntu_mirror

/var/log/ubuntu_mirror.log {
    monthly
    rotate 3
    compress
    delaycompress
    missingok
    notifempty
}

/var/log/ubuntu_mirror.debug {
    weekly
    rotate 3
    compress
    delaycompress
    missingok
    notifempty
}

这个时候,就可以查看到log。目前我正在同步中。

2012年7月17日更新

已经用上面脚本,成功把ubuntu 12.04的全部源都下载到本地,总共快120G,并且已经通过cobbler来安装ubuntu,非常顺利完成。

  12 Responses to “CentOS6.x 制作ubuntu12.04源”

  1. 为什么不直接用apt-mirror呢?有什么区别吗?

    • 反正我试过很多办法,同步下来的源,无法完成ubuntu的安装。只能用这个办法。

  2. 还有centos下有debmirror这个命令吗,我yum install 没成功

  3. 请问,我用以前的ubuntu版本直接把镜像挂载到/var/www/html下面就行了,12.04的却不行,是为什么呢?

  4. 沙克老师,可否在在同步下来的ubuntu源中,再添加第三方的源呢。如果可以,需要修改哪些配置

 Leave a Reply

(required)

(required)