fatlabel - show/set the volume label on (V)FAT partitions
fatlabel dev [label ...]
The fatlabel utility displays and manipulates the volume label on FAT and VFAT (``DOS'') partitions. Its typical use is to assign meaningful names to USB mass storage (memory sticks, MP3 players, etc.).
The dev parameter is the name of the partition's device file (e.g. /dev/sdb1). Without additional parameters, the current label of dev is displayed. The label parameters are joined, separated by spaces and the resulting string is written to the device as the new volume label. The new label will be truncated to fit the 11 character limit if it is too long.
The utility automatically detects whether it is dealing with a FAT (FAT12, FAT16) or VFAT (FAT32) partition. It will do nothing if it cannot determine the type.
The dev argument need not be a device per-se. The utility works equally well on disk images.
We assume that a USB key is mounted on /dev/sdb.
To test without breaking anything:
# dd if=/dev/sdb1 of=/tmp/disk count=1 bs=1024
To display the label:
# fatlabel /tmp/disk /tmp/disk: FAT32 label: "USB Key"
To change the label:
# fatlabel /tmp/disk "Bond, James Bond" /tmp/disk: FAT32 old label: "USB Key" new label: "Bond, James"
Note that the label was truncated.
Error Diagnostics are written to stderr.
Fatal. The dev argument cannot be opened. The string will give the system error message (no permissions, file does not exist, etc.).
Fatal. We cannot determine the FAT type (if any) of dev. This typically happens if dev is not a (V)FAT partition at all, if it is corrupted, or, in a single rare case, if it is a valid FAT partition (see CAVEATS below).
Fatal. The label may or may not have been partially written to dev.
Fatal. Nothing was written to dev and system-error gives more details about the error.
Success.
Failure. Diagnostics have been written to stderr.
http://www.win.tue.nl/~aeb/linux/fs/fat/fat-1.html
It's probably a good idea to ummount the device before changing its label.
Although a FAT32 partition will always be detected correctly (bytes 82-89 of the first sector contain a space-padded string ``FAT32''), a FAT partition may not always be detected correctly. This is because bytes 54-61 of the first sector can contain a space padded string (``FAT12'', ``FAT16'', or ``FAT''), or all zeros. If the latter is the case, it may actually be any other type of filesystem that just happens to have zeros at that location. Hence, we won't do anything in that case. However, I have yet to come across an occurence of the ``all zeros'' case.
Steven Bakker, (es bee at monkey-mind dot net), 2007.