I’m building my first image with packer/qemu. It’s a simple config for Ubuntu server 20.04, taken from the examples. The build process succeeds, an image is created.
I can import the image with
virsh. The resulting VM boots ok, but its network doesn’t start. The reason is that during packer-build the VM enumerated the network as
ens3, but in my new VM the network is enumerated as
enp1s0. During the autoinstall on Ubuntu it created a
netplan configuration with
ens3 in it.
I can manually fix that of course, but that is not the point of an automated process to create images.
I’m quite puzzled how to find out how this network enumeration process works. There is some documentation but nowhere it explains where the
ens3) comes from. Knowing how the system comes up with the
s may be an important clue. Maybe I need to define PCI devices?
Does anyone recognize this problem?
BTW. There is a work-around and that it to add
boot_command. In that case both the builder and the final image will fall back to the old fashioned
The documentation you’re looking for is at PredictableNetworkInterfaceNames
In 2013, systemd and udev changed to default to predictable names for network interfaces. The lists below are from the linked page, which also describes why this solution was chosen and what problem it’s trying to solve.
Names are created using the following schemes.
- Names incorporating Firmware/BIOS provided index numbers for on-board devices (example:
- Names incorporating Firmware/BIOS provided PCI Express hotplug slot index numbers (example:
- Names incorporating physical/geographical location of the connector of the hardware (example:
- Names incorporating the interfaces’s MAC address (example:
- Classic, unpredictable kernel-native ethX naming (example:
If you don’t want this, there are three alternatives.
- You disable the assignment of fixed names, so that the unpredictable kernel names are used again. For this, simply mask udev’s .link file for the default policy:
ln -s /dev/null /etc/systemd/network/99-default.link
- You create your own manual naming scheme, for example by naming your interfaces “internet0”, “dmz0” or “lan0”. For that create your own .link files in /etc/systemd/network/, that choose an explicit name or a better naming scheme for one, some, or all of your interfaces. See systemd.link(5) for more information.
- You pass
net.ifnames=0 on the kernel command line
Like you, I chose option 3 as my VMs overwhelmingly use a single network interface and this keeps it simple.