如何在安装前获取网络适配器的名称,并将其设置在自动安装程序配置文件中(Ubuntu 20.04)?

use*_*631 4 system-installation 20.04

network:
    network:
        version: 2
        ethernets:
            enp0s25:
               dhcp4: yes
Run Code Online (Sandbox Code Playgroud)

在安装之前我如何知道网络适配器的名称?不知道设备名称就可以只用mac吗?

And*_*her 8

如果您从自动安装配置中删除该network:部分,则会自动生成网络配置。这可能适合您的需求。

默认行为

网络配置过程非常混乱,但这就是当自动安装配置中没有部分时它的工作方式network:

1

在安装程序中,cloud-init有一个默认的通用网络规划配置,在未指定任何内容时使用该配置。此配置匹配所有物理接口。

# This is the initial network config.
# It can be overwritten by cloud-init or subiquity.
network:
    version: 2
    ethernets:
        zz-all-en:
            match:
                name: "en*"
            dhcp4: true
        zz-all-eth:
            match:
                name: "eth*"
            dhcp4: true
Run Code Online (Sandbox Code Playgroud)

2

实际接口详细信息已添加到安装程序文件系统中/etc/cloud/cloud.cfg.d/${IFNAME}.cfg。我相信casper正在将这个文件放置到位。

3

当安装程序启动时,cloud-init合并其配置以为安装程序环境创建 netplan 配置。我尝试过的测试虚拟机最终得到

# cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        ens192:
            critical: true
            dhcp-identifier: mac
            dhcp4: true
            nameservers:
                addresses:
                - REDACTED
                - REDACTED
                search:
                - REDACTED
        zz-all-en:
            dhcp4: true
            match:
                name: en*
        zz-all-eth:
            dhcp4: true
            match:
                name: eth*
    version: 2
Run Code Online (Sandbox Code Playgroud)

4

安装程序subiquity创建一个配置,curtin该配置仅包含与实际接口相关的安装程序 netplan 配置部分。

# cat /var/log/installer/subiquity-curtin-install.conf
...
write_files:
...
  etc_netplan_installer: {content: "# This is the network config written by 'subiquity'\n\
      network:\n  ethernets:\n    ens192:\n      critical: true\n      dhcp-identifier:\
      \ mac\n      dhcp4: true\n      nameservers:\n        addresses:\n        -\
      \ REDACTED\n        - REDACTED\n        search:\n        - REDACTED\n\
      \  version: 2\n", path: etc/netplan/00-installer-config.yaml}
...
Run Code Online (Sandbox Code Playgroud)

5

已安装的系统(位于/target)最终的配置为curtin

# cat /target/etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    ens192:
      critical: true
      dhcp-identifier: mac
      dhcp4: true
      nameservers:
        addresses:
        - REDACTED
        - REDACTED
        search:
        - REDACTED
  version: 2
Run Code Online (Sandbox Code Playgroud)

6

在某些时候,安装程序还会更改其自己的配置以使用已安装的配置。