13
6
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?
13
6
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?
13
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.
17
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):
UUID="1234-ABCD"
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
1that'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 – 2018-06-17T10:31:23.430
1Note 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 – 2018-08-12T17:22:02.633
dash(1) (the "/binsh" for ubuntu) cannot interpret ${UUID:7:2}
and the built-in printf
does not interpolate \xHH
. So it is better to use printf "%s" "${UUID}" | sed -r 's/(..)(..)-(..)(..)/\4\3\2\1/' | xxd -r -plain
– wolfmanx – 2019-05-02T20:35:56.423
0
Often one may want to set a new random UUID for a vfat partition (rather than set a specific one), for example to avoid conflicts after duplicating a partition with dd
. In this case, a simple solution is to use gparted
: right click on the partition, then "New UUID".
5
The servial number of a vfat device can be changed via the mlabel command of the mtools.
– liquidat – 2018-04-24T18:22:29.183Here's an example with the
mlabel
command :sudo mlabel -i /dev/mmcblk0p1 -N 12345678
– SebMa – 2019-11-22T00:35:05.277