A Rust library and command-line tool to retrieve hardware-innate unique identifiers from block devices, such as MMC CID or NVME controller serial numbers. These identifiers are suitable for use in cryptographic key derivation or device-specific configuration.
- C-compatible shared library interface
- Command-line tool for querying device identifiers
- Supports multiple block device types (MMC, NVME, etc.)
- Debian-native package with vendored dependencies
To build the Debian package normally:
debuild -b -uc -usThis is a Debian-native Rust package that uses vendored Debian versions of packages rather than fetching from crates.io. For network-isolated builds (e.g., in build environments without internet access), you can use bwrap (bubblewrap) to create an isolated build environment.
bwrapmust be installed- A
resolv.conffile must be present in the project root (or create one for DNS resolution if needed)
bwrap --bind / / --bind ./resolv.conf /etc/resolv.conf --dev /dev --proc /proc -- debuild -b -uc -usThis command:
--bind / /- Binds the root filesystem--bind ./resolv.conf /etc/resolv.conf- Uses a local resolv.conf file (prevents DNS lookups)--dev /dev- Provides access to device files--proc /proc- Provides access to /proc filesystem-- debuild -b -uc -us- Runs the Debian build process
If you don't have a resolv.conf file, you can create a minimal one:
echo "nameserver 127.0.0.1" > resolv.confOr copy your system's resolv.conf:
cp /etc/resolv.conf ./resolv.confNote: The resolv.conf file is used to prevent DNS resolution attempts during the build. Even with a non-functional nameserver, the build will work because all dependencies are vendored and no network access is required.
The build process uses Debian's dh-cargo which:
- Sets up a vendored cargo registry from
/usr/share/cargo/registry - Creates a
config.tomlindebian/cargo_home/that replaces crates.io with the local registry - Pre-generates cargo metadata for cbindgen to avoid network access
- Uses cbindgen with the pre-generated metadata to create C headers
All Rust dependencies are provided by Debian packages (e.g., librust-libc-dev, librust-nix-dev, etc.), so no network access to crates.io is needed.
block-device-id- Command-line toollibblockdeviceid1- Shared library (C-compatible)libblockdeviceid-dev- Development files (headers, examples)librust-block-device-id-dev- Rust source package
block-device-id /dev/mmcblk0See examples/get_device_id.c for a complete example.
#include <block_device_id.h>
char id[129];
int ret = bdi_get_id("/dev/nvme0n1", id, sizeof(id));
if (ret == 0) {
printf("Device ID: %s\n", id);
}BSD-3-Clause - See LICENSE file for details.