【发布时间】:2019-12-07 15:19:28
【问题描述】:
我有一个使用 systemd 的基于 yocto 的嵌入式 Linux 系统。 U-Boot/coreboot 用于引导系统。 U-Boot 环境中存储有 IP 地址 ...
=> printenv ipaddr
ipaddr=192.168.0.100
...以及在 systemd 的 /lib/systemd/network/wired.network 中:
[Match]
Name=eth0
[Network]
Address=192.168.0.100/24
.
为了测试多个设备,我需要更改 IP 地址,因为多个设备同时连接到网络。
每次都更改 systemd 网络文件是不可取的,因为在更新后(使用完整的 rootfs 映像,以及 systemd 配置),它将被重置为默认值。 所以我的想法是通过内核命令行向 Linux 内核提供 U-Boot IP 地址,正如我之前在其他设备上看到的那样。 不幸的是,我无法在 systemd 上找到有关如何执行此操作的信息,我找到的所有示例都在 System V 上。
我的方法是增强原始(本例中为 NFS)启动 cmdline:
# cat /proc/cmdline
console=ttyS4,115200 rootwait rw loglevel=1 macaddress=02:00:00:FF:FF:FF root=/dev/nfs nfsroot=192.168.0.1:/srv/nfs/192.168.0.100,v3 ip=192.168.0.100:192.168.0.1:192.168.0.1:255.255.255.0::eth0:off
通过附加 systemd.setenv=ipaddr=192.168.0.100 或 ipaddr=192.168.0.100 之类的内容,并在 systemd 网络配置中引用此内容:
[Match]
Name=eth0
[Network]
Address=${ipaddr}/24
.
但是,这并没有显示出预期的结果,我所取得的只是一个系统挂起:
[ OK ] Started System Logger Daemon.
[ OK ] Started Network Service.
[ OK ] Started Login Service.
[ OK ] Started Resetting boot counter.
[ OK ] Started Bluetooth service.
[ OK ] Reached target Bluetooth.
[ OK ] Started Usermode Init Manager for TI Shared Transport line discipline.
**Starting Wait for Network to be Configured...**
[ OK ] Started Thermal Daemon Service.
Starting Hostname Service...
系统版本是:
systemd 234 -PAM -AUDIT -SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP -LIBCRYPTSETUP -GCRYPT -GNUTLS +ACL +XZ -LZ4 -SECCOMP +BLKID -ELFUTILS +KMOD -IDN2 -IDN default-hierarchy=hybrid
谁能告诉我,这是否可能?如果,如何排序?任何提示都会有所帮助。
【问题讨论】: