Skip to content

Instantly share code, notes, and snippets.

@krisk0
Created December 2, 2025 09:13
Show Gist options
  • Select an option

  • Save krisk0/0c82b7ade9d87f30004a8c903cbe60e0 to your computer and use it in GitHub Desktop.

Select an option

Save krisk0/0c82b7ade9d87f30004a8c903cbe60e0 to your computer and use it in GitHub Desktop.
Python subroutine that returns hard disk serial no
def get_serial():
# TODO: find where root is mounted (mmcblk1p2), get mmcblk1 by cutting off
# 2-byte tail
f = '/sys/block/mmcblk1/device/serial'
if os.path.isfile(f):
with open(f, 'rb') as i:
n = i.read().rstrip()
if n[:2] == b'0x':
n = n[2:]
return n
f = '/sys/block/sda/device/vpd_pg80'
if os.path.isfile(f):
with open(f, 'rb') as i:
n = i.read().rstrip()
n=n[4:]
return n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment