Home / Alt manpages / fatlabel(8)

  • fatlabel(8)
  • Admin command
  • linux

Set and verify FAT labels and volume IDs with fatlabel

You can use fatlabel to read or change the human-readable label on a FAT filesystem, or to inspect and set its 32-bit hexadecimal volume ID. This guide uses dosfstools 4.2, the version installed on the machine used for these examples. Allow about five minutes for a label change, including a verification pass.

Before you start

You need the fatlabel command from the dosfstools package and the path to a FAT filesystem. A regular user can practise on an image file that they own. A USB stick or disk partition normally needs elevated privileges, so use sudo for the individual command rather than making the whole shell a root shell.

Do not operate on a filesystem while it is mounted or being written to. A label change is small, but it still writes filesystem metadata. Identify the intended device first:

lsblk -f
findmnt --source /dev/sdX1

Replace /dev/sdX1 with the actual FAT device. The second command should produce no entry before you continue. If it shows a mount point, stop and unmount that filesystem during a maintenance window. A whole-disk image or partition is the operand; a directory containing a mounted filesystem is not.

Checkpoint

You have confirmed the device and know whether the command needs sudo.

Read the current label

With no new value, fatlabel prints the existing label:

sudo fatlabel /dev/sdX1

For example, the output might be:

CAMERA

In label mode, which is the default, an omitted second argument means read rather than change. The related historical name dosfslabel is an alias in this guide's source set, but prefer fatlabel. The manpage warns against using versions of the old command before 3.0.16 because their label handling was incomplete. The installed command reports version 4.2.

Change a label

Pass the new label after the device. Keep it to 11 bytes or fewer. Upper-case ASCII is the safest choice when the volume will be used by older DOS or Windows systems:

sudo fatlabel /dev/sdX1 ARCHIVE

A successful change normally produces no output. Read it back immediately:

sudo fatlabel /dev/sdX1
ARCHIVE

This command changes metadata, so treat the operation as destructive to the previous label. Record the old value before changing it if you may need to restore it:

old_label=$(sudo fatlabel /dev/sdX1); echo "$old_label"

Do not pass an empty string or whitespace as the new label. Labels longer than 11 bytes are rejected, and non-ASCII text depends on the DOS codepage used for encoding. The default is codepage 850. If another system expects a different DOS codepage, select it explicitly, for example:

sudo fatlabel --codepage=932 /dev/sdX1 CAMERA

Use a codepage that matches the systems which will read the volume. If compatibility is more important than local characters, choose a short upper-case ASCII label instead.

Checkpoint

The read-back command prints the new label, and any application using the device has been given time to see the change.

Read and set the volume ID

A FAT volume also has a numeric volume ID. Select volume ID mode with --volume-id or its short form -i:

sudo fatlabel --volume-id /dev/sdX1

The output is hexadecimal, such as:

a61a0e1b

To set a known ID, supply hexadecimal digits without a leading 0x:

sudo fatlabel --volume-id /dev/sdX1 1A2B3C4D
sudo fatlabel --volume-id /dev/sdX1
1a2b3c4d

The value must fit in 32 bits. A volume ID is not a substitute for a backup or an integrity check. Change it only when a tool or migration requires a particular identifier, because software may use it to recognise removable media.

Reset a label or ID

Warning

Reset is another metadata change. In normal label mode, --reset removes the label:

sudo fatlabel --reset /dev/sdX1
sudo fatlabel /dev/sdX1

The second command should print no label. To undo that change, set the recorded old label again:

sudo fatlabel /dev/sdX1 ARCHIVE

In volume ID mode, reset generates a new ID rather than removing the ID:

sudo fatlabel --volume-id --reset /dev/sdX1
sudo fatlabel --volume-id /dev/sdX1

There is no automatic undo for a generated ID. Restore the previous value only if you recorded it before the reset.

Common failures

  • Wrong device: stop if lsblk -f does not match the expected filesystem type, size and label. A device name such as /dev/sdb1 can change when removable storage is reconnected.
  • Mounted or busy filesystem: unmount it and retry. Do not force a metadata write into a filesystem that another process is using.
  • Rejected label: shorten it, remove whitespace-only input, and use upper-case ASCII unless you have checked the required codepage.
  • Invalid volume ID: remove 0x and use at most eight hexadecimal digits, for example 1A2B3C4D.
  • Unexpected label on another operating system: FAT labels have historically been stored in both the boot sector and the root directory. fatlabel 4.2 reads the root-directory label and updates both locations when changing it, which is the behaviour expected by common DOS and Windows readers.

Done means

  • You verified the target with lsblk -f and ensured it was not mounted.
  • You read back the label after changing or removing it.
  • You used --volume-id when handling the numeric ID, rather than confusing it with the label.
  • You recorded any old value needed for recovery.