dd: clear machine-id and disable MAC derivation to prevent connectivity loss#562
dd: clear machine-id and disable MAC derivation to prevent connectivity loss#562kelryry wants to merge 3 commits into
Conversation
…ty loss systemd's default MACAddressPolicy=persistent derives a stable MAC from machine-id + interface name. DD images carry the source machine's machine-id, causing the target NIC MAC to change. This breaks VPS providers using ebtables/MAC binding and causes incorrect DHCPv6 DUID and IPv6 SLAAC addresses. Fix: 1. Clear machine-id (set to "uninitialized") so systemd regenerates on first boot 2. Create 99-default.link with MACAddressPolicy=none to keep hardware MAC Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello @kelryry, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves critical network connectivity issues that arise when using DD images or Debian preseed installations. The problem stems from Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request correctly addresses the issue of MAC address derivation from machine-id in DD images by clearing the machine-id and setting MACAddressPolicy=none. This prevents connectivity loss on VPS providers that use MAC binding. The implementation covers both DD imaging in trans.sh and fresh Debian installations in debian.cfg. I have provided some feedback regarding the robustness of the root directory detection in trans.sh and suggested adding consistency to the cleanup process in debian.cfg.
| if etc_dir=$({ ls -d /os/etc/ || ls -d /os/*/etc/; } 2>/dev/null); then | ||
| os_dir=$(dirname $etc_dir) |
There was a problem hiding this comment.
The variable etc_dir can contain multiple lines if multiple etc directories are found within the partition (e.g., in different subvolumes or nested containers). Since BusyBox dirname does not support multiple arguments, it will fail and return an empty string for os_dir. This would cause subsequent commands to incorrectly target the Live OS root instead of the intended partition. Using head -n1 ensures only one path is processed, and quoting the variable prevents word splitting issues.
| if etc_dir=$({ ls -d /os/etc/ || ls -d /os/*/etc/; } 2>/dev/null); then | |
| os_dir=$(dirname $etc_dir) | |
| if etc_dir=$({ ls -d /os/etc/ || ls -d /os/*/etc/; } 2>/dev/null | head -n1); then | |
| os_dir=$(dirname "$etc_dir") |
| in-target systemctl enable fix-eth-name | ||
| in-target systemctl enable fix-eth-name; \ | ||
|
|
||
| echo uninitialized >/target/etc/machine-id; \ |
There was a problem hiding this comment.
For consistency with the clear_machine_id function used in trans.sh, it is recommended to also remove the random-seed file. This ensures that the entropy pool is uniquely initialized on the first boot of the new system.
echo uninitialized >/target/etc/machine-id; \
rm -f /target/var/lib/systemd/random-seed; \
- trans.sh: add head -n1 to etc_dir detection to handle multiple results, quote dirname argument to prevent word splitting - debian.cfg: also remove random-seed for consistency with clear_machine_id Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
不建议按照这种方式直接注入修改systemd的业务 或者可以考虑opt-in的方式让用户选择 |
Address review feedback: DD should not modify disk contents by default. Add --reset-machine-id flag so users can opt-in to clearing machine-id and disabling MAC address derivation. Update README docs accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
已根据反馈将 machine-id 清理改为 opt-in 方式:
用法示例: bash reinstall.sh dd --img "https://example.com/xxx.xz" --reset-machine-id |
有没有商家例子?
同样有没有商家例子? |
|
https://www.freedesktop.org/software/systemd/man/latest/systemd.link.html#MACAddressPolicy=
按我的理解,网卡有 MAC 地址,即使是 persistent ,也会使用网卡的 MAC 地址 |
a55a3a1 to
c784479
Compare
190f36d to
047b82a
Compare
569101f to
139c342
Compare
问题 / Problem
systemd 默认的
MACAddressPolicy=persistent会根据machine-id和网卡名派生出一个稳定的 MAC 地址,覆盖硬件真实 MAC。DD 镜像携带了源机器的machine-id,导致目标机器的网卡 MAC 被改变。systemd's default
MACAddressPolicy=persistentderives a stable MAC address frommachine-id+ interface name, overriding the hardware MAC. A DD image carries the source machine'smachine-id, causing the target NIC MAC to change.影响 / Impact
使用 ebtables/MAC 绑定的 VPS 商家会因为 MAC 地址变化而导致 DD 后失联
即使没有 MAC 绑定,错误的
machine-id也会导致 DHCPv6 DUID 和 IPv6 SLAAC 地址异常VPS providers using ebtables/MAC binding will lose connectivity after DD because the MAC address changed
Even without MAC binding, a wrong
machine-idcauses incorrect DHCPv6 DUID and IPv6 SLAAC addresses修复 / Fix
machine-id(设为uninitialized),让 systemd 首次启动时重新生成99-default.link设置MACAddressPolicy=none,禁止 systemd 派生 MAC 地址改动文件
trans.sh: DD 镜像的modify_os_on_disk阶段清除 machine-id 并创建 99-default.linkdebian.cfg: preseed late_command 阶段做同样处理