Overriding / Patching Linux System Serial Number
I'm a big fan of test driven development (TDD) for infrastructure components. I'm currently working on a hardware-related topic where we also use the system serial number as identifier. To create a proper integration test, we need to be able to start a system and set the serial number to a known value. This can easily be done with the help of virtual machines like in VMware or VirtualBox, but I couldn't find a way for changing the system serial number on hardware boxes, cloud VMs (e.g. on Alibaba Cloud) or other Linux system.
I was thinking: Linux is the operating system where I can potentially do everything. So how hard can this be? After some digging around I found out that there are those main sources for the serial number on Linux:
/sys/firmware/dmi/tables/DMIcontains a binary blob of Desktop Management Interface data provided by the kernel and the dmidecode utility is commonly used to decode it and extract the system serial number like this:
/sys/devices/virtual/dmi/id/product_uuidare text files that also contain the system serial number:
The idea behind the solution presented here is to not change the serial number of the system itself, but rather change the serial number visible to software running in user space. This should be enough for most problems where software looks at the serial number to identify a system.
To solve my problem I created a little program that overrides the serial number in user space, using it looks like this:
The program can be found at override-serial-number.sh (GitHub Gist) and it looks like this:
I hope that you find it useful.
Thanks for this. I needed to remove VMWare from the beginning of the serial for inventory. You can't seem to do it from the VMX. This worked great.ReplyDelete