2012-09-22

How to change the volume label to lowercase on an USB stick, memory card or any VFAT filesystem on Ubuntu Lucid

This blog post explains how to change the volume label to lower case on an USB stick, memory card or any other VFAT filesystem. The instructions given were verified for Ubuntu Lucid, but they may work on other Linux systems as well.

On the web some people claim it's not possible, but indeed it is. On the web there are instructions how to change the volume label with GParted or mlabel (part of Mtools) and palimpsest (Disk Utility), but none of them work, because these tools always convert lowercase to uppercase before setting the label. Nautilus, the default file manager for Ubuntu doesn't support changing the volume label at all.

mkdosfs (mkfs.vfat) 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 sudo 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. sudo 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 sudo blkid | grep ' TYPE="vfat"' , and examine its output to verify that the label has been changed properly.
  8. 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.

No comments: