No hostname file created for rockylinux instance

Hello
I noticed that rocky linux containers (8, 8/cloud, 9, 9/cloud) created with incus 0.6 on my debian 12 host don’t come with /etc/hostname file.
On my other incus hosts (arch linux / incus 0.6 and fedora 39 / incus 0.5.1), the file is correctly created.
Incus config is the same on all my hosts.
Does anyone have the same issue?

Here is the cloudinit ouput

$ cloud-init status -l
status: error
boot_status_code: enabled-by-generator
last_update: Thu, 29 Feb 2024 18:03:28 +0000
detail:
('set_hostname', SetHostnameError("Failed to set the hostname to qp (qp): Unexpected error while running command.\nCommand: ['hostnamectl', 'set-hostname', 'qp']\nExit code: 1\nReason: -\nStdout: \nStderr: Could not set pretty hostname: Could not activate remote peer."))

Regards

1 Like

It’s weird. There is supposed to be a /etc/hostname file.

1 Like

After more research, I found out that systemd-hostnamed.service is crashing

× systemd-hostnamed.service - Hostname Service
     Loaded: loaded (/usr/lib/systemd/system/systemd-hostnamed.service; static)
    Drop-In: /usr/lib/systemd/system/systemd-hostnamed.service.d
             └─disable-privatedevices.conf
             /run/systemd/system/service.d
             └─zzz-lxc-service.conf
     Active: failed (Result: exit-code) since Fri 2024-03-01 09:33:20 UTC; 9s ago
       Docs: man:systemd-hostnamed.service(8)
             man:hostname(5)
             man:machine-info(5)
             man:org.freedesktop.resolve1(5)
    Process: 869 ExecStart=/usr/lib/systemd/systemd-hostnamed (code=exited, status=225/NETWORK)
   Main PID: 869 (code=exited, status=225/NETWORK)
        CPU: 857us

Mar 01 09:33:20 testtestq systemd[869]: systemd-hostnamed.service: Failed to set up network namespacing: Permission denied
Mar 01 09:33:20 testtestq systemd[869]: systemd-hostnamed.service: Failed at step NETWORK spawning /usr/lib/systemd/systemd-hostnamed: Permission denied
Mar 01 09:33:20 testtestq systemd[1]: Starting Hostname Service...
Mar 01 09:33:20 testtestq systemd[1]: systemd-hostnamed.service: Main process exited, code=exited, status=225/NETWORK
Mar 01 09:33:20 testtestq systemd[1]: systemd-hostnamed.service: Failed with result 'exit-code'.
Mar 01 09:33:20 testtestq systemd[1]: Failed to start Hostname Service.

As described in this issue Services configured with `PrivateNetwork=yes` fail to start in containers · Issue #29526 · systemd/systemd · GitHub, the unit works fine when using PrivateNetwork=no instead of PrivateNetwork=yes in systemd-hostnamed.service, and the command hostnamectl set-hostname xxx execute successfully after that.

1 Like

I’m hitting the same issue as you on a Debian 12.6 incus host:

kim@debian:~$ incus launch images:rockylinux/9/cloud r9c
kim@debian:~$ incus exec r9c -- cloud-init status -l
status: error
extended_status: error
boot_status_code: enabled-by-generator
last_update: Mon, 01 Jul 2024 02:56:03 +0000
detail:
DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]
errors:
        - ('set_hostname', SetHostnameError("Failed to set the hostname to r9c (r9c): Unexpected error while running command.\nCommand: ['hostnamectl', 'set-hostname', 'r9c']\nExit code: 1\nReason: -\nStdout: \nStderr: Could not set pretty hostname: Could not activate remote peer."))
recoverable_errors:
WARNING:
        - Failed to set the hostname to r9c (r9c)
        - Unable to get zpool status of default: Unexpected error while running command. Command: ['zpool', 'status', 'default'] Exit code: - Reason: [Errno 2] No such file or directory: b'zpool' Stdout: - Stderr: -
        - Failed to set the hostname to r9c (r9c)
        - Running module set_hostname (<module 'cloudinit.config.cc_set_hostname' from '/usr/lib/python3.9/site-packages/cloudinit/config/cc_set_hostname.py'>) failed
        - Failed to set the hostname to r9c (r9c)

