Home » Questions » Computers [ Ask a new question ]

Using UDF on a USB flash drive

Using UDF on a USB flash drive

After failing to copy a file bigger than 4G to my 8G USB flash drive, I formatted it as ext3. While this is working fine for me so far, it will cause problems if I want to use it to copy files to someone which does not use Linux.

Asked by: Guest | Views: 280
Total answers/comments: 4
Guest [Entry]

"First, I zeroed completely the drive before creating the UDF filesystem with:

dd if=/dev/zero of=/dev/sdx bs=512

This is to avoid any leftover superblocks or other metadata which could confuse the operating systems' filesystem type detection (at least zeroing the first sector should be needed, to obliterate the partition table; the first few sectors are not used by UDF, and a leftover partition table could really confuse things). You could also use the count=1 switch on the dd command, in order to more-quickly zero just the first 512 bytes of the drive (where the MBR usually is located within), though this was not tested.

To create the file system, the command I used was:

mkudffs --media-type=hd --blocksize=512 /dev/sdx

mkudffs command will become available on Debian-based Linux distros (such as Ubuntu) after installing a udftools package:

sudo apt-get install udftools

The default blocksize for mkudffs is 2048, which is wrong for a USB flash drive (which uses 512-byte sectors). Since the block size is used to find the filesystem metadata, using a wrong block size can make it not be recognized as a UDF filesystem (since the anchor will not be where the filesystem driver is expecting). Note that the mkudffs man page is wrong; 512 is a valid value for the block size (and the code explicitly accepts it).

I also used the whole drive instead of a partition; this should be more compatible.

The result of my testing so far:

Linux with the most recent kernel (2.6.31, from Ubuntu 9.10): works.
Linux with an older kernel: needs the bs=512 option to mount, because it incorrectly used 2048 instead of the device sector size (fixed in commit 1197e4d).
Windows Vista: works.
A brand-new Mac: works.
Windows XP: can read fine, but gives ""access denied"" when trying to write; also seems to think the disk is full.

While I have not so far tried to create a file larger than 4G in it, I see no reason why it would not work.

Given that it worked perfectly on all recent operating systems (only having to mount manually on Linux, which will not be needed anymore as soon as Ubuntu 9.10 and Fedora 12 are out), and worked read-only in Windows XP (which was a surprise to me; I was expecting it to not recognize the filesystem at all), using UDF instead of FAT32 or NTFS in big USB flash drives seems a good idea."
Guest [Entry]

"I seem to recall having done that, the problem I found is that the linux version I had mounted it read only, as the driver had not been built for r/w. It did work in windows, and I think mac.

Yeah, a good solution is hard to find. For a while I had an external drive with a fat32 partition that had drivers for win and mac, a mac partition, and a big ext3 partition. It worked, but it meant installing drivers. Neat trick was it was also bootable on a mac (fw&usb), you have to leave space and take some notes, then you can add partitions via the command line and a mac partition table as well.

The world needs a free, usable by everything, file system. ZFS would be a nice choice. :-)"
Guest [Entry]

NTFS, with NTFS-3G you can write to it using Linux and take a look at http://macntfs-3g.blogspot.com/ for your Mac.
Guest [Entry]

There are drivers for Windows (and Mac) that can access EXT3 partitions, so you can format it to EXT3 and use it (with drivers) to everywhere. Another way would be to use an archiever to store the large file in two or more files up to 4GB each. This way you can use the FAT32 filesystem which is universal. On the host computer you have to extract the archive in order to use it, but it's a way to do it without drivers. Use a RAR format archiver since it works on Windows, Linux, Mac, although I think a ZIP format could work as well. But I would go with the drivers. Once installed you can do anything without restrictions. In the PC I have used Ext2Fsd for full EXT2, EXT3 and EXT4 access and Macdrive for full MacOS format access. Surely similar tools exists for Linux and MacOS as well to fully access NTFS partitions etc. If you only need read access, you don't need any drivers, Linux and MacOS support reading of NTFS partitions, so format the USB as NTFS! If all these computers are at the same network, things are easier! Make the USB either format and share it on the network. Other computers should not have problem accessing it!