67

How can I change the volume name of a FAT32 filesystem?  I know I can set the volume name when I format the partition with the -n option of mkfs.vfat.  But how to just change the name without formatting?

I especially want to be able to use lower and uppercase letters.  In worst case, I can use a Windows tool, but Windows by default transforms all letters to uppercase (but works fine with lowercase letters in volumes created with mkfs.vfat).

1

9 Answers 9

83

Dosfstools, which provides mkfs.vfat and friends, also provides fatlabel (called dosfslabel in older versions) to change the label.

5
  • I will try this in some days. Do you know if it can save lower-case letters?
    – Den
    Jul 30, 2012 at 5:51
  • It didn't work whit lower case letters. And after use, I got errors on the file system....
    – Den
    Sep 20, 2012 at 2:48
  • dosfslabel changed from supporting lower-case labels as of version 3.0.12 to rejecting them in 3.0.16
    – D McKeon
    Jan 9, 2014 at 20:11
  • 1
    @DMcKeon: it seems to work in 3.0.27, with a warning. Feb 29, 2016 at 3:51
  • blivet (at least, blivet3-data-3.1.3-3.el7) rejects lower-case labels for EFI partitions. dosfslabel (aka fatlabel, from dosfstools-3.0.20-10.el7) accepts them with a warning. So, blivet's being preemptively annoying. Oct 9, 2019 at 20:56
44

For my USB drive mlabel did not work, but fatlabelworked!

fatlabel /dev/device

gives you label

fatlabel /dev/device NEW_LABEL

sets new label

1
  • 1
    Because we label a file system and usually it is on a partition here is my command: sudo fatlabel /dev/sdXN NewLabel (/dev/sdf1, for example)
    – Mikolasan
    Oct 29, 2019 at 17:50
5

The solution is to use mkdosfs (mkfs.vfat) : it lets the user specify the volume label using the -n flag, and lowercase letters are kept lowercase, but this tool recreates the filesystem, so all data will be lost.

The non-destructive solution below is a combination of the mlabel and dosfslabel command-line tools.

  1. Connect the device to the computer if not already connected.
  2. Open a terminal window.
  3. Run blkid | grep ' TYPE="vfat"' and </proc/mounts grep ' vfat ' to figure out the name of the device (e.g. /dev/sdb1). Look around in /media etc. to confirm you have picked the right device. If unsure, unplug it, run the commands again, see it disappear, plug it back, and run the commands again.
  4. Unmount the device by running umount /dev/sdb1 (substituting /dev/sdb1 with the name of the device found above). If it was mounted, and the unmount failed, then close some windows, kill some programs (e.g. fuser -m /dev/sdb1), and try unmounting again.
  5. Run sudo env MTOOLS_SKIP_CHECK=1 mlabel -i /dev/sdb1 ::x (substituting /dev/sdb1 with the name of the device found above). If the system can't find mlabel, then install it by running sudo apt-get install mtools , and try again.
  6. Run sudo dosfslabel /dev/sdb1 MyLabel (substituting MyLabel with the desired label and /dev/sdb1 with the name of the device found above). Ignore any warnings about boot sector differences. If the system can't find dosfslabel, then install it by running sudo apt-get install dosfstools , and try again.
  7. Run blkid | grep ' TYPE="vfat"', and examine its output to verify that the label has been changed properly. Optionally, unplug the device, and then plug it back in. The system will recognize it, and mount it under /media/MyLabel, without converting lowercase letters in the volume label to uppercase.

Please note that there is an 11 character limit on the length of a VFAT volume label. If you specify a longer label, it will be truncated. There is another restriction: the label can contain only (some) ASCII characters: accented letters etc. won't work.

1
  • Thanks for your long answer! Can you explain what the command in 5. is doing exactly? It sets the label to 'x'?
    – Den
    Feb 23, 2016 at 13:19
4

Have a look at the Ubuntu page about renaming USB drives.  It's basically:

