lxc / distrobuilder

System container image builder for LXC and Incus
https://linuxcontainers.org
Apache License 2.0
584 stars 168 forks source link

CentOS image missing some packages to boot successfully #122

Closed floschmied closed 5 years ago

floschmied commented 5 years ago

Hi,

two days ago, I have followed the howto to build distrobuilder and make my own centos 7.5 image. I needed 7.5, because the application I want to install is not yet compatible to 7.6...

Building the image was successfully, but it was not able to start. I got this error:

lxc info --show-log local:fschmid-centos-lxd-v1
Name: fschmid-centos-lxd-v1
Remote: unix://
Architecture: x86_64
Created: 2019/01/16 15:46 UTC
Status: Stopped
Type: persistent
Profiles: default

Log:

lxc fschmid-centos-lxd-v1 20190116154702.966 WARN     conf - conf.c:lxc_setup_devpts:1616 - Invalid argument - Failed to unmount old devpts instance
lxc fschmid-centos-lxd-v1 20190116154702.967 ERROR    start - start.c:start:2028 - No such file or directory - Failed to exec "/sbin/init"
lxc fschmid-centos-lxd-v1 20190116154702.967 ERROR    sync - sync.c:__sync_wait:62 - An error occurred in another process (expected sequence number 7)
lxc fschmid-centos-lxd-v1 20190116154702.967 WARN     network - network.c:lxc_delete_network_priv:2589 - Operation not permitted - Failed to remove interface "eth0" with index 20
lxc fschmid-centos-lxd-v1 20190116154702.967 ERROR    lxccontainer - lxccontainer.c:wait_on_daemonized_start:842 - Received container state "ABORTING" instead of "RUNNING"
lxc fschmid-centos-lxd-v1 20190116154702.967 ERROR    start - start.c:__lxc_start:1939 - Failed to spawn container "fschmid-centos-lxd-v1"
lxc 20190116154702.972 WARN     commands - commands.c:lxc_cmd_rsp_recv:132 - Connection reset by peer - Failed to receive response for command "get_state"

My second problem: After fixing first issue, I saw, that the image is missing two important templates:

Here is my centos.yaml file:

image:
  distribution: centos
  release: 7
  variant: Minimal
  description: CentOS {{ image.release }}
  expiry: 3000d
  architecture: x86_64

source:
  downloader: centos-http
  url: http://ownrepo/prod/centos/
  keys:
    - 24C6A8A7F4A80EB5
    - 0946FCA2C105B9DE
  variant: Minimal
#  variant: default
  skip_verification: true

targets:
  lxc:
    create-message: |
        You just created a CentOS container (release={{ image.release }}, arch={{ image.architecture }})

    config:
      - type: all
        before: 5
        content: |-
          lxc.include = LXC_TEMPLATE_CONFIG/centos.common.conf

      - type: user
        before: 5
        content: |-
          lxc.include = LXC_TEMPLATE_CONFIG/centos.userns.conf

      - type: all
        after: 4
        content: |-
          lxc.include = LXC_TEMPLATE_CONFIG/common.conf

      - type: user
        after: 4
        content: |-
          lxc.include = LXC_TEMPLATE_CONFIG/userns.conf

      - type: all
        content: |-
          lxc.arch = {{ image.architecture_kernel }}

files:
 - name: hostname
   path: /etc/hostname
   generator: hostname

 - name: hosts
   path: /etc/hosts
   generator: hosts

packages:
    manager: yum

    update: false
    cleanup: true

My fix for the first problem (image is not bootable):

197 yum --installroot=/rootfs --disablerepo=* --enablerepo=cdrom -y --releasever=%s install basesystem centos-release yum systemd binutils crontabs dhclient glibc-common iputils json logrotate openssh-clients openssh-server passwd rpm-python rsyslog tzdata vim-minimal policycoreutils json-c audit authconfig file postfix gettext net-tools rootfiles

Maybe not all of them are necessary, but most of them are. At least systemd was missing

My fix for the second problem (no networing inside contianer):

With this, I also have networking inside the container.

What I have seen, is, that there have been quite a lot changes in the last two weeks to these files:

BR Florian Schmid

stgraber commented 5 years ago

https://github.com/lxc/lxc-ci/blob/master/images/centos.yaml

That's what we use for the official images. @monstermunchkin may want to tweak the examples a bit.

monstermunchkin commented 5 years ago

Yes, I can tweak the example and fix networking in the container.

I don't have access to a CentOS 7.5 image, but a CentOS 7.6 image boots perfectly without having to change anything.

floschmied commented 5 years ago

Hi,

Stéphane, thank you very much for that link. Yes, this file looks a way better than the default one. I will test it, if it is working for me for CentOS 7.5.

Thomas, which centos.yaml file have you used for CentOS 7.6? The one from distrobuilder or the one from Stéphanes link?

monstermunchkin commented 5 years ago

I used the CentOS example we provide, but added systemd to the package list. You're right, that it doesn't boot without it. I'll fix that.

Using the yaml file we use for our official images, everything works. It boots and provides networking.

I will also update our example to make networking work out of the box.

floschmied commented 5 years ago

Hi Thomas,

thank you very much!

Perhaps you can help me with one more issue I have? I want to inject our own CentOS repository before the packages will be installed in yaml file or packages should be used from CD-Rom, but it should not be installed from internet repo. I have tried with trigger pre-packages, but this is not available.

Is there a possibility to do this?

monstermunchkin commented 5 years ago

Yes, there is a kind of pre-packages trigger called post-unpack. Perhaps that's what you're looking for.

floschmied commented 5 years ago

Hi,

thank you very much. That worked!