format-udf

授权协议 GPL-2.0 License
开发语言 SHELL
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 华谭三
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

format-udf

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.

Features

  • Formats a block device (hard drive or Flash drive) in Universal Disk Format (UDF)
    • UDF revision 2.01 used for maximal compatibility (see note on Linux support below)
  • Resulting file system can be read/written across multiple operating system families (Windows, macOS, and Linux)
  • Runs on any OS having a Bash environment
  • Optionally wipes device before formatting
  • Ability to override detected device block size
  • Option to force non-interactive mode (useful for scripting)
  • Writes a fake MBR for added compatibility on Windows (optionally disabled)

For the advanced user, format-udf is also capable of formatting a single existing partition, without modifying the partition table. Beware that using this method will render the newly formatted UDF partition unusable on macOS (but still usable on Linux and Windows). (See #24 for caveats.) Because of this limitation, the recommendation is to format the entire device.

Why?

format-udf was created to address some OS-specific quirks that prevent a naively-formatted UDF device from working across various operating systems. Here are some of the complicating factors, which format-udf aims to abstract away:

  • Different operating systems support different versions of the UDF specification. Some OS versions only offer read-only support.
  • Windows seems to only mount UDF devices if the file system block size matches the device's logical block size
  • Different operating systems (like Windows XP) only attempt mounting UDF file systems with a hard-coded block size
  • Windows does not support hard disks without a partition table. (This is strange because Windows does not apply the same limitation to flash drives.)
  • macOS seems to only mount UDF file systems that utilize the full disk (not just a partition)

At first glance, these constraints appear to be in partial conflict. The solution, as suggested by Pieter, is to place a fake partition table (via MBR) in the first block of the drive, which lists a single entire-disk partition. This works because UDF (perhaps intentionally) doesn't utilize the first block. Unfortunately, there has been no easy way to do this, while juggling all of the other variables (such as device logical block size). format-udf writes such a fake MBR for added compatibility on Windows. If this is not what you desire, you can disable the MBR with -p none.

The goal of this project is to provide access to a cross-platform file system with modern features, in such a way that is:

  1. Easy to use for the average user
  2. Maximally compatible across operating systems
  3. As compliant as is reasonable with the UDF specification
  4. Maximally flexible to help users with uncommon needs

UDF OS Support

Not all operating systems support UDF. The following tables detail operating system support for UDF. Data was adapted from https://en.wikipedia.org/wiki/Universal_Disk_Format#Compatibility (as retrieved on 2017-06-16).

Natively Supported

Both read/write are supported unless otherwise listed below.

Operating System Read-only Note
Windows XP, Server 2003 Read-only Write support available with third party utilities
Windows Vista, 7, 8, 10 Referred to by Microsoft as "Live File System"; Requires fake full-disk partition
Mac OS 9
Mac OS X 10.5 through 10.11
macOS 10.12+
Linux 2.6+, 3.x UDF revisions 2.01 and before have read/write. After UDF revision 2.01, read-only.
AIX 5.2, 5.3, 6.1
BeOS, magnussoft ZETA, Haiku
DosBox
eComStation, OS/2 Additional-fee drivers on OS/2
NetBSD 5.0
Solaris 8, 9, 10

Supported with Third-Party Utilities

Operating System Note
Windows 95 OSR2+, 98 Utilities include DLA and InCD
Windows 2000, ME

Not Supported

Operating System Note
DOS, FreeDOS, Windows 3.11 or older File systems that have an ISO9660 backward compatibility structure can be read

4K Drive Support

Not all operating systems support 4K drives (Advanced Format). If you operating system supports UDF, but not your 4K drive, you still may encounter issues using format-udf.

Windows 4K Drive Support

The following tables detail Windows support for 4K drives. Data was adapted from the Microsoft support policy for 4K sector hard drives in Windows (as retrieved on 2017-06-16). Overlaid into this table are testing results from the format-udf community. (Special thanks to @pali for his testing on XP.)

Size / OS 512-byte native 512 emulation
(AKA "512e")
4K native
(AKA "4Kn")
Logical block size 512 bytes 512 bytes 4096 bytes
Physical block size 512 bytes 4096 bytes 4096 bytes
Maximum UDF file
system capacity
2 TiB 2 TiB 16 TiB
Windows XP Supported;
Works
Unsupported;
Doesn't work
Unsupported;
Doesn't work
Windows XP Pro x64,
Server 2003,
Server 2003 R2
Supported;
Likely works but untested
Unsupported Unsupported
Windows Vista,
Server 2008
Supported;
Likely works but untested
Supported;
Likely works but untested
Unsupported
Windows 7,
Server 2008 R2
Supported;
Likely works but untested
Supported;
Likely works but untested
Unsupported
Windows 8,
Server 2012
Supported;
Likely works but untested
Supported;
Likely works but untested
Supported;
Likely works but untested
Windows 8.1,
Server 2012 R2
Supported;
Likely works but untested
Unsupported Unsupported
Windows 10,
Server 2016
Supported;
Likely works but untested
Unsupported Supported;
Likely works but untested

If you have conducted testing and would like to update this table to benefit future users of format-udf, please send a pull request. Please include a link to your raw data or testing results.

Environment

  • Any OS having a Bash environment
  • The following tools must be installed, executable, and in the PATH:
    • printf
    • xxd
    • One of the following: blockdev, ioreg
    • One of the following: blockdev, diskutil
    • One of the following: lsblk, diskutil
    • One of the following: umount, diskutil
    • One of the following: mkudffs, newfs_udf

Prerequisites

To install necessary prerequisites on Ubuntu:

sudo apt-get install udftools coreutils vim-common

Installation

format-udf is a self-contained script. Simply copy format-udf.sh to a directory of your choosing. Don't forget to make it executable:

chmod +x format-udf.sh

Usage

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"

Example usage

On 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.

On 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.

Caveats

Block Size

If's extremely important that format-udf use the correct block size when formatting your drive. format-udf will attempt to detect and use the correct (logical) block size. If you know what you're doing, the format-udf -b BLOCK_SIZE option can be used to explicitly override the detected block size value.

If the wrong block size is used while formatting (i.e. one that doesn't match the logical block size of your drive), the resultant drive will likely have OS compatibility issues and suffer from non-optimal performance issues.

In the same way, it's just as important that the resultant drive be mounted using the correct block size. Many operating systems will only attempt one block size (usually whatever the mount utility defaults to). For example, In order to mount a UDF device, Windows seems to require that the UDF file system use a block size equal to the logical block size. If your block size isn't the OS's default, then auto-mounting likely will not work on your OS. While a small nuisance, manual mounting attempts should still succeed for nonstandard block sizes.

Example of how to manually mount on Linux:

$ mount -t udf -o bs=4096 /dev/sdX /mnt/mount-point

Example of how to manually mount on macOS:

$ sudo mount_udf -b 4096 /dev/diskN /Volumes/MountPoint

Sadly, anything with block size different than 512 doesn't seem to mount on Windows XP.

For more info, see #12, #13, #16, and #31.

Maximum UDF File System Capacity

The UDF format has a maximum of 2^32 blocks. With format-udf, these blocks equate to logical blocks.

  • If your drive's logical block size is 512 bytes, then your maximum UDF file system capacity will be 2 TiB
  • If your drive's logical block size is 4096 bytes, then your maximum UDF file system capacity will be 16 TiB

If your drive has capacity in excess of this maximum size, the extra capacity will not be used. This is a limitation of UDF itself.

For Best Results

For maximal OS compatibility, use format-udf on a device having a logical block size of 512 bytes. This will limit your total capacity to 2 TiB, but the resultant device should work on the most operating systems.

For maximal resultant UDF file system capacity, use use format-udf on a device having a logical block size of 4096 bytes. This will increase your total capacity (from 2 TiB) to 16 TiB, but will limit the number/types of operating systems that will be able to mount/read/write the resultant device. See compatibility tables above for more detail.

For a human-readable device label, use format-udf in one of the following configurations:

  • Run format-udf on Linux
  • Run format-udf on macOS, but modify the drive label using Linux or Windows

Miscellaneous Tips

  • After installing GRUB2 on a partitionless drive, you can use fdisk to set the partition as active if your BIOS can't boot from partitionless drives. (Thanks to @tome- for the tip.)

Contributions

  • Thanks to @walterav1984 for his contribution to add NVMe support

See Also

  • 简介 Hive为我们提供了众多的内置函数,但是在实际的运用过程中仍然不能满足我们所有的需求.hive是用java开发的,本身提供了使用java去开发UDF的方式.而这里我们采用python的方式去实现UDF函数. DEMO实现 我们这里用python自定义函数,去实现一个方法,利用身份证号去判断性别(18位身份证的倒数第二位偶数为女,奇数为男.15位身份证的倒数第一位偶数为女,奇数为男.).其实这

  • 1.分区 手动创建hive分区目录是无法被识别的。 需要执行命令创建: alter table book add partition(dt="20190722") location '/user/hive/warehouse/mytest.db/book/dt=20190722' 或者执行修复分区命令 MSCK repair table book; 2.元数据库 hive自带有一个元数据库为d

  • 0.要继承org.apache.hadoop.hive.ql.exec.UDF类实现evaluate 自定义函数调用过程: 1.添加jar包(在hive命令行里面执行) hive> add jar /root/NUDF.jar; 2.创建临时函数 hive> create temporary function getNation as ‘cn.itcast.hive.udf.NationUDF’;

  • 首先pom文件导入依赖,Hadoop和hive的依赖导入自己机器的版本,hive记得导jdbc <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-client</artifactId> <version>2.6.1</version>

  • Wenguang's Introduction to Universal Disk Format (UDF) 是初学UDF格式的有用文档,可惜是英文,对于大多数不熟悉英文的工程人员读起来费劲,当然对于读spec还是要容易一些。于是有想法把它翻译成中文,希望能把这个工程完成吧。 尊重作者,把链接贴出,也许不是原始链接: "Wenguang's Introduction to Universal Di

  • 由于impala处理日期的函数如date_sub(),date_trunc(),last_day()等这些日期处理函数还需要进行日期格式化为yyyy-MM-dd使用,sql代码段过长,导致频繁嵌套过于复杂.所以自定义udf函数解决这些问题.以下为实现过程. 日期加减,月份加减 对应日期的周一或周末,月初或月末,年初或年末 1 创建maven工程 导入以下maven依赖 <dependenc

  • 目录 1 Hive--HiveServer2 命令行代码连接 1.1 配置HiveServer2 WEB 参数 1.2 开启HiveServer2 1.3 使用Beeline连接HiveServer2 1.4 使用代码查询HiveServer2 1.5 使用DBeaver连接Hive   2 Hive--Hive常用命令 2.1 Hive 命令 2.2 Hive Shell 命令   3 Hive

  • 一.UDF的描述 用户自定义函数(UDF)是一个允许用户扩展HiveQL的强大的功能。用户可以使用Java编写自己的UDF,一旦将用户自定义函数加入到用户会话中(交互式的或者通过脚本执行的),它们就将和内置的函数一样使用,甚至可以提供联机帮助。Hive具有多种类型的用户自定义函数,每一种都会针对输入数据执行特定“一类”的转换过程。 在ETL处理中,ETL(是指:ETL是将业务系统的数据经过抽取、清

  • ISO和UDF: ISO-9660:又简称ISO,是由国际标准化组织在1985年制定的,当前唯一通用的光盘文件系统,任何类型的计算机都支持它,所有的烧录软件也都支持它。而且,若想让所有的CD-ROM都能读取烧录好的光盘,就必须使用ISO-9660或与其兼容的文件系统,其他的文件系统只能在CD-R或CD-RW上读取(有的还需要相应的烧录软件配合)。ISO-9660目前有两个标准:Level 1和Le

  • 注册一个判断指定日期的星期数的SQL函数 object UDFUtils { def main(args: Array[String]) { println(dayOfWeek("2017-05-14")) } def registerUDF(sqlContext: SQLContext, udfName: String): Unit = { udfName ma

  • 问题描述 最近几次,我看到UDF建议作为Linux,Mac OS X和Windows XP及更高版本上使用的驱动器的跨平台格式的解决方案。 我在这里搜索,没有找到相同的建议(大多数建议是ntfs-3g,它似乎要花钱,并且没有预装在Mac上)。 所以我的问题是:这怎么做正确,有人做过吗?然后,您是否已填满驱动器并删除了一些文件以腾出空间,以使所有内容看起来都像真正的r /w格式,即使它似乎主要是一次

  • 问题描述 最近几次,我看到UDF建议作为Linux,Mac OS X和Windows XP及更高版本上使用的驱动器的跨平台格式的解决方案。 我在这里搜索,没有找到相同的建议(大多数建议是ntfs-3g,它似乎要花钱,并且没有预装在Mac上)。 所以我的问题是:这怎么做正确,有人做过吗?然后,您是否已填满驱动器并删除了一些文件以腾出空间,以使所有内容看起来都像真正的r /w格式,即使它似乎主要是一次

  • 1.读取Hive中的数据加载成DataFrame <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-hive_2.11</artifactId> <version>2.3.1</version> </dependency> object sparkSQL06 {

 相关资料
  • 如前所述,Perl代表实用提取和报告语言,现在我们将讨论使用Perl编写报告。 Perl使用称为“格式”的书写模板来输出报告。 要使用Perl的格式功能,您必须 - 定义格式 传递将在格式上显示的数据 调用格式 定义格式 以下是定义Perl格式的语法 format FormatName = fieldline value_one, value_two, value_three f

  • 字符串的格式可以通过简单格式函数完成。 format函数使用java.lang.String.format.格式化字符串java.lang.String.format. 语法 (Syntax) 以下是语法。 (format fmt args) Parameters - 'fmt'是需要应用的格式。 'Args'是需要应用格式的参数。 Return Value - 返回值是一个字符串。 例子 (E

  • 代码格式化 用法 $ fecs format [target...] $ fecs format [target...] --type=js,css 说明 使用 eslint与 esformatter 对 当前目录 下所有 JavaScript 代码进行格式化。 使用 csscomb 对 当前目录 下所有 CSS 代码进行格式化。 使用 https://www.wenjiangs.com/doc/

  • import "go/format" Package format implements standard formatting of Go source.。 func Node(dst io.Writer, fset *token.FileSet, node interface{}) error func Source(src []byte) ([]byte, error) func Node

  • WebAssembly will define a standardized text format that encodes a WebAssembly module with all its contained definitions in a way that is equivalent to the binary format. This format will use S-express

  • 有没有注意到, 有时候 JavaScript 对数字的显示方式与预想的不一样, 比如下面这个简单的循环: for (var i = 0; i < 10; i++) { console.log(0.1 * i); } 你会得到如下结果: 0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6000000000000001 0.7000000000000001 0.8