mlabel -i <device> ::<label>
5
  • Thanks! Change the name works, but it is transvormed to upercase: # mlabel -i /dev/sdc1 ::redsd # mlabel -i /dev/sdc1 -s :: Volume label is REDSD
    – Den
    Jul 27, 2012 at 3:31
  • 2
    @Den FAT disk labels are uppercase only
    – Matteo
    Jul 27, 2012 at 15:35
  • 1
    @Matteo I have here a HD whit FAT32 which have lower and upper case letters in the name: mlabel -vi /dev/sdb1 -s :: Volume label is miniTR
    – Den
    Jul 30, 2012 at 5:50
  • 2
    @Den yes FAT32 supports it. It is most likely a FAT16 formatted drive.
    – Matteo
    Jul 30, 2012 at 7:11
  • @Matteo Thanks for confirming I'm not completely silly ;-) The device I try to rename is a 15.9 GB FAT32 formated SD card.
    – Den
    Aug 17, 2012 at 1:39
2

The above commands didn't worked for me on Rasberry Pi / Rasbian Jessie 8. I decided to go with gparted.

Go to the Menu: Partition / Label. Write your desired name and then click on the green pipe (apply).

After the procedure you can see the details hided under the "multiple" + sign. There is a command total other:

 mlabel ::"LABEL_NAME" -i/dev/sda1
2

So far the only way I found to change a FAT volume name with lower case letters is to edit it with a hex editor (copy the first few sectors with dd to a temporary file, edit it and copy it back).  It works well so far (even with FAT16) and neither fsck nor CHKDSK from Windows 7 complained.  But no guarantee, of course ;-)

0

For a GUI alternative, gparted has a Label File System menu item for many file systems, including VFAT. It becomes available after unmounting the file system.

0

An update : Since now, the FAT32 file system has been superseded by the new exFAT for most flash devices, you my find that fatlabel do not work on many cards. you should the try exfatlabel instead of fatlabel

-1

Apologies for coming back to this 7 years later, but this is a top answer on google for the question, and I didn't have any of the tools suggested in the existing answers on the system I was using.

As a last resort,

if [ "`dd if=/dev/hda1 bs=1 count=7 skip=54 2>/dev/null`" = 'FAT16  ' ] ; then
  echo -n 'MYNEWLABEL1' | dd of=/dev/hda1 seek=43 count=11 bs=1 conv=notrunc
elif [ "`dd if=/dev/hda1 bs=1 count=7 skip=82 2>/dev/null`" = 'FAT32  ' ] ; then
  echo -n 'MYNEWLABEL1' | dd of=/dev/hda1 seek=71 count=11 bs=1 conv=notrunc
fi

ought to work.

5
  • 1
    Welcome to the site, and thank you for your contribution. May I recommend that you use the $( ... ) style for command substitutions insted of the backticks, as these are deprecated now.
    – AdminBee
    Jul 1, 2020 at 15:15
  • 1
    This is an unwise last resort. It makes assumptions about the BPB and the rest of the volume that aren't necessarily, or even usually, true. For example, often the volume label is entries in the root directory. If you don't have the tools, the right thing to do is obtain them. fatlabel handles the various BPB and root directory possibilties
    – JdeBP
    Jul 2, 2020 at 7:43
  • JdeBP: "even usually" "often". I'd dispute both. I've personally never come across a volume label in the root directory, and the "assumptions" it makes about the BPB are defined. Finally, if it turns out the assumptions are incorrect and you do have some bizarrely formatted disk that doesn't conform to the standard, it should be non-destructive. I would say in the majority case this will be sufficient. And telling someone to obtain tools, which may take hours of faffing with build environments just to label a disk is facile. If you have the tools, sure use them. If not, this should work.
    – Whinger
    Jul 2, 2020 at 8:28
  • 1
    Then you do not heave nearly enough experience with FAT. The volume label being directory entries has long been commonplace. This is not ¨bizarre" nor is it non-standard. Whereas in contrast this solution is unwise and has no guarantee of working at all, not least because the volume label in the root directory often gets precedence.
    – JdeBP
    Jul 2, 2020 at 18:14
  • 2
    I wrote my first FAT disk parser for an 8-bit home micro 28 years ago. If you dislike the solution, why not modify it to include the things you believe it needs rather than just whining about how it wouldn't work (when it demonstrably does)?
    – Whinger
    Jul 4, 2020 at 1:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .