How do I change the UUID of a vfat partition? For ext2/ext3/ext4 this is done with a simple

tune2fs -U <new-uuid> /dev/<partition>

Is there a similar command for vfat partitions?


It might be helpful to know why you want to do this. I don't know of a tool to do what you want, but there may be other options....

Technically, FAT partitions don't have UUIDs; they have serial numbers, which several Linux tools and files (such as mount and /etc/fstab) can use in place of UUIDs. On GPT disks, the partitions that hold FAT filesystems have GUIDs, which (on recent enough Linux distributions) can be referred to as PARTUUIDs in mount and /etc/fstab. Both FAT filesystems and (on GPT disks) the partitions that contain them can also have names, which can also be used by mount or in /etc/fstab. Any of these features might be usable in place of the FAT serial number.

Although I don't know of a tool to change FAT partitions' serial numbers, they can be set when the filesystem is created via the -i option to mkdosfs, as in:

mkdosfs -i ABCD1234 /dev/sdc1

This example sets the serial number of /dev/sdc1 to ABCD-1234. If the filesystem is small enough, you could back it up, create a fresh filesystem with the desired serial number, and restore it. If you're trying to set the serial number as part of a disk or installation setup script, setting it via mkdosfs might be all you need.

You can change the partition's GUID with gdisk or sgdisk. Using the latter, you'd do the job via the -u option, as in:

sgdisk -u 1:BC87D91A-02F3-4C52-87CD-536A3DF2A074 /dev/sdc

This example sets the GUID of /dev/sdc1 to BC87D91A-02F3-4C52-87CD-536A3DF2A074. (Note that -u takes a colon-delimited set of options, the first of which is the partition number and the second of which is the GUID value. The device filename for the whole-disk device [not the partition] is the final option.)

Depending on your needs, one of these approaches may work. Moving broader afield, you can set the filesystem's label with the dosfslabel tool; or you can change a GPT partition's name with sgdisk's -c option, which works much like -u, but takes a name rather than a GUID.

  • 2
    The servial number of a vfat device can be changed via the mlabel command of the mtools. – liquidat Apr 24 '18 at 18:22

The volume ID of FAT32 is stored in the first sector at offset 67 (0x43), for FAT16 it's at 39 (0x27). One can use the dd command to read it (replace /dev/sdc1 with your real partition):

dd bs=1 skip=67 count=4 if=/dev/sdc1 2>/dev/null \
| xxd -plain -u \
| sed -r 's/(..)(..)(..)(..)/\4\3-\2\1/'

And, of course, one can also store a new UUID (replace 1234-ABCD with your desired value):

printf "\x${UUID:7:2}\x${UUID:5:2}\x${UUID:2:2}\x${UUID:0:2}" \
| dd bs=1 seek=67 count=4 conv=notrunc of=/dev/sdc1

Reference: FAT physical structure (Volume Serial Number offset): https://technet.microsoft.com/en-us/library/cc776720(v=ws.10).aspx#w2k3tr_fat_how_gkxz

  • 1
    that's amazing! This is especially handy if you want to exchange a external micro sd-card on an Android device and want the new one match the same path as the old one. – therealmarv Jun 17 '18 at 10:31
  • Note that for FAT12/FAT16 volumes the offset is 39, not 67! This may happen if your partition is really small (mine was a 256M microSD). You can do a sanity check if you compare the readout by dd with the output of blkid before trying to write to your partition. – Ruslan Aug 12 '18 at 17:22

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.