Changing Disk Identifier Using fdisk

I was putting together a little script to help automate my simple, but good-enough-for-now backup jobs of my file server. The process consists of hooking up a USB drive and rsyncing the data down; there’s no data retention policy, etc, but for now, it’ll recover from a disaster. Improving the logic is for another day. For now, I just wanted to automate the process: just plug in the drive and have the backup run. In order for the drive discovery and mount to work reliably, I wanted the script to detect something unique about the disk. I noticed there’s a “disk identifier” when pulling up fdisk -l All the disks on my system had the identifier 0x0000000. These can be manually set by going into the fdisk shell and going to “expert mode” (x -> i). However, when editing it, the new identifier wasn’t being saved back and written to disk. This appears to be a known bug with at least the version of fdisk I had, to which a workaround has been found.

After setting the new disk identifier, then change partition type of any of the partitions, then change it back again to what it should be. Then exit with the ‘w’ command. This time the disk identifier is written to the disk.

This is a personal website. Unless otherwise stated, the content and opinions expressed here are my own and not those of my employer.