Oscdimg使用指南

Oscdimg使用指南

Oscdimg是微软开发的一个ISO工具,它支持多种光盘文件系统,常用于系统镜像的封装与引导。

概述

ISO映像生成在PE打包和系统光盘制作中很常见,但是目前并没有完善的统一方案,微软为此开发了 Oscdimg 工具用于ISO的制作。在Linux上还有另一个开源工具 mkisofs ,同时也有Windows移植版,不过它的命令行参数过于庞大复杂,并不适合新手接触。

Oscdimg的前身是 CDImage,它也是微软开发的ISO工具,在Windows XP时代使用较多,后面逐步被新的Oscdimg取代。目前Oscdimg的最新版本是2012年的 v2.56,由于ISO文件规范是固定的,工具不需要频繁更新,所以即便在当下,微软官网的Windows镜像也是由它打包生成的。

预备知识

英文版维基百科对这部分内容有详细介绍

官方文档

Oscdimg的参数较多,微软的开发者文档和软件的自述文档中均有详细说明,但是官网的中文开发者手册是机器翻译的,其中存在不少错漏,建议直接阅读英文原版手册。

获取Oscdimg

Oscdimg是 Windows ADK 中的一个工具,包含 amd64 (64位架构)、 x86 (32位架构)、 arm64 (ARMv8架构)、 arm (ARMv7架构) 四个版本。你可以在微软官网的ADK安装页面找到对应你系统版本的安装包,下载 adksetup.exe,在安装时会询问你需要哪些功能,这一步必须勾选 部署工具 一项,其他功能按需选择即可。

选择需要安装的功能

安装完毕后,oscdimg.exe 一般位于 C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\$系统架构\Oscdimg\,同级目录还有 efisys.binetfsboot.com 两个文件,它们分别是UEFI与BIOS模式下的ISO引导程序,创建Windows系统的ISO镜像时需要用到它们。

这里可以下载到已提取的Oscdimg工具,里面包含amd64、x86、arm和arm64四种系统架构,并同时附带对应的ISO引导程序,提取的工具不依赖其他系统环境,直接在命令行中打开即可使用。

配置与使用

在安装有Windows ADK的系统上可以把Oscdimg目录添加到环境变量,使用时输入 oscdimg 就能直接调用。如果当前系统没有安装Windows ADK,也可以从已安装的系统上直接复制,同样也建议将目录添加为系统环境变量,方便在任意目录下调用。

配置完成后,在命令行工具中输入 oscdimg 可得到版本号及使用说明。

Oscdimg-CLI

ISO文件系统

ISO映像是最常见的光盘存储格式,其后缀通常为 .iso

ISO映像是光盘的存档文件,数据由一张光盘的全部扇区组成,它不对数据进行任何压缩,只是逐个复制一张光盘上的数据扇区,进而存储在单独的二进制文件中。ISO映像的数据存储结构与光盘创建时使用的文件系统相同,一般以2048字节为基础单位进行记录,但由于创建时会忽略控制头和错误纠正数据,因此文件大小会略低于原始的光盘介质。

ISO映像可以包含文件系统,常见的有以下三种:

  • ISO 9660 (CD-ROM介质)

  • Joliet (ISO 9660的一种扩展)

  • UDF (ISO/IEC 13346) (DVD或蓝光光盘)

ISO 9660

ISO 9660基于 High Sierra 格式,后者在1986年起草为 ECMA-119 标准,进而确定为 ISO9660:1988 标准,成为了目前使用最广泛和兼容性最好的光盘文件系统,也常被称为 CDFS

ISO 9660是国际标准化组织为光盘介质发布的文件系统,在设计上是一种只读的文件系统,所有数据都必须一次性写入到介质中,写入后就不能再更改存储内容。它保留映像的前32768个字节(共16个扇区,每个扇区2048字节),这部分区域不存储数据,预留给以后的标准使用,此外,它的文件系统目录深度最大为8层,并且任何文件的路径长度不得超过255字节。

标准中还将其分为多个级别,分别是Level1、Level2和Level3,其中Level1与DOS兼容,文件名或目录不得多于8个字符,后缀名不得多于3个字符,且所有字符只能是26个大写英文字母、10个阿拉伯数字及下划线,而Level2和Level3的文件名可以达到32个字符。

