在申请 dhcp 地址时使 initramfs 使用正确的主机名?

在申请 dhcp 地址时使 initramfs 使用正确的主机名?

我有一些带有加密根分区的 ubuntu 服务器,通常它们在启动时会在控制台上要求输入密码。为了远程启动它们,我在 initramfs 中使用 dropbear 通过 ssh 登录到 initramfs 进程。

问题:

一切正常,除了一个细节。当内核 + initramfs 进程请求 DHCP 地址时,它不使用机器的常规主机名(在启动过程中可能尚未设置),而是使用一个空名称。因此,ssh 客户端无法找到该机器并进行登录。

如果启动过程根本不使用主机名选项,则不会出现太大问题,允许 dhcp 服务器记住连接到此 MAC 地址和 IP 地址的最后一个主机名,但使用空主机名会替换真实主机名。

所以问题是:如何让 initramfs 使用正确的主机名?

不幸的是,文献中没有说明。

我找到了一个提示 https://realtechtalk.com/Howto_Set_Static_IP_on_boot_in_initramfs_for_dropbear_or_other_purposes_NFS_Linux_Debian_Ubuntu_CentOS-2278-articles

设置类似

IP=192.168.1.27::192.168.1.1:255.255.255.0:myhost.com

在 /etc/initramfs-tools/initramfs.conf 中会设置这个,但这是一个静态地址,而不是 dhcp 请求。但 /etc/initramfs-tools/initramfs.conf 没有记录这样的参数。

相反,有提示表明这是一个内核参数,通常用于 nfs 启动,如下所述:

https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt

Redhat 也有一些描述 https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/networking_guide/sec-configuring_ip_networking_from_the_kernel_command_line

但这与 dracut 有关,而不是 initramfs。

我的问题是:

在 dropbear 运行时,让 initramfs 使用正确的主机名进行 dhcp 请求的正确且 ubuntu 认可的方法是什么?

问候

相关内容