From 34dea62ef02c5763635aa981f5a028e9e3ae2cd3 Mon Sep 17 00:00:00 2001 From: Philip Roche Date: Thu, 18 Jan 2024 10:45:59 +0000 Subject: [PATCH 1/5] fix: Fix calls to `unminimize` if lxd-installer package not present (LP: #2049723) The unminimize script will try to install the lxd snap using the shim script `/usr/sbin/lxd` from the lxd-installer package. Previously `unminimize` was using `snap` to install `lxd` directly which was being diverted by diverting the `snap` command. This is no longer the case so we can remove `/usr/sbin/lxd` from the lxd-installer package if it exists and then redirect any calls to `/usr/sbin/lxd` to `/bin/true`. --- debian/changelog | 6 +++++ .../hooks/01-unminimize.chroot_early | 25 +++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/debian/changelog b/debian/changelog index 1655a3db..b137231b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +livecd-rootfs (2.765.37) jammy; urgency=medium + + * fix: Fix for calling unminimize if lxd-installer package not installed. (LP: #2049723) + + -- Philip Roche Mon, 22 Jan 2024 13:26:43 +0000 + livecd-rootfs (2.765.36) jammy; urgency=medium * Use correct /etc/ssh/sshd_config.d/ filename so cloud-init overrides diff --git a/live-build/ubuntu-server/hooks/01-unminimize.chroot_early b/live-build/ubuntu-server/hooks/01-unminimize.chroot_early index f70b59b4..69fbbccb 100755 --- a/live-build/ubuntu-server/hooks/01-unminimize.chroot_early +++ b/live-build/ubuntu-server/hooks/01-unminimize.chroot_early @@ -10,11 +10,22 @@ case ${PASS} in ;; esac -# The unminimize script will try to install the lxd snap. We can't -# do that at this stage so just neuter the snap command (the snap +# The unminimize script will try to install the lxd snap using the shim script +# /usr/sbin/lxd from the lxd-installer package. +# We can't do that at this stage so just neuter the lxd command (the snap # will get properly seeded by generic machinery). -dpkg-divert --add --divert /usr/bin/snap.REAL --rename /usr/bin/snap -ln -s /bin/true /usr/bin/snap -yes | /usr/local/sbin/unminimize -rm /usr/bin/snap -dpkg-divert --remove --rename /usr/bin/snap +if [[ -f "/usr/sbin/lxd" ]]; then + rm --verbose --force /usr/sbin/lxd + ln -s /bin/true /usr/sbin/lxd + yes | /usr/local/sbin/unminimize + # unminimize also uninstalls lxd-installer package + # and also removed `/usr/sbin/lxd` as a result so we don't need to restore +else + # if /usr/sbin/lxd doesn't exist when lxd-installer package isn't installed so we can mock the command + # to avoid the unminimize script failing + ln -s /bin/true /usr/sbin/lxd + yes | /usr/local/sbin/unminimize + # as the lxd-installer package was not installed and thus not removed the mock + # /usr/sbin/lxd will still be present so we need to remove it + rm --verbose --force /usr/sbin/lxd +fi \ No newline at end of file From c09d4c1652961986b5015adcba5aa969682b114b Mon Sep 17 00:00:00 2001 From: Philip Roche Date: Mon, 22 Jan 2024 12:41:41 +0000 Subject: [PATCH 2/5] fix: Only use single brackets for if statements Double brackets are not required and do not follow the uses elsewhere in this code base --- live-build/ubuntu-server/hooks/01-unminimize.chroot_early | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/live-build/ubuntu-server/hooks/01-unminimize.chroot_early b/live-build/ubuntu-server/hooks/01-unminimize.chroot_early index 69fbbccb..64680be4 100755 --- a/live-build/ubuntu-server/hooks/01-unminimize.chroot_early +++ b/live-build/ubuntu-server/hooks/01-unminimize.chroot_early @@ -14,7 +14,7 @@ esac # /usr/sbin/lxd from the lxd-installer package. # We can't do that at this stage so just neuter the lxd command (the snap # will get properly seeded by generic machinery). -if [[ -f "/usr/sbin/lxd" ]]; then +if [ -f "/usr/sbin/lxd" ]; then rm --verbose --force /usr/sbin/lxd ln -s /bin/true /usr/sbin/lxd yes | /usr/local/sbin/unminimize From d97514cba0f3d772d9f2d0ebf33cfa69961bf925 Mon Sep 17 00:00:00 2001 From: Philip Roche Date: Mon, 22 Jan 2024 12:44:08 +0000 Subject: [PATCH 3/5] fix: Improve comments for case when lxd-installer package is not installed Improve confusing comments for case when lxd-installer package is not installed. This was worded confusingly --- live-build/ubuntu-server/hooks/01-unminimize.chroot_early | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/live-build/ubuntu-server/hooks/01-unminimize.chroot_early b/live-build/ubuntu-server/hooks/01-unminimize.chroot_early index 64680be4..9ec78a82 100755 --- a/live-build/ubuntu-server/hooks/01-unminimize.chroot_early +++ b/live-build/ubuntu-server/hooks/01-unminimize.chroot_early @@ -21,11 +21,11 @@ if [ -f "/usr/sbin/lxd" ]; then # unminimize also uninstalls lxd-installer package # and also removed `/usr/sbin/lxd` as a result so we don't need to restore else - # if /usr/sbin/lxd doesn't exist when lxd-installer package isn't installed so we can mock the command - # to avoid the unminimize script failing + # if /usr/sbin/lxd doesn't exist then lxd-installer package isn't installed. + # Instead, we can mock the command to avoid the unminimize script failing ln -s /bin/true /usr/sbin/lxd yes | /usr/local/sbin/unminimize - # as the lxd-installer package was not installed and thus not removed the mock - # /usr/sbin/lxd will still be present so we need to remove it + # as the lxd-installer package was not installed and thus not removed by `unminimize` + # the mock /usr/sbin/lxd will still be present, so we need to remove it rm --verbose --force /usr/sbin/lxd fi \ No newline at end of file From 6ad70d64a5bf728cd13c1f255b1335a095b22340 Mon Sep 17 00:00:00 2001 From: Philip Roche Date: Mon, 22 Jan 2024 12:45:57 +0000 Subject: [PATCH 4/5] fix: When using `rm` do not use `--force` when not required `--force` implies that we wish not to fail `rm` even if the file is not present. This was not our intention and as such can be removed. Also use short option `-v` for verbose output as per the test of the code base. --- live-build/ubuntu-server/hooks/01-unminimize.chroot_early | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/live-build/ubuntu-server/hooks/01-unminimize.chroot_early b/live-build/ubuntu-server/hooks/01-unminimize.chroot_early index 9ec78a82..cefc73c7 100755 --- a/live-build/ubuntu-server/hooks/01-unminimize.chroot_early +++ b/live-build/ubuntu-server/hooks/01-unminimize.chroot_early @@ -27,5 +27,5 @@ else yes | /usr/local/sbin/unminimize # as the lxd-installer package was not installed and thus not removed by `unminimize` # the mock /usr/sbin/lxd will still be present, so we need to remove it - rm --verbose --force /usr/sbin/lxd + rm -v /usr/sbin/lxd fi \ No newline at end of file From 8f8415e1dc84eba6009feeb7605af26eddd512de Mon Sep 17 00:00:00 2001 From: Philip Roche Date: Mon, 22 Jan 2024 12:48:55 +0000 Subject: [PATCH 5/5] fix: Always use `dpkg-divert` instead of altering files maintained by packages Altering a file maintained by a package can lead to unexpected behaviou expecially in this case where packages are being removed and added. Instead use `dpkg-divert` to allow us to mock `lxd` to `true` to allow `unminimize` to work without error and to avoid installing of the `lxd` snap. --- .../ubuntu-server/hooks/01-unminimize.chroot_early | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/live-build/ubuntu-server/hooks/01-unminimize.chroot_early b/live-build/ubuntu-server/hooks/01-unminimize.chroot_early index cefc73c7..1265966b 100755 --- a/live-build/ubuntu-server/hooks/01-unminimize.chroot_early +++ b/live-build/ubuntu-server/hooks/01-unminimize.chroot_early @@ -15,11 +15,16 @@ esac # We can't do that at this stage so just neuter the lxd command (the snap # will get properly seeded by generic machinery). if [ -f "/usr/sbin/lxd" ]; then - rm --verbose --force /usr/sbin/lxd + dpkg-divert --add --divert /usr/sbin/lxd.REAL --rename /usr/sbin/lxd ln -s /bin/true /usr/sbin/lxd yes | /usr/local/sbin/unminimize # unminimize also uninstalls lxd-installer package - # and also removed `/usr/sbin/lxd` as a result so we don't need to restore + # and also removed `/usr/sbin/lxd` as a result, so we don't need to restore, but + # we do need to remove the mock we used as part of dpkg-divert + # first we need to remove the diversion + dpkg-divert --remove --no-rename /usr/sbin/lxd + # now remove the renamed file that we originally diverted to + rm -v /usr/sbin/lxd.REAL else # if /usr/sbin/lxd doesn't exist then lxd-installer package isn't installed. # Instead, we can mock the command to avoid the unminimize script failing