A rockylinux/8/cloud instance also has the same error but a debian/12/cloud instance works fine.

Yet on another system, a Ubuntu 22.04 incus host it works fine.

kim@ubuntu:~$ incus launch images:rockylinux/9/cloud r9c
kim@ubuntu:~$ incus exec r2 -- cloud-init status -l
status: done
extended_status: done
boot_status_code: enabled-by-generator
last_update: Mon, 01 Jul 2024 03:10:08 +0000
detail:
DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]
errors: []
recoverable_errors: {}

Also working on another Debian 12.5 WSL system:

kim@deb2:~$ incus launch images:rockylinux/9/cloud r3
Launching r3
kim@deb2:~$ incus exec r3 -- cloud-init status -l
status: done
extended_status: done
boot_status_code: enabled-by-generator
last_update: Mon, 01 Jul 2024 03:21:26 +0000
detail:
DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]
errors: []
recoverable_errors: {}

On yet another Debian 12 system it’s not working but I found it does work after the instance is restarted:

kim@cube:~$ incus launch images:rockylinux/9/cloud r9c
Launching r9c
kim@cube:~$ incus exec r9c -- cloud-init status -l
status: error
extended_status: error
boot_status_code: enabled-by-generator
last_update: Mon, 01 Jul 2024 04:49:54 +0000
detail:
DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]
errors:
	- ('set_hostname', SetHostnameError("Failed to set the hostname to r9c (r9c): Unexpected error while running command.\nCommand: ['hostnamectl', 'set-hostname', 'r9c']\nExit code: 1\nReason: -\nStdout: \nStderr: Could not set pretty hostname: Could not activate remote peer."))
recoverable_errors:
WARNING:
	- Failed to set the hostname to r9c (r9c)
	- Failed to set the hostname to r9c (r9c)
	- Running module set_hostname (<module 'cloudinit.config.cc_set_hostname' from '/usr/lib/python3.9/site-packages/cloudinit/config/cc_set_hostname.py'>) failed
	- Failed to set the hostname to r9c (r9c)
kim@cube:~$ incus restart r9c
kim@cube:~$ incus exec r9c -- cloud-init status -l
status: running
extended_status: degraded running
boot_status_code: enabled-by-generator
last_update: Mon, 01 Jul 2024 04:50:15 +0000
detail:
Running in stage: init
errors: []
recoverable_errors:
WARNING:
	- Failed to set the hostname to r9c (r9c)

In my use case I wait for cloud-init status to be done before running further automated tests. So on the debian and cube hosts this is broken, but it works on the debian wsl host (deb2).

Disabling apparmor before starting the instance seems to work:

kim@cube:~$ incus init images:rockylinux/9/cloud r9
Creating r9
kim@cube:~$ incus config set r9 raw.lxc lxc.apparmor.profile=unconfined
kim@cube:~$ incus start r9
kim@cube:~$ incus exec r9 -- cloud-init status -l
status: done
extended_status: done
boot_status_code: enabled-by-generator
last_update: Mon, 01 Jul 2024 05:57:10 +0000
detail:
DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]
errors: []
recoverable_errors: {}

So does that mean something in the apparmor profile is blocking hostnamectl with the debian kernel (6.1.0-22-amd64) but not with the WSL2 kernel (5.15.153.1-microsoft-standard-WSL2) or the ubuntu kernel (6.2.0-39-generic)?

I tried a newer kernel from GitHub - zabbly/linux: Linux kernel builds and that seems to have solved the issue for me:

kim@cube:~$ incus launch images:rockylinux/9/cloud r9
Launching r9
kim@cube:~$ incus exec r9 -- cloud-init status -l
status: running
extended_status: running
boot_status_code: enabled-by-generator
last_update: Mon, 01 Jul 2024 11:36:43 +0000
detail:
Running in stage: init
errors: []
recoverable_errors: {}
kim@cube:~$ uname -a
Linux cube 6.9.7-zabbly+ #debian12 SMP PREEMPT_DYNAMIC Fri Jun 28 19:34:34 UTC 2024 x86_64 GNU/Linux