Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install in initrd #169

Conversation

valentindavid
Copy link
Collaborator

No description provided.

Copy link
Member

@alfonsosanchezbeato alfonsosanchezbeato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick - also a question, how much is the initramfs increased with these changes?

Also, maybe expand a little bit the commit message and mention the binaries that are now added to the image, which seem to be:

  • cryptsetup
  • sfdisk
  • partx
  • tar
  • mkfs.ext4

debian/control Outdated
@@ -60,7 +60,7 @@ Build-Depends: debhelper-compat (= 12), dh-python, python3:any, dracut-core, qui
squashfs-tools,
snapd (>= 2.50+20.04),
systemd-bootchart,
golang-go, indent, libapparmor-dev, libcap-dev, libfuse-dev, libglib2.0-dev, liblzma-dev, liblzo2-dev, libseccomp-dev, libudev-dev, openssh-client, pkg-config, python3, python3-docutils, python3-markdown, squashfs-tools, tzdata, udev, xfslibs-dev
golang-go, indent, libapparmor-dev, libcap-dev, libfuse-dev, libglib2.0-dev, liblzma-dev, liblzo2-dev, libseccomp-dev, libudev-dev, openssh-client, pkg-config, python3, python3-docutils, python3-markdown, squashfs-tools, tzdata, udev, xfslibs-dev, cryptsetup-bin

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move cryptsetup-bin to a different line - the deps on this line come from the time when we had a fork of snap-bootstrap for cloud images, which fortunately is not the case anymore, and afaik were kept intentionally on just one line so they could be removed easily. So actually, hopefully the full line of deps can be dropped now (we can do that in another PR)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/usr/bin/unsquashfs \
/usr/lib/snapd/info \
/usr/lib/snapd/snap-bootstrap \
/usr/sbin/mkfs.ext4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reformatting this

@pedronis pedronis self-requested a review June 13, 2023 13:54
Copy link

@kubiko kubiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to reverse logic and use
/run/mnt/data/system-data/var/lib/snapd/modeen as primary source of truth and only if not accessible to fallback to /proc/cmdline

this will make it also lot easier to address other modes like factory-reset

@@ -5,10 +5,19 @@ cp /sysroot/run/image.fstab /run/
# TODO:UC20: move this logic into snap-bootstrap to be incorporated with
# initramfs-mounts

if grep -q snapd_recovery_mode=run /proc/cmdline; then
Copy link

@kubiko kubiko Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we not use /run/mnt/ubuntu-data/system-data/var/lib/snapd/modeenv as primary source of truth?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

if grep -q snapd_recovery_mode=run /proc/cmdline; then
run_mode=1
elif grep -q snapd_recovery_mode=install /proc/cmdline; then
if grep -q mode=run /run/mnt/ubuntu-data/system-data/var/lib/snapd/modeenv; then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this condition is too restrictive.
What if snapd_recovery_mode=factory-reset?

run_mode=1
fi
fi

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about using this instead:

# Always prefer to use modeevn, if it is available
if [ -e "/run/mnt/data/system-data/var/lib/snapd/modeenv" ]; then
  run_mode="$(sed -n 's/mode=\([^[:space:]]*\)/\1/p' /run/mnt/data/system-data/var/lib/snapd/modeenv)"
else
  run_mode="$(sed 's/.*snapd_recovery_mode=\([^[:space:]]*\)[[:space:]].*/\1/' /proc/cmdline))"
fi

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmdline is more complex. It could be the last argument. In 22 branch we have a shell script that properly parses and we can use that there.

I will propose something different tomorrow.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean /usr/libexec/core/get?
Yeah in 22 I used
run_mode="$(/usr/libexec/core/get-arg snapd_recovery_mode || true)"
If we can backport that script, of course even better, then you can do

if [ -e "/run/mnt/data/system-data/var/lib/snapd/modeenv" ]; then
  run_mode="$(sed -n 's/mode=\([^[:space:]]*\)/\1/p' /run/mnt/data/system-data/var/lib/snapd/modeenv)"
else
  run_mode="$(/usr/libexec/core/get-arg snapd_recovery_mode || true)"
fi

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed it. Take a look.

# Always bind-mount all the host filesystems
mkdir -p /run/mnt/host
echo '/run/mnt/host /host none rbind 0 0' >> /run/image.fstab
if grep -q snapd_recovery_mode=run /proc/cmdline; then
if [ -n "${run_mode-}" ]; then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then using
if [ "${run_mode}" = "run" ]; then

@kubiko
Copy link

kubiko commented Jun 13, 2023

@alfonsosanchezbeato with zstd compression this added 980kB on arm64
My test included libdbus... which we are adding regardless so even less than 980kB

@mvo5
Copy link
Contributor

mvo5 commented Jun 14, 2023

Fwiw, this looks fine to me

@valentindavid valentindavid force-pushed the valentindavid/install-in-initrd branch 2 times, most recently from 03c4c56 to 047640b Compare June 14, 2023 15:47
@valentindavid
Copy link
Collaborator Author

Also, maybe expand a little bit the commit message and mention the binaries that are now added to the image, which seem to be:

I have split it into 2 commits. So now the patch show what is added.

@valentindavid
Copy link
Collaborator Author

I had to add kmod-nls-cp437 in the modules to be able to run fsck on vfat. Not sure why it worked before without it.

Copy link

@kubiko kubiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just missing /usr/libexec/core/get-mode file to review.

@@ -5,10 +5,12 @@ cp /sysroot/run/image.fstab /run/
# TODO:UC20: move this logic into snap-bootstrap to be incorporated with
# initramfs-mounts

mode="$(/usr/libexec/core/get-mode mode)" || mode="$(/usr/libexec/core/get-arg snapd_recovery_mode)" || mode="unknown"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this.
I cannot find /usr/libexec/core/get-mode though. Have you forgot to include it in the commit?

@valentindavid valentindavid force-pushed the valentindavid/install-in-initrd branch from 047640b to 1f2f111 Compare June 14, 2023 16:41
Copy link

@kubiko kubiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
thank you!

Copy link
Member

@alfonsosanchezbeato alfonsosanchezbeato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very clean, thanks! Approving, but please check question.

@@ -8,6 +8,7 @@ ahci
libahci
usb-storage
nls_iso8859-1
kmod-nls-cp437

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this now? Maybe it should have its own commit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is fsck.vfat. I am not totally sure what change required that. But it does make sense since we mount the ESP. Not sure why we did not need it before. I will add some comment.

@valentindavid valentindavid force-pushed the valentindavid/install-in-initrd branch from 1f2f111 to 2f3051d Compare June 15, 2023 10:08
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@valentindavid valentindavid marked this pull request as ready for review June 19, 2023 08:02
@alfonsosanchezbeato alfonsosanchezbeato merged commit 410b860 into canonical:core20 Jun 19, 2023
This was referenced Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants