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-的提示。)