From 8f93156dbae7e1daaff22d81fbbcca234059c494 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Tue, 19 Dec 2023 10:29:54 +0000 Subject: [PATCH 1/5] Fix an outdated comment about mmdebstrap Since a8d07323d6502a9d147b696000b19d66013e57f4 we create the buildroot with ostree, not mmdebstrap. https://phabricator.endlessm.com/T4482 --- run-build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-build b/run-build index eb763a2e..ef2e0cb3 100755 --- a/run-build +++ b/run-build @@ -42,7 +42,7 @@ log = logging.getLogger(os.path.basename(__file__)) class ImageBuildRoot(object): """Build root for performing actual image build - A temporary build root is created with mmdebstrap at builddir. The + A temporary build root is created with ostree at builddir. The options in the config section buildroot control what gets installed and mounted in the buildroot. """ From 4190cbf858a97e45ec964f5e6326c037e120a6cc Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Tue, 19 Dec 2023 10:29:11 +0000 Subject: [PATCH 2/5] Factor out running a command in buildroot https://phabricator.endlessm.com/T4482 --- run-build | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/run-build b/run-build index ef2e0cb3..ce898059 100755 --- a/run-build +++ b/run-build @@ -195,11 +195,13 @@ class ImageBuildRoot(object): "--force-confnew"; }}; """)) - apt_cmd = ['chroot', self.builddir, 'apt-get', 'update'] - subprocess.check_call(apt_cmd, env=apt_env) - apt_cmd = ['chroot', self.builddir, 'apt-get', 'install', '-y'] + self._run(['apt-get', 'update'], env=apt_env) + apt_cmd = ['apt-get', 'install', '-y'] apt_cmd += packages - subprocess.check_call(apt_cmd, env=apt_env) + self._run(apt_cmd, env=apt_env) + + def _run(self, cmd, env=None): + subprocess.check_call(['chroot', self.builddir] + cmd, env=env) def mount(self, path, target=None): """Bind mount path in the build directory""" From 703a95675f1b195072b031c803a3fe536d125532 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Tue, 19 Dec 2023 09:54:31 +0000 Subject: [PATCH 3/5] Initialise /var/lib and friends in buildroot We recently merged a change to completely wipe `/var` in the ostree, replacing it with an empty directory. This is because on a real system, `/var` from the ostree is not used: instead a persistent, read-write directory is mounted over it. It turns out that `apt update` is happy to create its own directory hierarchy below `/var/lib`, but if that directory does not exist it fails with: E: List directory /var/lib/apt/lists/partial is missing. - Acquire (2: No such file or directory) Similarly, installing packages requires /var/lib/dpkg to exist, but we have moved this to /usr E: Could not open lock file /var/lib/dpkg/lock-frontend - open (2: No such file or directory) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root? On a real Endless OS system, `/var/lib` is initialised at boot by `systemd-tmpfiles`. Do the same here. Move the dpkg database back to its rightful home. Remove the tmpfiles snippet that eos-ostree-builder adds to deal with the changes we are undoing. https://phabricator.endlessm.com/T4482 --- run-build | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/run-build b/run-build index ce898059..3c2d0207 100755 --- a/run-build +++ b/run-build @@ -173,6 +173,22 @@ class ImageBuildRoot(object): for path in to_mount: self.mount(path) + # Remove the tmpfiles.d snippet that sets up symlinks for changes we have + # just reversed, and for the dpkg database we are about to move back + os.unlink(os.path.join(self.builddir, 'usr/lib/tmpfiles.d/ostree.conf')) + + # Create any files that would normally be handled at runtime. This is + # particularly important for /var since it's likely that it was removed + # from the ostree commit. Run this inside the chroot to avoid depending on + # systemd-tmpfiles on the host system. + self._run(['systemd-tmpfiles', '--create', '--remove', '--boot', '-E']) + + # Move the dpkg database back to its normal location + os.rename( + os.path.join(self.builddir, 'usr/share/dpkg/database'), + os.path.join(self.builddir, 'var/lib/dpkg'), + ) + log.info('Installing buildroot packages') apt_env = os.environ.copy() apt_env['DEBIAN_FRONTEND'] = 'noninteractive' From b8daefea49956b7683b9d8eafd63977d29ca02ad Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Tue, 19 Dec 2023 10:33:31 +0000 Subject: [PATCH 4/5] Placate update-catalog Installing an sgml catalog causes update-catalog to be run. This Perl script requires var/lib/sgml-base to exist. This directory is part of the sgml-base package but of course is deleted with the rest of /var. https://phabricator.endlessm.com/T4482 --- run-build | 3 +++ 1 file changed, 3 insertions(+) diff --git a/run-build b/run-build index 3c2d0207..5012c21c 100755 --- a/run-build +++ b/run-build @@ -189,6 +189,9 @@ class ImageBuildRoot(object): os.path.join(self.builddir, 'var/lib/dpkg'), ) + # update-catalog requires /var/lib/sgml-base to exist + os.makedirs(os.path.join(self.builddir, 'var/lib/sgml-base')) + log.info('Installing buildroot packages') apt_env = os.environ.copy() apt_env['DEBIAN_FRONTEND'] = 'noninteractive' From e38381babb0b860176d52243e86eb4037bc9d047 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Tue, 19 Dec 2023 10:33:31 +0000 Subject: [PATCH 5/5] Placate update-xmlcatalog Installing, I guess, an XML DTD causes update-xmlcatalog to be run. This Perl script requires `/var/lib/xml-core` to exist. This directory is part of the `xml-core` package but of course is deleted with the rest of `/var`. https://phabricator.endlessm.com/T4482 --- run-build | 3 +++ 1 file changed, 3 insertions(+) diff --git a/run-build b/run-build index 5012c21c..bc997dc1 100755 --- a/run-build +++ b/run-build @@ -192,6 +192,9 @@ class ImageBuildRoot(object): # update-catalog requires /var/lib/sgml-base to exist os.makedirs(os.path.join(self.builddir, 'var/lib/sgml-base')) + # update-xmlcatalog requires /var/lib/xml-core to exist + os.makedirs(os.path.join(self.builddir, 'var/lib/xml-core')) + log.info('Installing buildroot packages') apt_env = os.environ.copy() apt_env['DEBIAN_FRONTEND'] = 'noninteractive'