创建镜像iso文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建镜像iso文件相关的知识,希望对你有一定的参考价值。
制作iso镜像(供yum源使用)使用cp命令即可,# cp /dev/sr0 /data/centos6.iso 生成的镜像iso可以用来引导系统的
查看内容iso内文件 # mount -t iso9660 /data/centos6.iso /mnt/iso
也可以使用# dd if=/dev/sr0 of=/data/centos6.iso 来生成iso镜像,同样可以用来引导系统
针对centos6 中将iso镜像分成两个,为了方便以后使用yum源时不缺包,可以将两个iso镜像合并
1.创建文件夹 mkdir /data/iso
2.将镜像中的所有文件拷贝至该目录下,对于相同的文件覆盖即可
3.使用mkisofs 来创建合集的iso镜像文件
#mkisofs -r -o centos6.iso /data/iso
注意:使用mkisofs创建的合集iso镜像不能用来引导系统,只可作为yum源使用
若想要创建可以引导的合集iso镜像文件,可以使用mkdvdiso 来创建
http://wiki.centos.org 在该网站中搜索mkdvdiso ,mkdvdiso是用来创建引导iso镜像的shell脚本
给出准确网址:https://wiki.centos.org/zh/TipsAndTricks/DtoDVDMedia?highlight=%28mkdvdiso%29
mkdvdiso 脚本:
#!/bin/bash
# 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 source /destination/DVD.iso
顺便想起来点东西:在linux系统中拷贝文件至USB设备中时,在cp命令执行完成以后记住要执行几次sync命令。
因为拷贝的过程分程是: 磁盘 --> 内存的cache区域 --> 内存的buffer区域 --> 系统会找个合适的时机将内容再拷贝至USB,所以可以执行几次sync 来将buffer中的数据写入USB
其实在/etc/fstab配置文件中,系统为了提高效率,默认的defaults中的选项不就是async的吗(man 5 fstab 配置文件帮助!你值得拥有)
以上是关于创建镜像iso文件的主要内容,如果未能解决你的问题,请参考以下文章