Created
December 2, 2025 09:13
-
-
Save krisk0/0c82b7ade9d87f30004a8c903cbe60e0 to your computer and use it in GitHub Desktop.
Python subroutine that returns hard disk serial no
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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