Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

Linux 下 ISO 的製作、刻錄與 MD5 自我校驗

檢驗下載的映像

md5sum download.iso

刻錄 ISO

sudo apt-get install cdrecord
cdrecord --scanbus          # 找出刻錄機,會給出類似 0,0,0 的數字
cdrecord dev=0,0,0 download.iso

檢驗刻好的光碟

先確保已安裝 isoinfo,然後查光碟資訊:

isoinfo -d -i /dev/cdrom
# Logical block size is: 2048
# Volume size is: 339344

再比對 MD5:

dd if=/dev/cdrom bs=2048 count=339344 conv=notrunc,noerror | md5sum

製作 ISO 映像

mkisofs -J -T -R -V volume_id -o mycd.iso source_dir

主要參數:
-J/-joliet:使用 Joliet 格式的目錄與檔名
-T/-translation-table:為每個目錄產生 TRANS.TBL 檔名轉換表
-R/-rock:使用 Rock Ridge Extensions
-V/-volid:指定光碟的卷標 ID

製作具自我校驗功能的光碟

ISO 在網路傳輸過程中可能發生改變,這可以透過 MD5 校驗碼檢測完整性:發布 ISO 的同時公布其 MD5,他人下載後再算一次,若數值相同即代表檔案一模一樣,否則就得重新下載。

那麼刻成光碟之後,如何確認片上的內容與原始 ISO 完全一致呢?這就要用到 isomd5sum:

implantisomd5 --force ISO檔案        # 加入 MD5 校驗資訊
checkisomd5 --verbose <光碟裝置,如 /dev/hdb>   # 刻錄後校驗

附:帶 MD5 校驗的 ISO 製作腳本

用法:mkiso.sh <原始檔案或目錄> <輸出 ISO> <CD 卷標>

#!/bin/sh
#****************************************************
# Author: Muddyboot - toobyddum@gmail.com
# Last modified: 2007-09-11 21:21
# Filename: mkiso.sh
# Description: script for easy creating ISO image
#****************************************************
if [ $# -lt 3 ]; then
    echo -e "\nUsage: `basename $0` source_dir output_iso cd_label \n"
    exit 1
fi
source=$1
output=$2
label=$3
### extra mkiso argument
shift 3
for i in $@; do
    extra_args="$extra_args $1 "
    shift
done
if [ ! -e "$source" ]; then
    echo -e "\nERR: Source file or directory does not exist ! \n"
    exit 1
fi
## remove exists TRANS.TBL files
if [ -d "$source" ]; then
    find $source -name TRANS.TBL | xargs rm -f
fi
### 製作 ISO
mkisofs -J -T -R $extra_args \
    -V $label -o $output $source
### 加入 MD5 校驗資訊
MD5_CHECKSUM=`whereis implantisomd5|awk -F': ' '{print $2}'`
if [ -z "$MD5_CHECKSUM" ]; then
    echo -e "\n** WARNING: implantisomd5 not found, no md5sum added.\n"
else
    echo -e "\n** Good, implantisomd5 program found."
    echo "Adding md5sum information for ISO image ..."
    implantisomd5 --force $output
fi
echo
echo "** ISO image $output created successfully ! "
echo
Copyright © Linux教程網 All Rights Reserved