• 欢迎访问水熊虫网站,这里是我个人的工作博客,内容大多是遇到问题完善后,会在这里进行总结归纳内容! QQ群
  • 网站导航中的友情链接专栏上线,更新的都是自己这三年整理的一些东西,感兴趣可以看看!
  • 你所浪费的今天,是昨天死去的人奢望的明天。你所厌恶的现在,是未来的你回不去的曾经!

合并CentOS 6 镜像

脚本 WaterBear 3年前 (2021-01-02) 623次浏览 已收录 扫描二维码

环境说明:

相关目录说明:

/CentOS_ISO/DVD1  #用于挂载 Centos dvd1镜像目录

/CentOS_ISO/DVD2  #用于挂载 Centos dvd2镜像目录

/CentOS_ISO/CentOS  #用于存放合并的镜像文件目录


1、创建目录

mkdir -p /CentOS_ISO/DVD1 /CentOS_ISO/DVD2 /CentOS_ISO/CentOS


2、上传 Centos 镜像到服务器,挂载 Centos 镜像文件

mount -o loop /CentOS_ISO/CentOS-6.10-x86_64-bin-DVD1.iso /CentOS_ISO/DVD1

mount -o loop /CentOS_ISO/CentOS-6.10-x86_64-bin-DVD2.iso /CentOS_ISO/DVD2

3、拷贝文件到 合并镜像目录 /CentOS_ISO/CentOS

首先, 拷贝第一张cdrom中的所有文件到 /CentOS_ISO/CentOS 目录下,然后, 只拷贝第二张 cdrom 中 Packages 目录下的所有RPM文件到  /CentOS_ISO/CentOS 目录下

cp -rfT /CentOS_ISO/DVD1 /CentOS_ISO/CentOS

