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.

Problem Analysis

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:

  1. /sys/firmware/dmi/tables/DMI contains 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:
  2. /sys/devices/virtual/dmi/id/product_serial and /sys/devices/virtual/dmi/id/product_uuid are text files that also contain the system serial number:

Solution Approach

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 Code

The program can be found at override-serial-number.sh (GitHub Gist) and it looks like this:

I hope that you find it useful.


  1. 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.

  2. Thanks ,Do you have any method to override uuid?

    1. Which UUID? Is that another file under /sys? You should be able to adapt this code for that as well.


Post a Comment

Like this content? You could send me something from my Amazon Wishlist. Need commercial support? Contact me for Consulting Services.

Popular posts from this blog

A Login Security Architecture Without Passwords

The Demise of KaiOS - Alcatel 3088X