Format USB flash stick in UDF under Linux. Detailed guide

Usually USB flash sticks are formated in Fat32 file-system. This has one major well-known issue: you can’t write files bigger than 2 GB.
It is also possible to format flash stick in NTFS. But this will require to install ntfs-3g driver to work on LInux and Mac OS X.
Not a big deal, but lets assume, you can’t install one. So, your choice is likely to be UDF.

Here is a step-by-step guide how to format flash stick to UDF in such way, that it’ll be readable and writable under Windows 7 and Linux.

From a bird view this procedure has 3 simple steps:

  1. Deleting any existing partitions
  2. Creating new partition
  3. Creating UDF file-system

To avoid any permission problems all actions are performed as root.

1. Deleting any existing partitions

To do this you need fdisk utility. The most likely you already have one in your distribution.

# fdisk -b 512 /dev/sdc

(/dev/sdc is my flash drive, substitute this with proper value)
You can watch existing partitions with p.
Delete any existing partition d .
In most cases command d will be enough. This by default removes your 1st partition.

Double-check, that no partitions are left

Command (m for help): p

Disk /dev/sdc: 8103 MB, 8103395328 bytes
24 heads, 18 sectors/track, 36636 cylinders, total 15826944 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes 
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00072df1

   Device Boot      Start         End      Blocks   Id  System    

You can write changes to disk with w now.

2. Creating new partition

Run fdisk again with the same command

# fdisk -b 512 /dev/sdc

Type a command to add new partition. You will be asked for

  • partition type (primary/extended) – primary
  • partition number (1-4) – 1
  • start sector – accept defaults (just hit enter)
  • end sector – accept defaults

The most likely this will create new partition of type 83 Linux

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    15826943     7912448   83  Linux

Here comes magic: to make flash stick writable on Windows 7 change partition id to 06 FAT16

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 6

So, partition table should look like this now

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    15826943     7912448    6  FAT16

Write changes to disk with w.

3. Creating UDF file-system

Install udftools. Google for it, if your repository has no one (ArchLinux has one in AUR).

# mkudffs --media-type=hd --blocksize=512 /dev/sdc1
start=0, blocks=64, type=RESERVED 
start=64, blocks=12, type=VRS 
start=76, blocks=180, type=USPACE 
start=256, blocks=1, type=ANCHOR 
start=257, blocks=16, type=PVDS 
start=273, blocks=1, type=LVID 
start=274, blocks=15826413, type=PSPACE 
start=15826687, blocks=1, type=ANCHOR 
start=15826688, blocks=239, type=USPACE 
start=15826927, blocks=16, type=RVDS 
start=15826943, blocks=1, type=ANCHOR

Grtz, you’re done. Now your flash is perfectly readable and writable under Linux and Windows 7. Drive will be readable under Windows XP.
Also, this might be a placebo, but seemed, like performance increased after formatting to UDF. However, I’ve performed no benchmarks and made no any measurements.


About these ads

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: