合并ISO(CentOS6.10)并制作可启动ISO

虚拟机上使用CentOS,不想网上下载rpm,于是想本地搞个rpm的yum源,但是官方的是两个iso,于是就想合并,但是网上的教程基本上都不全,有的甚至误导,所以自己综合一下吧,记录我制作的过程。如果你要看这篇文章来制作,请看完一遍后再开始,谢谢,而且虚拟机的盘的大小稍微大一点,否则制作到一半就废了。。。

  1. 准备:

    • 在/mnt下创建三个文件夹:
      mkdir -p /mnt/centos1 /mnt/centos2 /mnt/centos
      
      • centos1:用于挂载CentOS的第一张光盘
      • centos2:用于挂载CentOS的第二张光盘
      • centos:用于存放要生成启动盘内容
    • 上传iso文件
      • 这个方式太多,我用的是SecureCRT自带的SFTP,速度比较快
  2. 挂载 Centos 镜像文件,注意:根据自己iso位置

    mount -o loop ./CentOS-6.10-x86_64-bin-DVD1.iso /mnt/centos1
    mount -o loop ./CentOS-6.10-x86_64-bin-DVD2.iso /mnt/centos2
    
  3. 拷贝文件

    • 首先, 拷贝CentOS-6.10-x86_64-bin-DVD1.iso中的所有文件到 /mnt/centos 目录下
    • 拷贝CentOS-6.10-x86_64-bin-DVD2.iso 中 Packages 目录下的所有RPM文件到 /mnt/centos/Packages 目录下:
      cp -rv /mnt/centos1/. /mnt/centos/
      cp -v /mnt/centos2/Packages/*.rpm /mnt/centos/Packages/
      
      • 注意:使用.,而不是*,因为第一张光盘中有两个隐藏文件,我们平常的拷贝会胡烈隐藏文件
  4. 合并TRANS.TBL

    • 将centos2中TRANS.TBL的信息追加到centos1中TRANS.TBL后面, 并排序保存
      cat /mnt/centos2/Packages/TRANS.TBL >> /mnt/centos/Packages/TRANS.TBL 
      mv /mnt/centos/Packages/{TRANS.TBL,TRANS.TBL.BAK} 
      sort /mnt/centos/Packages/TRANS.TBL.BAK > /mnt/centos/Packages/TRANS.TBL 
      rm -f /mnt/centos/Packages/TRANS.TBL.BAK
      
    • /mnt/centos中的内容已经是合并后的内容了,即可以用作本地源和做成ISO使用。
  5. 更新Yum列表

    cd /etc/yum.repos.d
    rename .repo .repo.bak *.repo
    cp CentOS-Media.repo.bak CentOS-ISO.repo
    vi CentOS-ISO.repo
    
    • 参考内容:
      [c6-iso]
      name=CentOS-ISO
      baseurl=file:///mnt/centos
      gpgcheck=0
      enabled=1
      gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
      
    yum clean all
    
  6. 安装依赖包

    yum install -y createrepo
    yum install -y isomd5sum
    yum install -y genisoimage*
    
    • 注意这个命令需要自己找一下机型对应的安装包:yum whatprovides mkisofs,然后根据搜索结果进行安装
  7. 借助mkdvdiso.sh制作可启动ISO:

    #!/bin/bash
    
    # by Chris Kloiber <ckloiber@redhat.com>
    # Mods under CentOS by Phil Schaffner <pschaff2@verizon.net>
    
    # 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
    
  8. 添加执行权限

    chmod u+x ./mkdvdiso.sh
    
  9. 开始制作:

    ./mkdvdiso.sh /mnt/centos /root/CentOS-6.10-x86_64-bin-DVD-Everything.iso
    
    • 执行最后的内容:
      Total translation table size: 1689614
      Total rockridge attributes bytes: 743397
      Total directory bytes: 1122430
      Path table size(bytes): 112
      Done with: The File(s)                             Block(s)    3037927
      Writing:   Ending Padblock                         Start Block 3038884
      Done with: Ending Padblock                         Block(s)    150
      Max brk space used 6d3000
      3039034 extents written (5935 MB)
      
      Image complete, create md5sum...
      Inserting md5sum into iso image...
      md5 = ce84ea6fef4bf7cc2562c2fde851837d
      Inserting fragment md5sums into iso image...
      fragmd5 = c184edd1d8aa25e682503338b127e4665da5eea9e223943214b813f5e348
      frags = 20
      Setting supported flag to 1
      Start cleanup...
      
      Process Complete!
      Wrote DVD ISO image to /root/CentOS-6.10-x86_64-bin-DVD-Everything.iso
      
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,657评论 6 505
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,889评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,057评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,509评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,562评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,443评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,251评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,129评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,561评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,779评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,902评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,621评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,220评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,838评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,971评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,025评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,843评论 2 354

推荐阅读更多精彩内容