cp -af /CentOS_ISO/DVD2/Packages/*.rpm /CentOS_ISO/CentOS/Packages/


4、追加TRANS.TBL并排序

将cdrom2中TRANS.TBL的信息追加到cdrom1中TRANS.TBL后面, 并排序保存 

cat /CentOS_ISO/DVD2/Packages/TRANS.TBL >> /CentOS_ISO/CentOS/Packages/TRANS.TBL 

mv /CentOS_ISO/CentOS/Packages/{TRANS.TBL,TRANS.TBL.bak}

sort /CentOS_ISO/CentOS/Packages/TRANS.TBL.bak > /CentOS_ISO/CentOS/Packages/TRANS.TBL

rm -rf /CentOS_ISO/CentOS/Packages/TRANS.TBL.bak 

5、生成镜像

方法一、使用普通的文件系统转换,还不能做成启动光盘的iso文件,只能用来当作yum源。

mkisofs -r -o /CentOS_ISO/CentOS-6.10-x86_64-Everything.iso /CentOS_ISO/CentOS/

方法二、转换为可以做为启动光盘的文件,需要使用CentOS官网上的脚本运行 (mkdvdiso.sh)

官网脚本下载地址:https://wiki.centos.org/TipsAndTricks/CDtoDVDMedia

#mkdvdiso.sh  脚本代码放在文末

#用法: mkdvdiso.sh source /destination/DVD.iso

#“source”可以是包含一组isos的目录,也可以是类似ftp站点的分解树

#如果安装树不包含.discinfo文件,则必须从CD或DVD的顶层获得一个文件。

上传脚本并修改权限:

chmod +x mkdvdiso.sh

安装需要的环境:

yum install -y isomd5sum

yum install -y createrepo

sh mkdvdiso.sh /CentOS_ISO/CentOS /CentOS_ISO/CentOS-6.10-x86_64-Everything.iso

6、卸载镜像

umount /CentOS_ISO/DVD1

umount /CentOS_ISO/DVD2

7、 删除目录

rm -rf /CentOS_ISO/DVD1 /CentOS_ISO/DVD2 /CentOS_ISO/CentOS



本人制作好的镜像合并下载:

CentOS-6.10-i386-Everything.iso

https://oss.l-t.top/OSS/%E7%B3%BB%E7%BB%9F%E9%95%9C%E5%83%8F/CentOS-6.10/CentOS-6.10-i386-Everything.iso

CentOS-6.10-x86_64-Everything.iso

https://oss.l-t.top/OSS/%E7%B3%BB%E7%BB%9F%E9%95%9C%E5%83%8F/CentOS-6.10/CentOS-6.10-x86_64-Everything.iso

制作好的镜像校验信息如下:

文件名称:G:\CentOS-6.10-x86_64-Everything.iso

文件大小:5.79 GB (6223941632 字节)

修改时间:2021年01月02日,00:38:15

MD5     :CF5BC591AF9C2C3AEC4BDEC9E9FDF605

SHA1    :56F6C1A75B9819C9677150EC19AF95E20D056748

CRC32   :99811612

文件名称:G:\CentOS-6.10-i386-Everything.iso

文件大小:4.94 GB (5306486784 字节)

修改时间:2021年01月02日,01:29:01

MD5     :8D86C6F1463A8331253403E71E87920D

SHA1    :41B9F93F917410914CA60F0D69A083F06BFAD468

CRC32   :E65947C9

#mkdvdiso.sh  脚本代码如下:

# by Chris Kloiber <[email protected]>
# Mods under CentOS by Phil Schaffner <[email protected]>

# A quick hack that will create a bootable DVD iso of a Red Hat Linux
# Distribution. Feed it either a directory containing the downloaded
# iso files of a distribution, or point it at a directory containing
# the "RedHat", "isolinux", and "images" directories.

# This version only works with "isolinux" based Red Hat Linux versions.

# Lots of disk space required to work, 3X the distribution size at least.

# GPL version 2 applies. No warranties, yadda, yadda. Have fun.

# Modified to add sanity checks and fix CentOS4 syntax errors

# TODO:
#   Add checks for available disk space on devices holding output and
#       temp files.
#   Add optional 3rd parameter to specify location of temp directory.
#   Create .discinfo if not present.

OS_VER=\
$((test -e /etc/fedora-release && rpm -qf /etc/fedora-release --qf "FC%{VERSION}") \
|| (test -e /etc/redhat-release && rpm -qf /etc/redhat-release --qf "EL%{VERSION}") \
|| echo OS_unknown)

case "$OS_VER" in
  EL[45]*|FC?)
        IMPLANT=/usr/lib/anaconda-runtime/implantisomd5
        if [ ! -f $IMPLANT ]; then
            echo "Error: $IMPLANT Not Found!"
            echo "Please install anaconda-runtime and try again."
            exit 1
        fi
        ;;
  EL6*|FC1?)
        IMPLANT=/usr/bin/implantisomd5
        if [ ! -f $IMPLANT ]; then
            echo "Error: $IMPLANT Not Found!"
            echo "Please install isomd5sum and try again."
            exit 1
        fi
        ;;
  OS_unknown)
        echo "Unknown OS."
        exit 1
        ;;
  *)
        echo "Fix this script for $OS_VER"
        exit 1
esac

if [ $# -lt 2 ]; then
        echo "Usage: `basename $0` source /destination/DVD.iso"
        echo ""
        echo "        The 'source' can be either a directory containing a single"
        echo "        set of isos, or an exploded tree like an ftp site."
        exit 1
fi

DVD_DIR=`dirname $2`
DVD_FILE=`basename $2`

echo "DVD directory is $DVD_DIR"
echo "ISO file is $DVD_FILE"

if [ "$DVD_DIR" = "." ]; then
    echo "Destinaton Directory $DVD_DIR does not exist"
    exit 1
else
    if [ ! -d "/$DVD_DIR" ]; then
        echo "Destinaton Directory $DVD_DIR must be an absolute path"
        exit 1
    else
        if [ "$DVD_FILE" = "" ] || [ -d "$DVD_DIR/$DVD_FILE" ]; then
            echo "Null ISO file name."
            exit 1
        fi
    fi
fi

which mkisofs >&/dev/null
if [ "$?" != 0 ]; then
    echo "mkisofs Not Found"
    echo "yum install mkisofs"
fi

which createrepo >&/dev/null
if [ "$?" != 0 ]; then
    echo "createrepo Not Found"
    echo "yum install createrepo"
fi

if [ -f $2 ]; then
    echo "DVD ISO destination $2 already exists. Remove first to recreate."
    exit 1
fi

# Make sure there is enough free space to hold the DVD image on the filesystem
# where the home directory resides, otherwise change ~/mkrhdvd to point to
# a filesystem with sufficient free space.

cleanup() {
    [ ${LOOP:=/tmp/loop} = "/" ] && echo "LOOP mount point = \/, dying!" && exit
    [ -d $LOOP ] && rm -rf $LOOP 
    [ ${DVD:=~/mkrhdvd} = "/" ] && echo "DVD data location is \/, dying!" && exit
    [ -d $DVD ] && rm -rf $DVD 
}

cleanup
mkdir -p $LOOP
mkdir -p $DVD

ls $1/*.iso &>/dev/null
if [ "$?" = 0 ]; then

    echo "Found ISO CD images..."

    CDS=`expr 0`
    DISKS="1"

    [ -w / ] || {   # Very portable, but perhaps not perfect, test for superuser.
        echo "Only 'root' may use this script for loopback mounts" 1>&2
        exit 1
    }

    for f in `ls $1/*.iso`; do
        mount -o loop $f $LOOP
        cp -av $LOOP/* $DVD
        if [ -f $LOOP/.discinfo ]; then
            cp -av $LOOP/.discinfo $DVD
            CDS=`expr $CDS + 1`
            if [ $CDS != 1 ] ; then
                DISKS=`echo ${DISKS},${CDS}`
            fi
        fi
        umount $LOOP
    done
else
    if [ -f $1/isolinux/isolinux.bin ]; then

        echo "Found FTP-like tree..."

        if [ -e $1/.discinfo ]; then
            cp -av $1/.discinfo $DVD
        else
# How does one construct a legal .discinfo file if none is found?
            echo "Error: No .discinfo file found in $1"
            cleanup
            exit 1
        fi
        cp -av $1/* $DVD
    else
        echo "Error: No CD images nor FTP-like tree found in $1"
        cleanup
        exit 1
    fi
fi

if [ -e $DVD/.discinfo ]; then
    awk '{ if ( NR == 4 ) { print disks } else { print ; } }' disks="ALL" $DVD/.discinfo > $DVD/.discinfo.new
    mv $DVD/.discinfo.new $DVD/.discinfo
else
    echo  "Error: No .discinfo file found in $DVD"
    cleanup
    exit 1
fi

rm -rf $DVD/isolinux/boot.cat
find $DVD -name TRANS.TBL | xargs rm -f

cd $DVD
createrepo -g repodata/comps.xml ./
mkisofs -J -R -v -T -o $2 -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 8 -boot-info-table $DVD
if [ "$?" = 0 ]; then

    echo ""
    echo "Image complete, create md5sum..."

#  $IMPLANT --force $2
# Don't like forced mediacheck? Try this instead.
    $IMPLANT --supported-iso --force $2

    echo "Start cleanup..."

    cleanup

    echo ""
    echo "Process Complete!"
    echo "Wrote DVD ISO image to $DVD_DIR/$DVD_FILE"
    echo ""
else
    echo "ERROR: Image creation failed, start cleanup..."

    cleanup

    echo ""
    echo "Failed to create ISO image $DVD_DIR/$DVD_FILE"
    echo ""
fi

mkdvdiso.sh备份脚本下载:mkdvdiso.zip


WaterBear , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:合并CentOS 6 镜像
喜欢 (17)
[[email protected]]
分享 (0)