问题:
我正在尝试使用打包程序创建 Ubuntu Server 22.04 映像,但在使用有效的 netplan 配置重命名 NIC 并安装一个包时遇到了问题。
关于背景,有几点需要注意:
- 我正在重命名 NIC,因为我正在尝试使用 terraform 在启动时使用 proxmox 和 cloud-init 设置 NIC 配置。当 cloud-init 在克隆的映像上运行时,它似乎想要在第一次启动时重命名 NIC,并且由于它无法动态重命名 NIC(从 ens18 重命名为 eth0),因此需要第二次重新启动,然后 cloud-init 才能在 VM 上设置正确的 IP 地址。当我想使用 terraform 启动 ubuntu 服务器时,这并不理想,因为它需要手动重新启动。
我对 Proxmox 和它为以下操作系统提供的 cloud-init 驱动器/配置设置没有任何问题:
- AlmaLinux 8 和 9
- RHEL 7、8 和 9
- Windows Server 2012、2016、2019 和 2022 (Cloudbase-init)
它们似乎都接受了 terraform 发送给 proxmox 使用的 cloud-init 配置,一切就绪了。所有这些都表明 proxmox 可能不应该重命名 NIC,但 Ubuntu Server 是我遇到此问题的第一个操作系统,目前我并没有在 Ubuntu 之外寻找其他解决方案。
- 我需要
qemu-guest-agent
在 VM 上安装,以便打包程序能够从 Proxmox API 中读取 IP 地址,从而知道要连接到谁。
具体内容:
qemu-guest-agent
如果我不指定任何网络设置并让 subiquity/netplan 提供默认值,我就可以安装。当我这样做时,成功自动安装的最终autoinstall-user-data
位置/var/log/installer
显示以下网络和包配置:
autoinstall:
<snipped>
network:
ethernets:
ens18:
dhcp4: true
version: 2
packages:
- qemu-guest-agent
<snipped>
- 我可以使用 subiquity/netplan 成功重命名 NIC。完成后,无法安装 qemu-guest-agent 并导致构建过程失败。这是我为此使用的配置:
network:
ethernets:
ens18:
match:
driver: e1000
dhcp4: true
set-name: eth0
version: 2
packages:
- qemu-guest-agent
上述network:
代码块确实成功地将 NIC 重命名为 eth0,并且我在损坏的安装上拥有完整的网络。我可以 ping google.com 之类的东西,也可以通过 SSH 进入机器。我可以从日志中看到重命名成功,当它弹出 shell 时,我可以验证失败安装上的新 NIC 名称。
以下是 NIC 重命名后遇到的错误。
从subiquity-server-debug.log.1976
:
2022-09-04 07:21:30,557 DEBUG root:39 start: subiquity/Install/install/postinstall/install_qemu-guest-agent: installing qemu-guest-agent
2022-09-04 07:21:30,560 DEBUG subiquitycore.utils:112 astart_command called: ['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1976', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}', 'system-install', '-t', '/target', '--', 'qemu-guest-agent']
2022-09-04 07:21:30,570 INFO root:39 start: subiquity/Meta/status_GET:
2022-09-04 07:21:31,706 DEBUG root:39 start: subiquity/Install/install/postinstall/install_qemu-guest-agent/cmd-system-install: curtin command system-install
2022-09-04 07:21:31,826 ERROR root:39 finish: subiquity/Install/install/postinstall/install_qemu-guest-agent: FAIL: Command '['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1976', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}', 'system-install', '-t', '/target', '--', 'qemu-guest-agent']' returned non-zero exit status 100.
2022-09-04 07:21:31,833 ERROR root:39 finish: subiquity/Install/install/postinstall: FAIL: Command '['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1976', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}', 'system-install', '-t', '/target', '--', 'qemu-guest-agent']' returned non-zero exit status 100.
2022-09-04 07:21:31,834 DEBUG subiquitycore.common.errorreport:384 generating crash report
2022-09-04 07:21:31,872 INFO subiquitycore.common.errorreport:406 saving crash report 'install failed crashed with CalledProcessError' to /var/crash/1662276091.834314585.install_fail.crash
2022-09-04 07:21:31,873 ERROR root:39 finish: subiquity/Install/install: FAIL: Command '['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1976', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}', 'system-install', '-t', '/target', '--', 'qemu-guest-agent']' returned non-zero exit status 100.
2022-09-04 07:21:31,875 INFO root:39 start: subiquity/ErrorReporter/1662276091.834314585.install_fail/add_info:
2022-09-04 07:21:31,876 ERROR subiquity.server.server:416 top level error
Traceback (most recent call last):
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/cmdlist.py", line 104, in _run
await Install.install_task
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquitycore/context.py", line 148, in decorated_async
return await meth(self, **kw)
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/install.py", line 177, in install
await self.postinstall(context=context)
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquitycore/context.py", line 148, in decorated_async
return await meth(self, **kw)
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/install.py", line 200, in postinstall
await self.install_package(context=context, package=package)
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquitycore/context.py", line 148, in decorated_async
return await meth(self, **kw)
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/install.py", line 227, in install_package
await run_curtin_command(
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/curtin.py", line 181, in run_curtin_command
return await cmd.wait()
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/curtin.py", line 118, in wait
result = await self.runner.wait(self.proc)
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/runner.py", line 81, in wait
raise subprocess.CalledProcessError(proc.returncode, proc.args)
subprocess.CalledProcessError: Command '['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1976', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}', 'system-install', '-t', '/target', '--', 'qemu-guest-agent']' returned non-zero exit status 100.
2022-09-04 07:21:31,877 ERROR subiquity.server.server:416 top level error
Traceback (most recent call last):
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/shutdown.py", line 77, in _wait_install
await self.app.controllers.Install.install_task
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/cmdlist.py", line 104, in _run
await Install.install_task
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquitycore/context.py", line 148, in decorated_async
return await meth(self, **kw)
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/install.py", line 177, in install
await self.postinstall(context=context)
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquitycore/context.py", line 148, in decorated_async
return await meth(self, **kw)
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/install.py", line 200, in postinstall
await self.install_package(context=context, package=package)
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquitycore/context.py", line 148, in decorated_async
return await meth(self, **kw)
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/controllers/install.py", line 227, in install_package
await run_curtin_command(
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/curtin.py", line 181, in run_curtin_command
return await cmd.wait()
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/curtin.py", line 118, in wait
result = await self.runner.wait(self.proc)
File "/snap/subiquity/3698/lib/python3.8/site-packages/subiquity/server/runner.py", line 81, in wait
raise subprocess.CalledProcessError(proc.returncode, proc.args)
subprocess.CalledProcessError: Command '['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1976', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}', 'system-install', '-t', '/target', '--', 'qemu-guest-agent']' returned non-zero exit status 100.
2022-09-04 07:21:32,072 ERROR root:39 finish: subiquity/Install/install/postinstall/install_qemu-guest-agent/cmd-system-install: FAIL: curtin command system-install
2022-09-04 07:21:32,594 INFO root:39 finish: subiquity/ErrorReporter/1662276091.834314585.install_fail/add_info: SUCCESS: written to /var/crash/1662276091.834314585.install_fail.crash
2022-09-04 07:21:32,596 INFO root:39 finish: subiquity/Meta/status_GET: SUCCESS: 200 {"state": "ERROR", "confirming_tty": "", "error": {"state": "DONE", "base": "...
2022-09-04 07:21:32,599 INFO aiohttp.access:233 [04/Sep/2022:07:21:30 +0000] "GET /meta/status?cur=%22POST_RUNNING%22 HTTP/1.1" 200 524 "-" "Python/3.8 aiohttp/3.6.2"
如果我手动从失败日志中运行命令:
systemd-run --wait --same-dir --property SyslogIdentifier=subiquity_log.1976 --setenv PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin --setenv PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages --setenv PYTHON=/snap/subiquity/3698/usr/bin/python3.8 --setenv SNAP=/snap/subiquity/3698 -- /snap/subiquity/3698/usr/bin/python3.8 -m curtin --showtrace -vvvvvv --set json:reporting='{"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}}' system-install -t /target -- qemu-guest-agent
我可以在系统日志中看到以下内容:
Sep 4 07:31:18 ubuntu-server systemd[1]: Started /snap/subiquity/3698/usr/bin/python3.8 -m curtin --showtrace -vvvvvv --set json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1976.5"}} system-install -t /target -- qemu-guest-agent.
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: start: cmd-system-install: curtin command system-install
Sep 4 07:31:19 ubuntu-server curtin_event.1976.5[16331]: start: cmd-system-install: curtin command system-install
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--bind', '/dev', '/target/dev'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--bind', '/proc', '/target/proc'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--bind', '/run', '/target/run'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--bind', '/sys', '/target/sys'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['unshare', '--help'] with allowed return codes [0] (capture=True)
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['unshare', '--fork', '--pid', '--', 'chroot', '/target', 'eatmydata', 'apt-get', '--quiet', '--assume-yes', '--option=Dpkg::options::=--force-unsafe-io', '--option=Dpkg::Options::=--force-confold', 'install', 'qemu-guest-agent'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16342]: Reading package lists...
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16342]: Building dependency tree...
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16342]: Reading state information...
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16342]: E: Unable to locate package qemu-guest-agent
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['udevadm', 'settle'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: TIMED subp(['udevadm', 'settle']): 0.028
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--make-private', '/target/sys'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['umount', '/target/sys'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--make-private', '/target/run'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server systemd[1]: target-sys.mount: Deactivated successfully.
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['umount', '/target/run'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--make-private', '/target/proc'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['umount', '/target/proc'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['mount', '--make-private', '/target/dev'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Running command ['umount', '/target/dev'] with allowed return codes [0] (capture=False)
Sep 4 07:31:19 ubuntu-server subiquity_event.1976[1976]: subiquity/Install/install/postinstall/install_qemu-guest-agent/cmd-system-install: curtin command system-install
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: system install failed for ['qemu-guest-agent']: Unexpected error while running command.
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Command: ['unshare', '--fork', '--pid', '--', 'chroot', '/target', 'eatmydata', 'apt-get', '--quiet', '--assume-yes', '--option=Dpkg::options::=--force-unsafe-io', '--option=Dpkg::Options::=--force-confold', 'install', 'qemu-guest-agent']
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Exit code: 100
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Reason: -
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Stdout: ''
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: Stderr: ''
Sep 4 07:31:19 ubuntu-server subiquity_log.1976[16331]: finish: cmd-system-install: FAIL: curtin command system-install
Sep 4 07:31:19 ubuntu-server curtin_event.1976.5[16331]: finish: cmd-system-install: FAIL: curtin command system-install
Sep 4 07:31:19 ubuntu-server systemd[1]: run-u70.service: Main process exited, code=exited, status=100/n/a
Sep 4 07:31:19 ubuntu-server systemd[1]: run-u70.service: Failed with result 'exit-code'.
Sep 4 07:31:19 ubuntu-server systemd[1]: run-u70.service: Consumed 1.595s CPU time.
Sep 4 07:31:20 ubuntu-server subiquity_event.1976[1976]: subiquity/Install/install/postinstall/install_qemu-guest-agent/cmd-system-install: curtin command system-install
Sep 4 07:31:20 ubuntu-server systemd[1]: target-run.mount: Deactivated successfully.
Sep 4 07:31:20 ubuntu-server systemd[1]: target-proc.mount: Deactivated successfully.
Sep 4 07:31:20 ubuntu-server systemd[1]: target-dev.mount: Deactivated successfully.
在自动安装中运行时无需重命名 NIC,此相同的步骤/配置即可成功:
2022-09-01 23:11:45,679 DEBUG root:39 start: subiquity/Install/install/postinstall/install_qemu-guest-agent: installing qemu-guest-agent
2022-09-01 23:11:45,988 DEBUG subiquitycore.utils:112 astart_command called: ['systemd-run', '--wait', '--same-dir', '--property', 'SyslogIdentifier=subiquity_log.1972', '--setenv', 'PATH=/snap/subiquity/3698/bin:/snap/subiquity/3698/usr/bin:/usr/local/s
bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/subiquity/3698/bin', '--setenv', 'PYTHONPATH=:/snap/subiquity/3698/lib/python3.8/site-packages', '--setenv', 'PYTHON=/snap/subiquity/3698/usr/bin/python3.8', '--
setenv', 'SNAP=/snap/subiquity/3698', '--', '/snap/subiquity/3698/usr/bin/python3.8', '-m', 'curtin', '--showtrace', '-vvv', '--set', 'json:reporting={"subiquity": {"type": "journald", "identifier": "curtin_event.1972.5"}}', 'system-install', '-t', '/tar
get', '--', 'qemu-guest-agent']
2022-09-01 23:11:46,031 INFO root:39 start: subiquity/Meta/status_GET:
2022-09-01 23:11:47,706 DEBUG root:39 start: subiquity/Install/install/postinstall/install_qemu-guest-agent/cmd-system-install: curtin command system-install
2022-09-01 23:11:56,394 DEBUG subiquity.server.curtin:123 waited 0.1 seconds for events to drain
2022-09-01 23:11:56,458 DEBUG root:39 finish: subiquity/Install/install/postinstall/install_qemu-guest-agent/cmd-system-install: SUCCESS: curtin command system-install
2022-09-01 23:11:56,496 DEBUG subiquity.server.curtin:123 waited 0.2 seconds for events to drain
2022-09-01 23:11:56,497 DEBUG root:39 finish: subiquity/Install/install/postinstall/install_qemu-guest-agent: SUCCESS: installing qemu-guest-agent
此时,我不太清楚为什么在 NIC 重命名后它无法找到包。此时我有点困惑,因为在看到 shell 后,虚拟机确实可以完全访问互联网。
任何形式的帮助/故障排除步骤都值得感激。很乐意提供我所能提供的任何信息。
答案1
我喜欢使用 配置网络late-commands
。
#cloud-config
autoinstall:
late-commands:
- |
rm /target/etc/netplan/00-installer-config.yaml
cat <<EOF > /target/etc/netplan/80-my.yaml
network:
ethernets:
ens18:
match:
driver: e1000
dhcp4: true
set-name: eth0
version: 2
EOF
怎么运行的
如果您的文件中没有network
配置块user-data
,则安装程序(下位性) 将要使用通用的 netplan 配置。 之后,下位性将为已安装的系统生成 netplan 配置,并将其用于安装程序环境。late-commands
您可以删除下位性生成的配置并将其替换为您想要的任何内容。这只会影响已安装的系统。
链接
答案2
我想为可能遇到类似问题的人添加更多信息。现在我已经解决了我的问题并知道问题出在哪里,我的主要帖子在某些方面是不正确的。
首先,Andrew 的回答将解决帖子中提出的问题。但在他的帖子的帮助下,我弄清楚了为什么我的 cloud-init 没有启动。
我最初查看的 cloud-init 日志中的某些内容使我认为无法使用 cloud-init 重命名 NIC,这就是我试图重命名 NIC 并遇到所有这些问题的原因。但这是错误的。
当我使用 Andrew 的配置启动克隆并重命名 NIC 时,我意识到它总是在提取 DHCP 配置,即使在连续重新启动之后也是如此。在进一步深入研究之后,我意识到 cloud-init 确实与 netplan 交互(这就是它与我列出的所有其他操作系统不同的原因)。
我发现这种情况发生在 cloud-init 上,表明它在某些情况下与 netplan 交互:
Sep 6 00:23:13 ubuntu22 cloud-init[773]: 2022-09-06 00:23:08,634 - util.py[DEBUG]: Writing to /etc/netplan/50-cloud-init.yaml - wb: [644] 695 bytes
Sep 6 00:23:13 ubuntu22 cloud-init[773]: 2022-09-06 00:23:08,636 - subp.py[DEBUG]: Running command ['netplan', 'generate'] with allowed return codes [0] (shell=False, capture=True)
Sep 6 00:23:13 ubuntu22 cloud-init[773]: 2022-09-06 00:23:09,030 - subp.py[DEBUG]: Running command ['udevadm', 'test-builtin', 'net_setup_link', '/sys/class/net/eth0'] with allowed return codes [0] (shell=False, capture=True)
Sep 6 00:23:13 ubuntu22 cloud-init[773]: 2022-09-06 00:23:09,049 - subp.py[DEBUG]: Running command ['udevadm', 'test-builtin', 'net_setup_link', '/sys/class/net/lo'] with allowed return codes [0] (shell=False, capture=True)
因此,为了让 cloud-init 正确设置网络配置,我最终需要删除内置安装程序 netplan 配置并重新安装/清理 cloud-init。以下是我使用 ansible 执行此操作的步骤:
- name: Run cloud-init clean
ansible.builtin.shell: cloud-init clean
when: ansible_distribution == "Ubuntu"
- name: Remove cloud-init
ansible.builtin.apt:
name: cloud-init
state: absent
when: ansible_distribution == "Ubuntu"
- name: Remove /etc/cloud
ansible.builtin.shell: rm -rf /etc/cloud
when: ansible_distribution == "Ubuntu"
- name: Remove /var/lib/cloud
ansible.builtin.shell: rm -rf /var/lib/cloud
when: ansible_distribution == "Ubuntu"
- name: Reboot the Ubuntu VM
ansible.builtin.reboot:
when: ansible_distribution == "Ubuntu"
- name: Install cloud-init
ansible.builtin.apt:
name: cloud-init
state: latest
when: ansible_distribution == "Ubuntu"
- name: Remove netplan file
ansible.builtin.shell: rm -f /etc/netplan/00-installer-config.yaml
when: ansible_distribution == "Ubuntu"
ignore_errors: yes
并且上面附带一个自动安装配置,它排除了network:
我认为需要的整个块(从而允许 subiquity 生成它)。
答案3
set timeout=10
if loadfont /boot/grub/fonts/font.pf2 ; then
set gfxmode=auto
insmod efi_gop
insmod efi_uga
insmod gfxterm
terminal_output gfxterm
fi
# background_image /boot/grub/image/splash.png
set menu_color_normal=white/black
set menu_color_highlight=black/light-red
menuentry "Install Ubuntu" {
set gfxpayload=keep
linux /casper/vmlinuz ip=dhcp cloud-config-url=/dev/null autoinstall ds="nocloud-net;s=http://xxx.xxx.xxx.xxx/autoinstall/" --- net.ifnames=0 biosdevname=0
initrd /casper/initrd
}
grub_platform
if [ "$grub_platform" = "efi" ]; then
menuentry 'Boot from next volume' {
exit 1
}
menuentry 'UEFI Firmware Settings' {
fwsetup
}
else
menuentry 'Test memory' {
linux16 /boot/memtest86+.bin
}
fi
在安装 grub 中,您的以太网卡将被命名为 eth0,并且带有“net.ifnames=0 biosdevname=0”