Linux 中的 mkisofs 命令用于创建用于在 CD-ROM 设备上写入的文件系统。wodim 实用程序将实际刻录磁盘。mkisofs 命令准备要在介质上刻录的文件。
mkisofs 创建一个 iso 文件,它是光盘的映像文件(存档)。
本教程介绍了在 Linux 中创建 iso 映像的 mkisofs 工具。
使用 mkisofs
根据mkisofs 命令的手册页
"The mkisofs command creates a hybrid ISO9660/JOLIET/HFS filesystem with optional Rock Ridge attributes.""mkisofs takes a snapshot of a given directory tree, and generates a binary image which will correspond to an ISO9660 or HFS filesystem when written to a block device."
ISO9660 文件系统有一些限制
• 文件名必须为8.3 格式,即文件名最多可以有8 个字符,3 个字符的扩展名只能使用大写字母、数字和下划线。
• 最大目录深度为 8。
• 文件名不能有任何空格。文件名中最多允许一个点。目录不得包含任何点。
创建 iso9660 文件时,文件名将映射如下
• 文件名被截断为 8 个字符。
• 文件名中除最后一个点外的所有点都转换为下划线。
• 文件名版本作为;n 附加到文件名。
• 例如,“initrd-latest.img”将映射到“initrd_l.img”。
在 RRIP(Rock Ridge 交换协议)扩展中允许
• 更长的文件名(最多 255 个字节)和更少的允许字符限制(支持小写等)
• UNIX 样式的文件模式、用户 ID 和组 ID,以及文件时间戳
• 支持符号链接和设备文件
• 更深的目录层次结构(超过 8 级)
• 稀疏文件的高效存储
(来自维基百科)
默认情况下,mkisofs 命令转储 STDOUT 上的输出。可以使用 -o 开关给出输出文件名。一个使用 mkisofs 的简单例子:
$ mkisofs -o bootiso.iso /bootINFO: UTF-8 character encoding detected by locale settings.Assuming UTF-8 encoded filenames on source filesystem,use -input-charset to override.mkisofs: Symlink /boot/grub/menu.lst ignored - continuing.Total translation table size: 0Total rockridge attributes bytes: 0Total directory bytes: 4096Path table size(bytes): 38Max brk space used 190005078 extents written (9 MB)
如何列出 ISO 文件的内容
可以使用 列出isoinfo和提取ISO 文件的内容p7zip。
以下命令将列出 ISO 文件的内容。
$ isoinfo -l -i bootiso.iso
以下命令将从“bootiso.iso”文件中提取文件到“extracted_folder”。
$ 7z x -o extracted_folder bootiso.iso
在目录上挂载 ISO 文件
让我们将 iso 文件挂载到一个目录。运行以下命令:
$ mount -o loop bootiso.iso looped
/boot目录的原始内容是:
$ ls /boot/config-2.6.18-238.el5 grub initrd-2.6.18-238.el5.img initrd-latest.img lost+found symvers-2.6.18-238.el5.gz System.map-2.6.18-238.el5 vmlinuz-2.6.18-238.el5
文件名映射如下:
$ ls looped/config_2.el5 grub initrd_2.img initrd_l.img lost_fou symvers_.gz system_m.el5 vmlinuz_.el5 _vmlinuz.hma
在显示这些内容时,大写文件名被映射为小写。
该-R选项告诉 mkisofs 使用 Rock Ridge 协议。mkisofs 的其他有用选项是:
-L - allow dot files (hidden)-l - allow full 31 character filenames.-allow-lowercase - allows lower case characters to appear in iso9660 filenames.-allow-multidot - allows more than one dot to appear in filenames.-input-charset - specify a character set.
现在,使用这些选项:
$ mkisofs -l -L -input-charset default -allow-lowercase -allow-multidot -o bootiso.iso /bootmkisofs: The option '-L' is reserved by POSIX.1-2001.mkisofs: The option '-L' means 'follow all symbolic links'.mkisofs: Mkisofs-2.02 will introduce POSIX semantics for'-L'.mkisofs: Use -allow-leading-dots in future to get old mkisofs behavior.Warning: creating filesystem that does not conform to ISO-9660.mkisofs: Symlink /boot/grub/menu.lst ignored - continuing.Total translation table size: 0Total rockridge attributes bytes: 0Total directory bytes: 4096Path table size(bytes): 40Max brk space used 05078 extents written (9 MB)$ mount -o loop bootiso.iso looped/$ ls -a looped/. .. config_2.6.18_238.el5 grub initrd_2.6.18_238.el5.img initrd_latest.img lost_found symvers_2.6.18_238.el5.gz system.map_2.6.18_238.el5 vmlinuz_2.6.18_238.el5 .vmlinuz_2.6.18_238.el5.hmac
在本教程中,我们学习了如何在 Linux 中创建 iso 映像。