Joliet

Joliet是由微软公司提出和实现的光盘文件系统,是ISO 9660的一种扩展

Joliet文件系统的主要目的是放宽ISO 9660的文件名限制,它允许文件名最大长度为64个Unicode字符。由于是微软发起的标准,Windows95以后的Windows操作系统都支持该格式,大部分Linux发行版也支持,但是MacOS系统不支持该格式。

UDF

UDF是由光学存储技术协会开发并维护的光盘文件系统,初版发布于1995年,它实行了 ISO/IEC 13346 标准,旨在取代ISO 9660

UDF (UniversalDisk Format)是一种新式的光盘映像标准,支持只读和可写媒体,它与传统光盘的不同点在于用户可以移除,复制或删除文件,功能上与其他通用文件系统类似,基于该文件系统的ISO有时候会使用后缀名 .udf

UDF标准在十年间陆续发布了8个版本,目前最新标准为发布于2005年三月的2.60版本。由于DVD联盟采用UDF的1.02版本(发布于1996年八月)作为DVD音频和视频的官方文件系统,因此DVD和蓝光光盘均使用UDF文件系统。

命令行参数

Oscdimg是微软在 Windows ADK (Windows评估和部署工具包)中内置的一个命令行工具,可用于创建自定义的ISO映像文件,它支持ISO 9660、Joliet及UDF文件系统。

使用命令:

Oscdimg.exe [<options>] <sourceLocation> <targetFile>

<options> :命令行参数,可选

<sourceLocation> :存放数据的文件夹路径

<targetFile> :保存ISO映像的路径和名称

文件系统选项

Oscdimg工具支持三种文件系统格式:ISO 9660、Joliet和UDF。

三个选项之间存在互斥关系:

  • ISO 9660选项不能与Joliet或UDF选项组合

  • Joliet选项不能与ISO 9660选项组合

  • UDF选项也不能与ISO 9660选项组合

ISO 9660选项

ISO 9660文件系统中,文件名称的长度不能超过30个字符。

注意 -d-nt 不能一起使用。

  • -d :允许小写文件名称,否则所有文件名都会变成大写;

  • -n :允许文件名称长度超过DOS 8.3文件名称,即文件名少于8个字符,扩展名少于3个字符;

  • -nt :允许与Windows NT 3.51兼容的长文件名。

Joliet选项

Joliet文件系统允许较长的文件名称和Unicode字符,其文件夹深度可以大于8。

注意 -j2 选项不能与任何UDF选项一起使用。

  • -j1 :对 Joliet Unicode 文件名进行编码,在ISO 9660标准下生成兼容DOS 8.3的文件名,这些文件名可被Joliet或ISO 9660系统读取,但是Oscdimg可能会更改ISO 9660中的一些文件名以符合DOS 8.3的命名限制。这种情况下,Joliet文件系统将具有最多64个字符的Unicode文件名。

  • -j2 :在无标准ISO 9660名称的情况下对 Joliet Unicode 文件名进行编码,用于生成只有Joliet文件系统的映像。不支持Joliet的系统只会看到默认的文本文件,该TXT文件提醒用户此映像仅在支持Joliet的计算机上可用。

  • -js :覆盖用于 -j2 选项的默认文本文件,例如:-jsC:\readme.txt

UDF选项

  • -u1 :生成包含UDF和ISO 9660文件系统的映像,其中ISO 9660文件系统将使用兼容DOS 8.3的文件名写入,UDF文件系统将使用Unicode文件名写入;

  • -u2 :生成仅包含UDF文件系统的映像。不支持UDF的系统只会看到默认的文本文件,该TXT文件提醒用户此映像仅在支持UDF的计算机上可用;

  • -ur :覆盖用于-u2选项的默认文本文件,例如:-urC:\Readme.txt

  • -ue :创建内嵌文件,必须与 -u2 选项同时使用;

  • -uf :内嵌UDF文件标识符条目,必须与 -u2 选项同时使用;

  • -us :在可用时创建稀疏文件,更有效地利用磁盘空间,必须与 -u2 选项同时使用;

  • -yl :使用长分配描述符而非短分配描述符;

  • -udfver102 :指定UDF文件系统为 v1.02 ,可用于Windows 98及更高版本;

  • -udfver150 :指定UDF文件系统为 v1.50 ,可用于Windows 2000及更高版本;

  • -udfver200 :指定UDF文件系统为 v2.00 ,可用于Windows XP及更高版本;

