bash脚本以在UDF中格式化块设备(硬盘驱动器或闪存驱动器)。输出是一个驱动器,可用于跨多个操作系统系列的读取/写作:Windows,MacOS和Linux。该脚本应能够在MacOS或Linux中运行。
对于高级用户,格式-UDF也能够格式化单个现有分区,而无需修改分区表。注意,使用此方法将使新格式的UDF分区在MACOS上无法使用(但仍可在Linux和Windows上使用)。 (请参阅第24页。)由于此限制,建议是格式化整个设备。
创建格式-UDF的目的是解决一些特定于OS的怪癖,这些怪癖可以防止使用各种操作系统的自然成型的UDF设备在工作中工作。以下是一些复杂因素,格式化为旨在抽象出去:
乍一看,这些约束似乎处于部分冲突中。如Pieter所建议的那样,该解决方案是将假分区表(通过MBR)放在驱动器的第一个块中,该表列出了一个全盘分区。这是因为UDF(也许是故意)不使用第一个块。不幸的是,没有简单的方法可以做到这一点,同时兼顾所有其他变量(例如设备逻辑块大小)。格式化-UDF编写了这样的假MBR,以在Windows上增加兼容性。如果这不是您想要的,则可以使用-p none 。
该项目的目的是提供对具有现代功能的跨平台文件系统的访问,即以下方式:
并非所有操作系统都支持UDF。以下表详细信息操作系统支持UDF。数据根据https://en.wikipedia.org/wiki/universal_disk_format#compatibility(如2017-06-16检索)。
除非下面另有列出,否则两个读/写都得到支持。
| 操作系统 | 只读 | 笔记 |
|---|---|---|
| Windows XP,Server 2003 | 只读 | 与第三方公用事业一起提供支持 |
| Windows Vista,7、8、10 | Microsoft称为“实时文件系统”;需要假的全盘分区 | |
| Mac OS 9 | ||
| Mac OS X 10.5至10.11 | ||
| MacOS 10.12+ | ||
| Linux 2.6+,3.x | UDF修订2.01及之前读写。 UDF修订2.01之后,只读。 | |
| AIX 5.2、5.3、6.1 | ||
| Beos,Magnussoft Zeta,haiku | ||
| DOSBOX | ||
| Ecomstation,OS/2 | OS/2上的其他费用驱动程序 | |
| Netbsd 5.0 | ||
| Solaris 8、9、10 |
| 操作系统 | 笔记 |
|---|---|
| Windows 95 OSR2+,98 | 公用事业包括DLA和INCD |
| Windows 2000,我 |
| 操作系统 | 笔记 |
|---|---|
| DOS,Freedos,Windows 3.11或以上 | 可以读取具有ISO9660向后兼容结构的文件系统 |
并非所有操作系统都支持4K驱动器(高级格式)。如果您操作系统支持UDF,但不支持您的4K驱动器,则仍然可能会使用格式-UDF遇到问题。
以下表详细介绍了4K驱动器的Windows支持。数据是根据Windows中4K扇区硬盘驱动器的Microsoft支持策略进行了调整(如2017-06-16检索)。覆盖在该表中的正在测试格式-UDF社区的结果。 (特别感谢@Pali对XP的测试。)
| 尺寸 / OS | 512-BYTE本地 | 512仿真 (又名“ 512e”) | 4K本地 (又名“ 4KN”) |
|---|---|---|---|
| 逻辑块大小 | 512字节 | 512字节 | 4096字节 |
| 物理块大小 | 512字节 | 4096字节 | 4096字节 |
| 最大UDF文件 系统容量 | 2 tib | 2 tib | 16 tib |
| Windows XP | 支持; 作品 | 不支持; 行不通 | 不支持; 行不通 |
| Windows XP Pro X64, 服务器2003, 服务器2003 R2 | 支持; 可能有效但未经测试 | 不支持 | 不支持 |
| Windows Vista, 服务器2008 | 支持; 可能有效但未经测试 | 支持; 可能有效但未经测试 | 不支持 |
| Windows 7, 服务器2008 R2 | 支持; 可能有效但未经测试 | 支持; 可能有效但未经测试 | 不支持 |
| Windows 8, 服务器2012 | 支持; 可能有效但未经测试 | 支持; 可能有效但未经测试 | 支持; 可能有效但未经测试 |
| Windows 8.1, 服务器2012 R2 | 支持; 可能有效但未经测试 | 不支持 | 不支持 |
| Windows 10, 服务器2016 | 支持; 可能有效但未经测试 | 不支持 | 支持; 可能有效但未经测试 |
如果您已经进行了测试并想更新此表以使Format-UDF的未来用户受益,请发送拉动请求。请包括指向原始数据或测试结果的链接。
printfxxdblockdev , ioregblockdev , diskutillsblk , diskutilumount , diskutilmkudffs , newfs_udf要在Ubuntu上安装必要的先决条件:
sudo apt-get install udftools coreutils vim-common
格式-UDF是一个独立的脚本。只需将格式 - udf.sh复制到您选择的目录。不要忘记使其可执行:
chmod +x format-udf.sh
Bash script to format a block device (hard drive or Flash drive) in UDF.
The output is a drive that can be used for reading/writing across multiple
operating system families: Windows, macOS, and Linux.
This script should be capable of running in macOS or in Linux.
Usage: ./format-udf.sh [-b BLOCK_SIZE] [-f] [-p PARTITION_TYPE] [-w WIPE_METHOD] device label
./format-udf.sh -v
./format-udf.sh -h
-b BLOCK_SIZE
Block size to be used during format operation.
If absent, defaults to value reported by blockdev/diskutil.
This is an expert-only option. Please consult the README for details.
-f
Forces non-interactive mode. Useful for scripting.
Please use with caution, as no user confirmation is given.
-h
Display help information and exit.
-p PARTITION_TYPE
Partition type to set during format operation.
Currently supported types include: mbr, none
mbr - Master boot record (default)
none - Do not modify partitions
If absent, defaults to 'mbr'.
See also:
https://github.com/JElchison/format-udf#why
-v
Display version information and exit.
-w WIPE_METHOD
Wipe method to be used before format operation.
Currently supported types include: quick, zero, scrub
quick - Quick method (default)
zero - Write zeros to the entire device
scrub - Iteratively writes patterns on device
to make retrieving the data more difficult.
Requires 'scrub' to be executable and in the PATH.
See also http://linux.die.net/man/1/scrub
If absent, defaults to 'quick'.
Note: 'zero' and 'scrub' methods will take a long time.
device
Device to format. Examples:
* /dev/sdx (Linux, where 'x' is a letter) or
* /dev/diskN (macOS, where 'N' is a number)
label
Label to apply to formatted device.
Example: ./format-udf.sh /dev/sdg "My UDF External Drive"
在Ubuntu上:
user@computer:~$ ./format-udf.sh /dev/sdg "My UDF External Drive"
[+] Validating arguments...
[+] Testing dependencies...
[+] Looking for drive detail tool... using /sbin/blockdev
[+] Looking for drive listing tool... using /sbin/blockdev
[+] Looking for drive info tool... using /bin/lsblk
[+] Looking for drive summary tool... using /sbin/blkid
[+] Looking for unmount tool... using /bin/umount
[+] Looking for UDF tool... using /usr/sbin/mkudffs
[+] Detecting logical block size...
[sudo] password for user:
[*] Detected logical block size of 512
[+] Validating detected logical block size...
[+] Detecting physical block size...
[*] Detected physical block size of 512
[+] Validating detected physical block size...
[+] Validating file system block size...
[*] Using file system block size of 512
[+] Detecting total size...
[*] Detected total size of 8019509248
[+] Validating detected total size...
[+] Gathering drive information...
/dev/sdg: LABEL="Old Drive" UUID="4843-D1BD" TYPE="vfat"
RO RA SSZ BSZ StartSec Size Device
rw 256 512 512 0 8019509248 /dev/sdg
The above-listed device (and partitions, if any) will be completely erased.
Type 'yes' if this is what you intend: yes
[+] Unmounting device...
umount: /dev/sdg: not mounted
[+] Zeroing out first chunk of device...
4096+0 records in
4096+0 records out
2097152 bytes (2.1 MB, 2.0 MiB) copied, 0.450716 s, 4.7 MB/s
[+] Formatting /dev/sdg ...
filename=/dev/sdg
label=My UDF External Drive
uuid=5e4924cc17b50769
blocksize=512
blocks=15663104
udfrev=2.01
start=0, blocks=64, type=ERASE
start=64, blocks=13, type=VRS
start=77, blocks=19, type=ERASE
start=96, blocks=16, type=MVDS
start=112, blocks=16, type=ERASE
start=128, blocks=16, type=LVID
start=144, blocks=112, type=ERASE
start=256, blocks=1, type=ANCHOR
start=257, blocks=15662590, type=PSPACE
start=15662847, blocks=1, type=ANCHOR
start=15662848, blocks=96, type=ERASE
start=15662944, blocks=16, type=RVDS
start=15662960, blocks=143, type=ERASE
start=15663103, blocks=1, type=ANCHOR
[+] Writing fake MBR...
16+0 records in
16+0 records out
16 bytes copied, 0.0037039 s, 4.3 kB/s
2+0 records in
2+0 records out
2 bytes copied, 3.7193e-05 s, 53.8 kB/s
[+] Successfully formatted /dev/sdg: UUID="5e4924cc17b50769" LABEL="My UDF External Drive" TYPE="udf" PTTYPE="dos"
Please disconnect/reconnect your drive now.
在MacOS上:
computer:~ user$ ./format-udf.sh /dev/disk4 "My UDF External Drive"
[+] Validating arguments...
[+] Testing dependencies...
[+] Looking for drive detail tool... using /usr/sbin/ioreg
[+] Looking for drive listing tool... using /usr/sbin/diskutil
[+] Looking for drive info tool... using /usr/sbin/diskutil
[+] Looking for drive summary tool... using (none)
[+] Looking for unmount tool... using /usr/sbin/diskutil
[+] Looking for UDF tool... using /sbin/newfs_udf
[+] Detecting logical block size...
[*] Detected logical block size of 512
[+] Validating detected logical block size...
[+] Detecting physical block size...
[+] Validating file system block size...
[*] Using file system block size of 512
[+] Detecting total size...
[*] Detected total size of 8019509248
[+] Validating detected total size...
[+] Gathering drive information...
/dev/disk4 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *8.0 GB disk4
1: Windows_FAT_32 Old Drive 8.0 GB disk4s1
The above-listed device (and partitions, if any) will be completely erased.
Type 'yes' if this is what you intend: yes
[+] Unmounting device...
Password:
Unmount of all volumes on disk4 was successful
[+] Zeroing out first chunk of device...
4096+0 records in
4096+0 records out
2097152 bytes transferred in 3.113956 secs (673469 bytes/sec)
[+] Formatting /dev/disk4 ...
write to block device: /dev/disk4 last written block address: 15663103
[+] Writing fake MBR...
16+0 records in
16+0 records out
16 bytes transferred in 0.000615 secs (26021 bytes/sec)
2+0 records in
2+0 records out
2 bytes transferred in 0.000644 secs (3106 bytes/sec)
[+] Successfully formatted
Please disconnect/reconnect your drive now.
如果格式化格式在格式化驱动器时,使用正确的块大小非常重要。格式-UDF将尝试检测和使用正确的(逻辑)块大小。如果您知道自己在做什么,则可以使用格式-UDF -b BLOCK_SIZE选项明确覆盖检测到的块大小值。
如果在格式化时使用了错误的块大小(即与驱动器的逻辑块大小不符),则结果驱动器可能会遇到OS兼容性问题并遭受非最佳性能问题。
以同样的方式,使用正确的块大小安装所得驱动器也同样重要。许多操作系统只会尝试一个块大小(通常是安装实用程序默认设置的任何东西)。例如,为了安装UDF设备,Windows似乎要求UDF文件系统使用等于逻辑块大小的块大小。如果您的块大小不是操作系统的默认设置,则自动安装可能不会在您的操作系统上使用。虽然小滋扰,但对于非标准的块尺寸,手动安装尝试仍然应该取得成功。
如何手动安装在Linux上的示例:
$ mount -t udf -o bs=4096 /dev/sdX /mnt/mount-point
如何手动安装MacOS的示例:
$ sudo mount_udf -b 4096 /dev/diskN /Volumes/MountPoint
可悲的是,块大小不同于512的任何东西似乎都没有安装在Windows XP上。
有关更多信息,请参见#12,#13,#16和#31。
UDF格式的最大值为2^32个块。使用格式-UDF,这些块等同于逻辑块。
如果您的驱动器的容量超过此最大尺寸,则不会使用额外的容量。这是UDF本身的限制。
对于最大OS兼容性,请在具有512个字节的逻辑块大小的设备上使用格式-UDF。这将使您的总容量限制为2个TIB,但是所得的设备应在最多的操作系统上使用。
对于最大产生的UDF文件系统容量,请在具有4096字节的逻辑块大小的设备上使用格式-UDF。这将使您的总容量(从2个TIB)增加到16个TIB,但将限制能够安装/读取/编写所得设备的操作系统的数量/类型。有关更多详细信息,请参见上面的兼容性表。
对于人类可读的设备标签,请在以下配置之一中使用格式-UDF:
fdisk将分区设置为活动。 (感谢 @tome-的提示。)