VFAT, UUID, SD Cards, Android Mount

Last night I was setting up a new Android tablet to match an old one. Both have SD cards with apps that store data on it. To make things easier, I wanted the SD card to mount to the same point in the filesystem. But Android 6 mounts the SD card to a directory whose name is the card’s serial number (UUID). That is: /storage/XXXX-XXXX. We’re talking about the serial number, not the volume label – so it’s not easy to change – tune2fs can’t do it because it’s fvat, not ext.

Eventually I succeeded but there were a few twists along the way.

Ubuntu help forums online have a procedure to do this with dd commands, but I want to avoid performing block level I/O on the filesystem. I found a simpler, cleaner, safer way to do this:

First, install mtools. It’s in Ubuntu’s standard repos: sudo apt-get install mtools

Next, connect the SD card and check which device it is – in my case /dev/sdc1 but this will vary. Make sure it’s unmounted, but not ejected.

Next use mlabel to set the UUID: sudo mlabel -i /dev/sdc1 -N XXXXXXXX ::VOL-LABEL

NOTE: mlabel’s -i param is undocumented. It’s how you specify the device. You can omit the VOL-LABEL, but leave the :: in place.

NOTE: after doing this if you check the UUID using blkid or other commands, they will report it unchanged – even if you remove and reinstall the SD card. This is incorrect; the UUID did actually change. Apparently, you must reboot before Linux will recognize a changed UUID for a filesystem.