利用Shell脚本创建基于本机的ISO镜像

前提:1.以当前系统的anaconda-ks.cfg为模板,创建kickstart文件
     2.以install.log为模板摘取其中软件包包名信息并复制这些软件包到/tmp/iso目录中去,而后要复制过来的目录做createrepo(注意要保留原有光盘上的目录结构,比如Server,VT等而复制来的软件包应按原来的位置存放)
     3.将第一步创建的kickstart文件复制到/tmp/iso目录中为ks.cfg
     4.创建光盘镜像

#!/bin/bash
#
cat /root/install.log |awk '{print $2}' |sed 's/.*://g' >>/tmp/pkglist.txt
MYFILE='/tmp/pkglist.txt'
LDIR='/mnt/cdrom'
MDIR='/tmp/iso'
let count=0

[ -e $MDIR ] && mv $MDIR $MDIR.old && mkdir -p $MDIR/{Cluster,ClusterStorage,Server,VT} 2>>/tmp/error1.txt || mkdir -p $MDIR/{Cluster,ClusterStorage,Server,VT} 2>>/tmp/error1.txt
 
while read LINE
  do
    for I in Cluster ClusterStorage Server VT ;do
      if cp -r $LDIR/$I/$LINE.rpm $MDIR/$I 2>>/tmp/error2.txt ;then
        let COUNT++
     echo -e "${COUNT}:$LINE.rpm copy \033[31msuccessfully...\033[0m"
        break
      else
        continue
      fi
    done
  done < $MYFILE
 
echo -e "\033[31,5mcopy successfylly......\033[0m"
 
cp -r $LDIR/{isolinux,.discinfo,EULA,eula.en_US,GPL,images,README-en,TRANS.TBL,.treeinfo} $MDIR
 
echo -e "\033[32mcontinue...\033[0m"
 
[ -x `which wget` ] && wget ftp://192.168.0.254/pub/gls/server.repo /etc/yum.repos.d/ || rpm -i $LDIR/Server/wget-1.11.4-2.el5.i386.rpm $>/dev/null

yum clean all &>/dev/null
 
[ -x `which createrepo` ] && echo "The command createrepo exits..." || rpm -i $LDIR/Server/createrepo-0.4.11-3.el5.noarch.rpm &>/dev/null
 
cd $MDIR/Cluster/
createrepo -g repodata/comps-rhel5-cluster.xml ./
cd $MDIR/ClusterStorage/
createrepo -g repodata/comps-rhel5-cluster-st.xml ./
cd $MDIR/Server/
createrepo -g repodata/comps-rhel5-server-core.xml ./
cd $MDIR/VT/
createrepo -g repodata/comps-rhel5-vt.xml ./
rm -rf $MDIR/*/.olddata/ &>/dev/null
 
echo -e "\033[34mcreaterepo successfully...\033[0m"
 
cp /root/anaconda-ks.cfg $MDIR/ks.cfg
sed -i '20,26s/^#//g' $MDIR/ks.cfg
 
find $MDIR/isolinux -name "*" -exec chmod u+w {} \;
 
sed -i 's/default linux/default linux=cdrom:/ks.cfg/g' $MDIR/isolinux/isolinux.cfg
 
echo -e "\033[31mStart make linux ISO\033[0m"
 
cd /tmp
mkisofs -o mylinux.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T iso/
 
echo -e "The \033[31,5mISO\033[0m created successfully..."

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwsgzx.html