启动选项

用于创建可启动的ISO映像。

注意:单启动项目指令和多启动项目指令不能同时使用。

生成单启动映像

  • -b<bootSectorFile> :指定El Torito引导扇区文件的位置,例如:-bC:\winpe_x86\Efisys.bin (UEFI引导), -bC:\winpe_x86\Etfsboot.com (BIOS引导);

  • -e :在El Torito编录中禁用软盘模拟;

  • -p :指定要用于El Torito编录中平台ID的值(默认ID 0xEF 表示UEFI系统, 0x00 代表BIOS系统)

生成多启动映像

-bootdata选项后必须有引导条目数,每个引导条目都必须通过 # 来分隔,启动选项之间通过逗号分隔,且每个启动选项都必须指定平台ID的值。

格式:-bootdata:<num>#defaultbootentry#bootentry2#bootentryN

<num> :指定多重引导条目数;

#bootentry :单条引导条目,格式如下:

  • b<bootSectorFile> :指定El Torito引导扇区文件的位置,例如:bEfisys.bin (UEFI引导), bEtfsboot.com (BIOS引导);

  • e :在El Torito编录中禁用软盘模拟;

  • p :指定要用于El Torito编录中平台ID的值,默认ID 0xEF 代表UEFI启动平台, 0x00 代表BIOS启动平台;

  • t :指定El Torito负载段,若未指定则默认 0x7C0

多重引导示例:

-bootdata:2#p0,bC:\etfsboot.com#pEF,e,bC:\Efisys.bin
  • -bootdata: :指定生成多重引导映像;

  • 2 :指定共有两条引导条目;

  • #p0,bC:\etfsboot.com :指定默认引导条目,基于BIOS启动平台(即Legacy引导方式),引导扇区文件使用 C:\etfsboot.com

  • #pEF,e,bC:\Efisys.bin :指定另一引导条目,基于UEFI启动平台,禁用软盘模拟,引导扇区文件使用 C:\Efisys.bin

这条命令将创建多引导映像,它具有启动 etfsboot.com 引导代码的x86引导扇区,并且在UEFI引导时启动 Efisys.bin

优化选项

通过扫描相同的文件防止重复存储,以此优化存储。

  • -o :通过文件MD5值比较每个文件;

  • -oc :在二进制下比较每个文件,比 -o 方式慢;

  • -oi :比较文件时忽略CAB压缩的时间戳;

  • -os :创建映像时显示重复的文件;

  • -ois :比较文件时,忽略CAB压缩的时间戳,且在创建映像时显示重复的文件,即 -oi-os 选项同时作用。

此处的 CAB压缩的时间戳 英文为 Diamond compression timestamps ,很多文档错误翻译为 菱形压缩时间戳 ,实际上 Diamond fileCabinet 压缩文件的别称,后者即为我们所熟知的CAB压缩 (Windows系统的存档文件格式),因此这里指的是CAB压缩时的时间戳。

顺序选项

此选项用于在磁盘上指定文件顺序。

注意:-yo 选项优先级高于 -y5 选项,且对于超过4.5GB的映像,必须确保启动文件位于映像的开始处。

-y5 :提前以逆序在i386目录中写入所有文件;

-yo<bootOrder.txt> :手动指定ISO映像中的文件写入顺序,该顺序记录在bootOrder.txt中,例如:-yoC:\temp\bootOrder.txt

<bootOrder.txt> 文件的要求:

  • 文件内容应为ANSI格式;

  • 文件应以一个新行结束;

  • 文件中每行包含一个文件路径;

  • 必须相对于映像的根目录来指定每个文件;

  • 应以长文件名来指定每个文件,不要使用短名称;

  • 每个文件路径长度不能超过MAX_PATH(包括卷名);

  • 可以不用列出全部文件,未列出文件的会顺序写入。

DVD选项

这部分选项不能与ISO 9660、Joliet或UDF的选项组合使用。

