Freshly created RHEL 7 image (tar.gz) does not get IPv4 through DHCP

I utilize centos7 images on the ubuntu host, and they all work fine. Any time an image is started up, it gets IPv4 automatically.

But: I had just CREATED a FRESH RHEL 7 image, through a small script by building everything onto a rootfs and creating a .tar.gz at the end. When this is imported, this container / snapshot does NOT get the IPv4 address on ‘lxc start or import’. It does seem to get the IPv6 on ‘lxc start or import’.

So, my solution was 'lxc exec $NAME – dhclient` , which then assigns a new IP address.

Is there a cleaner way to have the RHEL container created where it automatically gets the IPv4 renewed? (Metadata and just a miniscule templates directory files are attached)

PS: lxc network get lxdbr0 ipv4.dhcp was default, and I had manually set it to true.
Also:
lxc profile show default ==> outputs this::
config: {}
description: Default LXD profile
devices:
eth0:
name: eth0
nictype: bridged
parent: lxdbr0
type: nic
root:
path: /
pool: default
type: disk
name: default
used_by:

  • /1.0/containers/sut-781
  • /1.0/containers/sut-18340

This is what I see:
±------------------±--------±---------------------±----------------------------------------------±-----------±----------+
| sut-18340 | RUNNING | 10.38.207.241 (eth0) | fd42:f21a:8d11:f9df:216:3eff:fe4d:d209 (eth0) | PERSISTENT | 1 |
±------------------±--------±---------------------±----------------------------------------------±-----------±----------+
| sut-781 | RUNNING | | fd42:f21a:8d11:f9df:216:3eff:fe98:d301 (eth0) | PERSISTENT | 0 |
±------------------±--------±---------------------±----------------------------------------------±-----------±–

The metadata.yaml file is:
architecture: “x86_64”
creation_date: REPLACE_EPOCH_TIME
properties:
architecture: “x86_64”
description: “Red Hat Enterprise Linux release 7.8”
os: “redhat”
release: “7”

cat templates/hosts.tpl
127.0.1.1 {{ container.name }}
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

cat templates/ifcfg-eth0.lxd.tpl
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
HOSTNAME={{ container.name }}
NM_CONTROLLED=no
TYPE=Ethernet
MTU=
DHCP_HOSTNAME={{ container.name }}

cat templates/network.lxd.tpl
NETWORKING=yes
HOSTNAME={{ container.name }}

Your metadata.yaml doesn’t seem to be pointing to the templates so presumably nothing applies them on boot.

Note that we also have some workarounds on some centos versions where we need to bring down eth0 on startup.

SOLVED.
This is useful for creating a RHEL 7.8.

Thank you, Stephane
This is the full metadata.yaml file that was useful:

architecture: x86_64
creation_date: REPLACE_EPOCH_TIME
properties:
  architecture: x86_64
  description: Red Hat Enterprise Linux release 7.8
  os: redhat
  release: "7"
templates:
  /etc/hosts:
    when:
    - create
    - copy
    create_only: false
    template: hosts.tpl
    properties: {}
  /etc/sysconfig/network:
    when:
    - create
    - copy
    create_only: false
    template: network.lxd.tpl
    properties: {}
  /etc/sysconfig/network-scripts/ifcfg-eth0:
    when:
    - create
    - copy
    create_only: false
    template: ifcfg-eth0.lxd.tpl
    properties: {}

As a post solution, since I was dealing with RHEL, I had to do a few more steps to get the RHEL subscribed and users added as well.

Example lxc exec MY_CONTAINER -- bash:

subscription-manager register --activationkey=MY_KEY --org=XXXX  # You can replace with your own RHEL subscription-manager
subscription-manager attach --auto
useradd bala
chmod +w /etc/sudoers
echo "bala        ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers

su - bala    # This is just to test it works.

After this, I was able to create a final tar.gz file: using lxc snapshot / publish / export:

lxc snapshot myRunningSUT rhelactivatedanduseraddedsnapshot
lxc publish myRunningSUT/rhelactivatedanduseraddedsnapshot --alias myexport
lxc image export myexport .
lxc image delete myexport

This should be helpful for posterity.

1 Like