Home / Alt manpages / fatlabel(8)

  • fatlabel(8)
  • Admin command
  • linux

Set and Verify FAT Labels and Volume IDs with fatlabel

You can rename a USB stick or camera card in seconds with fatlabel, and read or set its 32-bit hexadecimal volume ID while you are there. This guide uses dosfstools 4.2, the version installed on the machine used for these examples. Allow about five minutes, including a read-back to prove it worked.

Before you start

You need the fatlabel command from the dosfstools package and the path to a FAT filesystem.

  • Practise safely. A regular user can experiment on an image file they own.
  • Real devices need privileges. A USB stick or disk partition normally does, so use sudo for the individual command rather than making the whole shell a root shell.
  • Unmount first. 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 before anything else:

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. The operand is a whole-disk image or a partition; a directory containing a mounted filesystem is not.

Checkpoint

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

1. 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 historical name dosfslabel is an alias in this guide's source set, but prefer fatlabel.

Warning

The manpage warns against versions of the old command before 3.0.16, because their label handling was incomplete. The installed command reports version 4.2.

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 older DOS or Windows systems will read the volume:

sudo fatlabel /dev/sdX1 ARCHIVE

A successful change normally prints nothing. Read it back immediately:

sudo fatlabel /dev/sdX1
ARCHIVE

Warning

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

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

What gets rejected or goes wrong:

  • Empty or whitespace labels. Do not pass them.
  • Anything over 11 bytes. Rejected.
  • Non-ASCII text. It depends on the DOS codepage used for encoding. The default is codepage 850.

If another system expects a different DOS codepage, select it explicitly:

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

Tip

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

Checkpoint

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

3. 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 backup or an integrity check. Change it only when a tool or migration demands a particular identifier, because software may use it to recognise removable media.

4. 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 it, 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

Recovery

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

Common traps

  • 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 what common DOS and Windows readers expect.

Done means

  • Right device. You verified the target with lsblk -f and made sure it was not mounted.
  • Label confirmed. You read it back after changing or removing it.
  • ID handled separately. You used --volume-id for the numeric ID rather than confusing it with the label.
  • Recovery value kept. You recorded any old value you might need to restore.