注意:-uv-ut 选项不能与 -u1-u2-ur-ue-uf-us-yl 选项组合使用。

  • -uv :在DVD视频/音频磁盘创建过程中指定UDF视频区兼容性,即UDF v1.02和ISO 9660都将写入磁盘,而且 VIDEO_TSAUDIO_TSJACKET_P 目录中的所有文件将首先写入,优先于用于此映像的所有其他排序规则;

  • -ut :在DVD视频/音频磁盘创建过程中截断映像的ISO 9660部分,使用此选项时,从ISO 9660文件系统仅能看到 VIDEO_TSAUDIO_TSJACKET_P 目录。

消息选项

  • -a :显示文件和目录的分配摘要;

  • -os :在创建映像时显示重复的文件;

  • -yd :不对具有相同初始64K字节的不同文件发出警告消息;

  • -w1 :显示所有不符合ISO或不符合Joliet的文件名或深度;

  • -w2 :显示所有不符合DOS 8.3的文件名;

  • -w3 :显示所有长度为零的文件;

  • -w4 :显示所有不符合DOS 8.3的文件名;

常规选项

可以与单启动或多启动项目选项同时使用。

注意:-m-maxsize 选项不能同时使用。

  • -c :使用ANSI文件名而不是OEM文件名;

  • -g :对所有文件使用通用协调时间 (UCT) 而不是当地时间;

  • -h :包含映像源路径下的所有隐藏文件和目录;

  • -k :即使一些源文件无法打开也仍然创建映像;

  • -x :计算并编码映像中的AutoCRC值;

  • -q :仅扫描源文件,不会创建映像;

  • -r :将符号链接解析到其目标位置;

  • -y6 :指定目录记录必须在扇区末尾完全对齐;

  • -yw :打开源文件且可以写共享;

  • -m :忽略映像的最大大小限制;

  • -maxsize:<limit> :覆盖映像的默认最大大小(74分钟的CD),limit 的单位为MB,若使用UDF则没有最大大小,例如:-maxsize:<4096>

  • -l<volumeLabel> :指定卷标,不超过32个字符,例如:-lMyVolume

  • -t<mm/dd/yyyy,hh:mm:ss> :指定映像上所有文件和目录的时间,例如:-t12/31/2000,15:01:00

使用示例

1. 创建基于UEFI的ISO映像文件

Oscdimg -bC:\winpe\Efisys.bin -pEF -u1 -udfver102 C:\winpe\media C:\winpe\winpe.iso

指定 C:\winpe\Efisys.bin 为引导文件,启动方式为UEFI,使用1.02版本UDF文件系统,同时兼容ISO9660。其中 C:\winpe\media 是源目录,C:\winpe\winpe.iso 是生成的ISO文件路径。

2. 创建基于UEFI或基于BIOS的多引导ISO映像文件

Oscdimg -bootdata:2#p0,e,bEtfsboot.com#pEF,e,bEfisys.bin -u1 -udfver102 C:\winpe\media C:\winpe\winpe.iso

创建多引导ISO映像,其中 etfsboot.com 为BIOS(Legacy)模式下的启动文件, Efisys.bin 为UEFI模式下的启动文件,使用1.02版本UDF文件系统,同时兼容ISO9660。其中 C:\winpe\media 是源目录,C:\winpe\winpe.iso 是生成的ISO文件路径。

3. 创建指定文件顺序的ISO映像文件

Oscdimg -m -n -yoC:\temp\bootOrder.txt -bC:\winpe_amd64\Efisys.bin C:\winpe C:\winpe_amd64\winpeamd64.iso

创建ISO映像时忽略大小限制,允许文件名称长度超过DOS8.3限制,同时指定ISO映像中的文件写入顺序为 bootOrder.txt 内的列表。其中 C:\winpe 是源目录,C:\winpe_amd64\winpeamd64.iso 是生成的ISO文件路径。

自述文档

这部分是软件自带的自述文档,可配合开发者手册阅读

版权声明

OSCDIMG 2.56 CD-ROM and DVD-ROM Premastering Utility
Copyright (C) Microsoft, 1993-2012. All rights reserved.
Licensed only for producing Microsoft authorized content.

命令行标准

Usage: OSCDIMG [options] sourceroot targetfile

ISO 9660选项

