lxc: backport patch to enable systemd StateDirectory for lxc
PATCH 1/1 lxc: backport patch to enable systemd StateDirectory for lxc
Backport upstream patch to make sure lxc systemd service defines a StateDirectory to ensure that the /var/lib/lxc directory is automatically created and managed by systemd during service startup.
Do not create lxc directory at build time for systemd.
--- ...nable-systemd-StateDirectory-for-lxc.patch | 55 +++++++++++++++++++ recipes-containers/lxc/lxc_git.bb | 3 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 recipes-containers/lxc/files/0001-enable-systemd-StateDirectory-for-lxc.patch
recipes-containers/lxc/files/0001-enable-systemd-StateDirectory-for-lxc.patch new file +55 -0
@@ -0,0 +1,55 @@ +From c7bd5a3576f7449040e2164b6740c94cc2f5940c Mon Sep 17 00:00:00 2001 +From: Vishwas Udupa <[email protected]> +Date: Wed, 17 Sep 2025 03:56:09 -0700 +Subject: [PATCH] Enable systemd to create /var/lib/lxc at runtime +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Upstream-Status: Backport [https://github.com/lxc/lxc/commit/c7bd5a3] +Signed-off-by: Vishwas Udupa <[email protected]> +Co-developed-by: Raghuvarya S <[email protected]> + +This change adds the StateDirectory= directive in the systemd +unit file to ensure that the /var/lib/lxc directory is +automatically created and managed by systemd during service startup. + +The StateDirectory= option instructs systemd to create a persistent +state directory under /var/lib/. This is particularly useful in +scenarios where the directory may be missing at first boot — such as +on OSTree-based Linux distributions, which typically ship with +empty /var directory as part of their immutable root filesystem. + +By adding StateDirectory=lxc, systemd will handle the creation of +/var/lib/lxc on first boot, ensuring that the service can start +reliably even when the directory is not present initially. + +--- + config/init/systemd/lxc.service.in | 1 + + config/init/systemd/[email protected] | 1 + + 2 files changed, 2 insertions(+) + +diff --git a/config/init/systemd/lxc.service.in b/config/init/systemd/lxc.service.in +index 397a6c4d04..7142656178 100644 +--- a/config/init/systemd/lxc.service.in ++++ b/config/init/systemd/lxc.service.in +@@ -13,6 +13,7 @@ ExecStop=@LIBEXECDIR@/lxc/lxc-containers stop + ExecReload=@LIBEXECDIR@/lxc/lxc-apparmor-load + # Environment=BOOTUP=serial + # Environment=CONSOLETYPE=serial ++StateDirectory=lxc + Delegate=yes + + [Install] +diff --git a/config/init/systemd/[email protected] b/config/init/systemd/[email protected] +index 21ce64aefe..44e5b14dd2 100644 +--- a/config/init/systemd/[email protected] ++++ b/config/init/systemd/[email protected] +@@ -13,6 +13,7 @@ ExecStart=@BINDIR@/lxc-start -F -n %i + ExecStop=@BINDIR@/lxc-stop -n %i + # Environment=BOOTUP=serial + # Environment=CONSOLETYPE=serial ++StateDirectory=lxc + Delegate=yes + + [Install]
recipes-containers/lxc/lxc_git.bb +2 -1
@@ -45,6 +45,7 @@ SRC_URI = "git://github.com/lxc/lxc.git;branch=stable-6.0;protocol=https \ file://0001-download-don-t-try-compatbility-index.patch \ file://tests-our-init-is-not-busybox.patch \ file://0001-template-if-busybox-contains-init-use-it-in-containe.patch \ + file://0001-enable-systemd-StateDirectory-for-lxc.patch \ file://dnsmasq.conf \ file://lxc-net \ "
@@ -140,7 +141,7 @@ do_install:append() { if "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}"; then # nothing special for systemd at the moment - true + (cd ${D}${localstatedir}; [ -d lib/lxc ] && rmdir -v --parents lib/lxc) else # with meson, these aren't built unless sysvinit is the enabled # init system.
Signature · 1 line
2.25.1
It looks like the stable-6.0 branch has picked up this change, so I've done another lxc bump and have moved master-next to master.
I held master-next for longer than I'd like as I was working on some issues in the stack. I finally have some of that sorted out, so I'm now starting to introduce a bit of changes into the layer as I finish that up.
Bruce
In message: [meta-virtualization] [PATCH] lxc: backport patch to enable systemd StateDirectory for lxc
Quoted 108 lines · on 20/11/2025 Vishwas Udupa via lists.yoctoproject.org wrote:
Backport upstream patch to make sure lxc systemd service defines a StateDirectory to ensure that the
/var/lib/lxcdirectory is automatically created and managed by systemd during service startup.
Do not create lxc directory at build time for systemd.Signed-off-by Vishwas Udupa <[email protected]>--- ...nable-systemd-StateDirectory-for-lxc.patch | 55 +++++++++++++++++++ recipes-containers/lxc/lxc_git.bb | 3 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 recipes-containers/lxc/files/0001-enable-systemd-StateDirectory-for-lxc.patchrecipes-containers/lxc/files/0001-enable-systemd-StateDirectory-for-lxc.patch new file +55
-0@@ -0,0 +1,55 @@ +From c7bd5a3576f7449040e2164b6740c94cc2f5940c Mon Sep 17 00:00:00 2001 +From: Vishwas Udupa <[email protected]> +Date: Wed, 17 Sep 2025 03:56:09 -0700 +Subject: [PATCH] Enable systemd to create /var/lib/lxc at runtime +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Upstream-Status: Backport [https://github.com/lxc/lxc/commit/c7bd5a3] +Signed-off-by: Vishwas Udupa <[email protected]> +Co-developed-by: Raghuvarya S <[email protected]> + +This change adds the StateDirectory= directive in the systemd +unit file to ensure that the /var/lib/lxc directory is +automatically created and managed by systemd during service startup. + +The StateDirectory= option instructs systemd to create a persistent +state directory under /var/lib/. This is particularly useful in +scenarios where the directory may be missing at first boot — such as +on OSTree-based Linux distributions, which typically ship with +empty /var directory as part of their immutable root filesystem. + +By adding StateDirectory=lxc, systemd will handle the creation of +/var/lib/lxc on first boot, ensuring that the service can start +reliably even when the directory is not present initially. + +--- + config/init/systemd/lxc.service.in | 1 + + config/init/systemd/[email protected] | 1 + + 2 files changed, 2 insertions(+) + +diff --git a/config/init/systemd/lxc.service.in b/config/init/systemd/lxc.service.in +index 397a6c4d04..7142656178 100644 +--- a/config/init/systemd/lxc.service.in ++++ b/config/init/systemd/lxc.service.in +@@ -13,6 +13,7 @@ ExecStop=@LIBEXECDIR@/lxc/lxc-containers stop + ExecReload=@LIBEXECDIR@/lxc/lxc-apparmor-load + # Environment=BOOTUP=serial + # Environment=CONSOLETYPE=serial ++StateDirectory=lxc + Delegate=yes + + [Install] +diff --git a/config/init/systemd/[email protected] b/config/init/systemd/[email protected] +index 21ce64aefe..44e5b14dd2 100644 +--- a/config/init/systemd/[email protected] ++++ b/config/init/systemd/[email protected] +@@ -13,6 +13,7 @@ ExecStart=@BINDIR@/lxc-start -F -n %i + ExecStop=@BINDIR@/lxc-stop -n %i + # Environment=BOOTUP=serial + # Environment=CONSOLETYPE=serial ++StateDirectory=lxc + Delegate=yes + + [Install]recipes-containers/lxc/lxc_git.bb +2
-1@@ -45,6 +45,7 @@ SRC_URI = "git://github.com/lxc/lxc.git;branch=stable-6.0;protocol=https \ file://0001-download-don-t-try-compatbility-index.patch \ file://tests-our-init-is-not-busybox.patch \ file://0001-template-if-busybox-contains-init-use-it-in-containe.patch \ + file://0001-enable-systemd-StateDirectory-for-lxc.patch \ file://dnsmasq.conf \ file://lxc-net \ "@@ -140,7 +141,7 @@ do_install:append() { if "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}"; then # nothing special for systemd at the moment - true + (cd ${D}${localstatedir}; [ -d lib/lxc ] && rmdir -v --parents lib/lxc) else # with meson, these aren't built unless sysvinit is the enabled # init system.Signature · 11 lines
2.25.1 -=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#9453): https://lists.yoctoproject.org/g/meta-virtualization/message/9453 Mute This Topic: https://lists.yoctoproject.org/mt/116390300/1050810 Group Owner: [email protected] Unsubscribe: https://lists.yoctoproject.org/g/meta-virtualization/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-