* [PATCH] lxc: backport patch to enable systemd StateDirectory for lxc
@ 2025-11-20 13:23 Vishwas Udupa
2025-12-02 3:46 ` [meta-virtualization] " Bruce Ashfield
0 siblings, 1 reply; 2+ messages in thread
From: Vishwas Udupa @ 2025-11-20 13:23 UTC (permalink / raw)
To: meta-virtualization; +Cc: anuj.mittal, Vishwas Udupa
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.
Signed-off-by: Vishwas Udupa <vudupa@qti.qualcomm.com>
---
...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
diff --git a/recipes-containers/lxc/files/0001-enable-systemd-StateDirectory-for-lxc.patch b/recipes-containers/lxc/files/0001-enable-systemd-StateDirectory-for-lxc.patch
new file mode 100644
index 00000000..2d60798a
--- /dev/null
+++ b/recipes-containers/lxc/files/0001-enable-systemd-StateDirectory-for-lxc.patch
@@ -0,0 +1,55 @@
+From c7bd5a3576f7449040e2164b6740c94cc2f5940c Mon Sep 17 00:00:00 2001
+From: Vishwas Udupa <vudupa@qti.qualcomm.com>
+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 <vudupa@qti.qualcomm.com>
+Co-developed-by: Raghuvarya S <raghuvar@qti.qualcomm.com>
+
+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/lxc@.service.in | 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/lxc@.service.in b/config/init/systemd/lxc@.service.in
+index 21ce64aefe..44e5b14dd2 100644
+--- a/config/init/systemd/lxc@.service.in
++++ b/config/init/systemd/lxc@.service.in
+@@ -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]
diff --git a/recipes-containers/lxc/lxc_git.bb b/recipes-containers/lxc/lxc_git.bb
index 2f0e8e74..97896280 100644
--- a/recipes-containers/lxc/lxc_git.bb
+++ b/recipes-containers/lxc/lxc_git.bb
@@ -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.
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [meta-virtualization] [PATCH] lxc: backport patch to enable systemd StateDirectory for lxc
2025-11-20 13:23 [PATCH] lxc: backport patch to enable systemd StateDirectory for lxc Vishwas Udupa
@ 2025-12-02 3:46 ` Bruce Ashfield
0 siblings, 0 replies; 2+ messages in thread
From: Bruce Ashfield @ 2025-12-02 3:46 UTC (permalink / raw)
To: vudupa; +Cc: meta-virtualization, anuj.mittal
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
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/lxc
> directory 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 <vudupa@qti.qualcomm.com>
> ---
> ...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
>
> diff --git a/recipes-containers/lxc/files/0001-enable-systemd-StateDirectory-for-lxc.patch b/recipes-containers/lxc/files/0001-enable-systemd-StateDirectory-for-lxc.patch
> new file mode 100644
> index 00000000..2d60798a
> --- /dev/null
> +++ b/recipes-containers/lxc/files/0001-enable-systemd-StateDirectory-for-lxc.patch
> @@ -0,0 +1,55 @@
> +From c7bd5a3576f7449040e2164b6740c94cc2f5940c Mon Sep 17 00:00:00 2001
> +From: Vishwas Udupa <vudupa@qti.qualcomm.com>
> +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 <vudupa@qti.qualcomm.com>
> +Co-developed-by: Raghuvarya S <raghuvar@qti.qualcomm.com>
> +
> +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/lxc@.service.in | 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/lxc@.service.in b/config/init/systemd/lxc@.service.in
> +index 21ce64aefe..44e5b14dd2 100644
> +--- a/config/init/systemd/lxc@.service.in
> ++++ b/config/init/systemd/lxc@.service.in
> +@@ -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]
> diff --git a/recipes-containers/lxc/lxc_git.bb b/recipes-containers/lxc/lxc_git.bb
> index 2f0e8e74..97896280 100644
> --- a/recipes-containers/lxc/lxc_git.bb
> +++ b/recipes-containers/lxc/lxc_git.bb
> @@ -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.
> --
> 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: meta-virtualization+owner@lists.yoctoproject.org
> Unsubscribe: https://lists.yoctoproject.org/g/meta-virtualization/unsub [bruce.ashfield@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-12-02 3:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-20 13:23 [PATCH] lxc: backport patch to enable systemd StateDirectory for lxc Vishwas Udupa
2025-12-02 3:46 ` [meta-virtualization] " Bruce Ashfield
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.