ISO 9660 options: These options cannot be combined with Joliet or UDF options

        -n  Use to allow long file names (longer than DOS 8.3 names)
        -nt Use to allow long file names, but restrict those names for
            NT 3.51 compatibility
        -d  Use to allow lowercase file names

The length of the file name plus the length of the file name extension shall
not exceed 30 characters for the ISO 9660 file system.  ISO 9660 is the most
widely compatible of the three available file systems produced by CDIMAGE.

NOTE: The (-nt) option cannot be used with the (-d) option

Joliet选项

Joliet options: These options cannot be combined with ISO 9660 options

        -j1  This option is used to produce an image that has both the Joliet
             file system as well as the ISO 9660 file system on it.  The ISO
             9660 file system will be written with DOS compatible 8.3 file
             names.  The Joliet file system will have Unicode file names up
             to 64 characters long.
        -j2  This option is used to produce an image that has only the Joliet
             file system on it.  Any system not capable of reading Joliet will
             only see a default text file alerting the user that this image is
             only available on computers that support Joliet.
        -js  This option overrides the default text file used with the (-j2)
             option.  Example: -jsc:\readme.txt

Joliet is an extension to the ISO 9660 file system.  It was created to
overcome some of the limitations of that file system.  It allows longer
file names, Unicode characters, and directory depths greater than 8.  Please
note that using the (-j1) option does not duplicate all files on the image.
The (-j1) option simply allows both file systems to view all the data on the
disk.

NOTE: The (-j2) option cannot be used with any UDF options.

UDF选项

UDF options: These options cannot be combined with ISO 9660 options

        -u1  This option is used to produce an image that has both the UDF file
             system and the ISO 9660 file system.  The ISO 9660 file system
             will be written with DOS compatible 8.3 file names.  The UDF file
             system will be written with Unicode file names.
        -u2  This option is used to produce an image that has only the UDF
             file system on it.  Any system not capable of reading UDF will
             only see a default text file alerting the user that this image is
             only available on computers that support UDF.
        -ur  This option overrides the default text file used with the (-u2)
             option.  Example: -urc:\readme.txt
        -us  This option will create sparse file when available.  This can only
             be used with the (-u2) option.
        -ue  This option will create embedded files.  This can only be used
             with the (-u2) option.
        -uf  This option will embed UDF file identifier entries.  This can
             only be used with the (-u2) option.
        -yl  This option will use long allocation descriptors instead of short
             allocation descriptors.

Three revisions of the UDF file system supported by CDIMAGE.
The default version is 1.50.
        -udfver102 Writes UDF revision 1.02  (Supported: Windows 98 and later)
        -udfver150 Writes UDF revision 1.50  (Supported: Windows 2K and later)
        -udfver200 Writes UDF revision 2.00  (Supported: Windows XP and later)

NOTE:  See DVD help for information on UDF and DVD Video/Audio images.

引导选项

Boot options: These options can be used to create bootable CD/DVD images

The following options may only be used for single boot entry images and may
not be combined with any multi-boot entry switches.

        -b  This option is used to specify the file that will be written in the
            boot sector(s) of the disk.  Example: -bc:\location\cdboot.bin
        -p  This option specifies the value to use for the Platform ID in the
            El Torito catalog.  The default is 0x00 to represent the x86
            platform.
        -e  This option means not to use floppy disk emulation in the El Torito
            catalog.

The following options may be used to generate multi boot entry images and may
not be combined with any single boot entry switches.

Each multi-boot entry is seperated via a # token, as well as the number of
boot entries.  The options for a boot entry are seperated via a comma token.
Each boot option must specify the boot code for that option.

        -bootdata:<num>#defaultbootentry#bootentry2#bootentryN

BootEntryOptions:
        b   This option is used to specify the file that will be written in the
            boot sector(s) of the disk.  Example: -bc:\location\cdboot.bin
        p   This option specifies the value to use for the Platform ID in the
            El Torito catalog.  The default is 0x00 to represent the x86
            platform. 0xEF represents an EFI-based system
        e   This option means not to use floppy disk emulation in the El Torito
            catalog.

        t   Specifies the El Torito load segment.  If not specified, defaults to
            0x7C0

Example:
 -bootdata:2#p0,bc:\location\etfsboot.com#pEF,bc:\location\ESPBootFile
