Add dynamic hostname generation for hardware-based device identification#1512
Add dynamic hostname generation for hardware-based device identification#1512brianmcgillion merged 1 commit intotiiuae:mainfrom
Conversation
|
ghaf/modules/microvm/host/microvm-host.nix Lines 223 to 248 in 0214189 can we consolidate your new change into this. so that we can have a unified and hopefully persistent name for the device that we can search in graphaha? |
|
found the problem and finally fixed it
|
f5b9336 to
c935b71
Compare
99b9f43 to
c935b71
Compare
20c607d to
bd226aa
Compare
|
@vadika |
|
Thanks for the quick reply! It is clear, and thanks for the hint/proposal. |
…tion
Implement runtime-generated, human-readable hostnames derived from
permanent hardware properties (DMI serial/UUID, MAC address, or
machine-id). The hostname format is 'ghaf-NNNNNNNNNN' where N is a
10-digit number deterministically generated from hardware properties.
Key features:
- Host generates and shares hostname via /persist/common/ghaf/hostname
- NetVM sets its actual hostname for DHCP client identification
- All VMs have access to the hostname via environment variable
- NetworkManager configured to preserve the dynamic hostname
- 10 billion possible hostnames for excellent uniqueness
- Replaces random device-id with deterministic hardware-based ID
- Consolidates device-id and machine-id generation into single script
- All machine-ids are deterministic and hardware-based (not random UUIDs)
- Configurable ID source: hardware (default), static, or random
Implementation:
- dynamic-hostname.nix: Single script generates hostname, device-id, and all VM machine-ids
- vm-hostname-export.nix: Exports hostname as environment variable
- vm-hostname-setter.nix: Sets actual VM hostname from shared file
- Virtiofs share (/persist/common -> /etc/common) propagates to VMs
- NetworkManager hostname-mode set to 'none' to prevent override
- dynamic-hostname.nix: Single script generates hostname, device-id, and all VM machine-i
ds
- vm-hostname-export.nix: Exports hostname as environment variable
- vm-hostname-setter.nix: Sets actual VM hostname from shared file
- Virtiofs share (/persist/common -> /etc/common) propagates to VMs
- NetworkManager hostname-mode set to 'none' to prevent override
- Replaces generate-device-id service from microvm-host.nix with single atomic operation
- Uses writeShellApplication for better error handling and shellcheck validation
- Code refactored with inherit (lib) for cleaner imports
- Uses sysfs directly instead of iproute2 for MAC address reading
Configuration options:
- source = "hardware": Best-effort detection (DMI <E2><86><92> disk UUID <E2><86><92> MAC <E2><86><92> machine-id)
- source = "static": User-provided value via staticValue option
- source = "random": Random value generated once and persisted
Technical details:
- Hostname: ghaf-NNNNNNNNNN (10-digit CRC32-based hardware ID)
- Device-id: Hardware ID formatted as hex string (e.g., 00-01-23-45-67)
- Machine-ids: MD5 hash of hardware key + VM name (deterministic, not random)
- Service runs before network-online.target for DHCP client identification
- All identity files generated atomically in single service execution
- Same hardware always produces same hostname, device-id, and machine-ids
- Each VM gets unique but deterministic machine-id
Use cases:
- DHCP client identification with unique device names
- Network troubleshooting and device tracking
- Logging and monitoring across host and VMs
- User visibility of hardware instance identity
- Deterministic device identification across reboots
- Reproducible VM identities for testing and automation
- Privacy-focused deployments with random mode
- Testing environments with static mode
Documentation added at docs/src/content/docs/ghaf/dev/ref/dynamic-hostname.mdx
Signed-off-by: Vadim Likholetov <vadikas@gmail.com>
bd226aa to
d23fadb
Compare
|
Tested on Darter Pro (new image)
|



Implement runtime-generated, human-readable hostnames derived from
permanent hardware properties (DMI serial/UUID, MAC address, or
machine-id). The hostname format is 'ghaf-NNNNNNNNNN' where N is a
10-digit number deterministically generated from hardware properties.
Key features:
Implementation:
Technical details:
Use cases:
Documentation added at docs/src/content/docs/ghaf/dev/ref/dynamic-hostname.mdx
Description of Changes
Type of Change
Related Issues / Tickets
Checklist
make-checksand it passesTesting Instructions
Applicable Targets
aarch64aarch64x86_64x86_64x86_64Installation Method
nixos-rebuild ... switchTest Steps To Verify:
Testing Instructions: Dynamic Hostname Generation
Overview
This commit adds hardware-based dynamic hostname generation for Ghaf hosts and VMs. Test the following scenarios to ensure proper functionality.
Test 1: Basic Hostname Generation (Hardware Mode)
Setup
Build and deploy a Ghaf system with default configuration.
Steps
ghaf-NNNNNNNNNN(10 digits)hostname # Should show "ghaf-host"Expected Results
/run/ghaf-hostnamecontains hostname likeghaf-1234567890$GHAF_HOSTNAMEenvironment variable is setghaf-host(not changed)/persist/common/ghaf/Test 2: VM Hostname Propagation
Steps
Expected Results
$GHAF_HOSTNAMEset, but actual hostname remainsgui-vm/etc/common/ghaf/hostnameTest 3: Deterministic Behavior
Steps
cat /run/ghaf-hostnameExpected Results
Test 4: Device ID Generation
Steps
XX-XX-XX-XX-XXExpected Results
Test 5: VM Machine IDs
Steps
Expected Results
Test 6: DHCP Client Identification
Steps
journalctl -u NetworkManager | grep -i hostnameghaf-NNNNNNNNNNExpected Results
Test 7: Static Mode Configuration
Setup
Configure system with static hardware ID:
Steps
Expected Results
ghaf-NNNNNNNNNNTest 8: Random Mode Configuration
Setup
Configure with random ID generation:
Steps
Expected Results
Test 9: Custom Prefix and Digits
Setup
Configure with custom parameters:
Steps
Expected Results
test-NNNNNN(6 digits)Test 10: Hardware Detection Priority
Steps
Expected Results
Test 11: Cross-VM Communication
Steps
Expected Results
$GHAF_HOSTNAMEvalue