This specifies a multi-boot image with the default image having an x86 boot
sector that launches the ETFSBOOT.com bootcode, and a secondary EFI boot
image that launches ESPBootFile when booted

优化选项

Optimize options: These options configure optimizations

        -o  This option will encode duplicate files only once.  This uses
            a MD5 hashing algorithm to compare files.
        -oc This option will encode duplicate files only once.  It does
            a binary compare on the files and is slower.
        -oi This option will ignore diamond compression timestamps when
            comparing files.

排序选项

Order options: These options allow specific file layout on disk

        -y5  This option will write all files in an i386 directory first and in
             reverse sort order.
        -yo  This option specifies a text file that has a layout for the files
             to be placed in the image.  The rules for this file are listed
             below.

Rules for order file.

1. The order file shall be in ANSI.
2. The order file shall end in a new line.
3. The order file shall have one file per line.
4. Each file shall be specified relative to the root of the image.
5. Each file shall be specified as a long file name.  No short names are
   allowed.
6. Each file path cannot be longer than MAX_PATH, including volume name.

For example:

If d:\cdimage looked as follows:
d:\cdimage\1\1.txt
d:\cdimage\2\2.txt
d:\cdimage\3\3.txt
d:\cdimage\3\3_5.txt
d:\cdimage\This is a long name.txt

And you ran the following: cdimage -yod:\orderfile.txt d:\cdimage image.iso

Then d:\orderfile.txt might look like this:

This is a long name.txt
1\1.txt
3\3_5.txt
2\2.txt
3\3.txt

Note that not all files must be listed in the order file.
Any files that are not listed in this file shall be ordered as they would if
there was no ordering file.

NOTE: The (-yo) option will take precedence over the (-y5) option.  Also, see
      the DVD help for ordering information on DVD Video/Audio disks.

DVD选项

DVD options: These options allow for DVD Video/Audio disk creation

        -uv  This option specifies that UDF Video Zone compatibility is to
             be enforced.  This means UDF 1.02 and ISO 9660 are written to
             the disk.  Also, all files in the VIDEO_TS, AUDIO_TS, and
             JACKET_P directories will be written first.  These directories
             take precedence over all other ordering rules used for this image.
        -ut  This option is used to truncate the ISO 9660 portion of the image.
             When this option is used, only the VIDEO_TS, AUDIO_TS, and
             JACKET_P directories will be visible from the ISO 9660 file
             system.

NOTE: These options cannot be combined with ISO, Joliet, or UDF options
NOTE: UDF file and directory names in VIDEO_TS, AUDIO_TS, and JACKET_P
      will use 8-bit characters as specified by the DVD Video spec.

消息选项

Mesg options: These options allow customization for what information is shown

        -w1 This option reports all non-ISO or non-Joliet compliant file names
            or depths
        -w2 This option reports all non-DOS compliant file names.
        -w3 This option reports all zero-length files.
        -w4 This option reports each file name copied to the image.
        -yd This option suppresses warnings for non-identical files with the
            same initial 64K.
        -a  This option displays the allocation summary for files and
            directories.
        -os This option will show duplicate files when creating the image.

常规选项

General Options: These are general options on image creation

        -l  This options specifies the volume label.  This should be 32
            characters or less.  There is no space after this option.
            Example: -lMyVolume
        -t  This option specifies a time stamp for all files and directories
            on the image.  Example: -t12/31/2000,15:01:00
        -g  This option  makes all times encoded in GMT time rather than the
            local time.
        -h  This option will include all hidden files and directories under the
            source path for this image.
        -c  This option will use ANSI file names instead of OEM file names.
        -y6 This options allows directory records to be exactly aligned at the
            end of sectors.
        -yw This option opens source files with write sharing.
        -k  This option creates an image even if it fails to open some of the
            source files.
        -q  This option just scans the source files only; it does not create
            an image.
        -m  This option is used to ignore the maximum size limit or an image.
        -maxsize This option overrides the default maximum size of an image.
                 The default value is a 74 minute CD unless UDF is used, in
                 which case the default is no maximum size.  The value
                 specified here is represented in MB.
                 Example: -maxsize:4096 limits the image to 4096MB.
        -r  This option resolves symbolic links to their target location.

NOTE: Option (-m) cannot be used with option (-maxsize).