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

Flatcar SDK: add experimental prefix builds #1151

Closed

Conversation

t-lo
Copy link
Member

@t-lo t-lo commented Sep 19, 2023

This PR adds experimental prefix builds to the Flatcar SDK.

Prefix builds use a custom sys prefix path and emerge all binaries and runtime dependencies into that prefix.

This path can then e.g. be shipped as a portable sysext since it includes all dependencies, and has libraries at a custom path so these do not conflict with libraries on target systems.

Prefix uses a staging environment (path) featuring a full-blown development environment, and a "final" environment for installing. Staging and final need to be created using setup_prefix first, which will also create an emerge wrapper to emerge ebuilds into staging and subsequently final. The root fs in final may be used to create a distro independent, portable sysext.

See the readme at https://github.com/chewi/flatcar-distro/blob/hackathon-prefix-builds-sync-to-upstream/PREFIX.md for more information.

How to use

Prefix requires cross-boss to be available locally.
Testing was done with the latest Alpha SDK, not the nightly build SDK.
The latest development is in the hackathon-prefix-builds-sync-to-upstream branch.

git clone https://github.com/chewi/flatcar-distro.git
cd flatcar-distro
git checkout hackathon-prefix-builds-sync-to-upstream

git clone https://github.com/chewi/cross-boss

./run_sdk_container -C ghcr.io/flatcar/flatcar-sdk-all:3717.0.0 -n flatcar-sdk-prefix-3717.0.0 -t

In the SDK container, initialise a prefix, then build (for example) python into it:

# Create prefix staging and final; bootstrap staging env
# Syntax is "setup_prefix <name> <prefix-path>
./setup_prefix prefixtest /usr/local/
emerge-prefix-prefixtest-amd64-usr python

Prefixes are architecture aware; the same prefix name can be used for multiple archs

./setup_prefix --board=arm64-usr prefixtest /usr/local/
emerge-prefix-prefixtest-arm64-usr python

"Final" environments will be in __prefix__/<board>/prefixtest after the builds conclude. __prefix__/<board>/prefixtest/root contain the root FS and can be used to create sysexts.

Testing done

Built the above (see "How to use") for amd64 and arm64, created a python sysext, tested on Flatcar x86_64 and arm64 QEmu instances.

  • Changelog entries added in the respective changelog/ directory (user-facing change, bug fix, security fix, update)
  • n/a Inspected CI output for image differences: /boot and /usr size, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.

chewi and others added 29 commits September 19, 2023 12:13
Flatcar actually lacks the dependencies.
Note that this package may need to be masked in the non-prefix builds.
We need this for a tmpfiles implementation. Gentoo now only supports
systemd itself or systemd-utils, and the former is masked for prefix.
opentmpfiles is dead and systemd-tmpfiles is now part of systemd-utils.
We either lack the packages or haven't built the host gcc with openmp
support.
We need this in the SDK for building prefix. It's been in upstream's
repo for a little while now anyway.
Not committed upstream yet, but we need this now. Not sure if this works
with the earlier versions.
This change updates PKGDIR and PORT_LOGDIR in the prefix's make.conf
(both staging and final) to /usr/local/microsoft/var/lib/portage/pkgs
and /usr/local/microsoft/var/log/portage, respectively.

This resolves an issue where emerge in the prefix was interfering with
the core SDK's emerge (overwriting packages etc.).
This change introduces softlinks in staging/ and final/ etc directories
to the root passwd and group files. This ensures that PORTAGE_USERNAME
and PORTAGE_GRPNAME defined in the prefix' make.conf files can use users
from the host system.

Also, sensible EMERGE_DEFAULT options are added to staging and final
make.conf: staging will always build packages, and final will always
install rdeps, and only use binpkgs by default.
This change makes prefixes configurable and adds a wrapper script
"setup_prefix" to create new prefixes.

It also greatly extends the documentation in PREFIX.md.
Signed-off-by: Thilo Fromm <thilofromm@microsoft.com>
This change updates hprexlify in
dev-libs/libgpg-error/libgpg-error-1.47.ebuild to use the build root
instead of EPREFIX when cross-compiling.

This fixes an isse with prefix + cross compilation where, if autogen.sh
is hprefixified to (cross) EPREFIX it will return an empty version
string when running eautoreconf later. That would reset the libgpg-error
version to an empty string, leading to compilation breakage with:

./mkheader        \
                   aarch64-cros-linux-gnu  /var/tmp/portage/dev-libs/libgpg-error-1.47/work/libgpg-error-1.47/src/gpg-error.h.in \
                   ../config.h  0x012f00 >gpg-error.h
usage: mkheader host_triplet template.h config.h version version_number
       mkheader host_triplet
make[2]: *** [Makefile:1704: gpg-error.h] Error 1
make[2]: Leaving directory '/var/tmp/portage/dev-libs/libgpg-error-1.47/work/libgpg-error-1.47-.arm64/src'
make[1]: *** [Makefile:521: all-recursive] Error 1
make[1]: Leaving directory '/var/tmp/portage/dev-libs/libgpg-error-1.47/work/libgpg-error-1.47-.arm64'
make: *** [Makefile:453: all] Error 2

Signed-off-by: Thilo Fromm <thilofromm@microsoft.com>
- Use bash built-ins for samity-checking mandatory args
- Remove spurious "installation dir" arg from help

Signed-off-by: Thilo Fromm <thilofromm@microsoft.com>
Signed-off-by: Thilo Fromm <thilofromm@microsoft.com>
secureboot.eclass was added while work on the prefix feature fork was
ongoing - which also added secureboot.eclass.

Move it from prefix-verlay to portage-stable where it belongs.

Signed-off-by: Thilo Fromm <thilofromm@microsoft.com>
Signed-off-by: Thilo Fromm <thilofromm@microsoft.com>
@t-lo t-lo requested a review from a team September 19, 2023 11:47
@t-lo t-lo temporarily deployed to development September 19, 2023 11:47 — with GitHub Actions Inactive
@pothos
Copy link
Member

pothos commented Sep 19, 2023

Thanks for working on this. To understand, what is the output of ldd /usr/local/my-stuff/usr/bin/python, for example? Are the library paths are in the binary absolute or is some ld.so.conf entry involved?

@github-actions
Copy link

github-actions bot commented Sep 19, 2023

@t-lo
Copy link
Member Author

t-lo commented Sep 19, 2023

Apparently things broke when I rebased this to the latest main (conflicting glibc and python eboulds). I'll close this, squash and apply a single patch in a branch directly in the scripts repo, and file a new PR.

Output of ldd:

core@localhost ~ $ ldd /usr/local/flatcar/usr/bin/awk 
        linux-vdso.so.1 (0x00007fffb67aa000)
        libreadline.so.8 => /lib64/libreadline.so.8 (0x00007f0391d14000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f0391c36000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f0391a55000)
        libtinfow.so.6 => /lib64/libtinfow.so.6 (0x00007f0391a15000)
        /usr/local/flatcar/lib64/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f0391e21000)

@pothos let's continue the discussion in the new PR, will close this one.

@t-lo t-lo closed this Sep 19, 2023
@pothos
Copy link
Member

pothos commented Sep 19, 2023

Output of ldd:

core@localhost ~ $ ldd /usr/local/flatcar/usr/bin/awk 
        linux-vdso.so.1 (0x00007fffb67aa000)
        libreadline.so.8 => /lib64/libreadline.so.8 (0x00007f0391d14000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f0391c36000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f0391a55000)
        libtinfow.so.6 => /lib64/libtinfow.so.6 (0x00007f0391a15000)
        /usr/local/flatcar/lib64/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f0391e21000

Oh, is this what you expect? It seems to use the host libraries which is wrong.

@t-lo
Copy link
Member Author

t-lo commented Sep 19, 2023

@pothos It's the output of the host ldd. If I use /usr/local/flatcar/usr/bin/ldd /usr/local/flatcar/usr/bin/awk then I get

linux-vdso.so.1 (0x00007ffd0ccbf000)                                   k 
libreadline.so.8 => /usr/local/flatcar/usr/lib64/libreadline.so.8 (0x00007f1ca7184000)
libm.so.6 => /usr/local/flatcar/lib64/libm.so.6 (0x00007f1ca70a7000)
libc.so.6 => /usr/local/flatcar/lib64/libc.so.6 (0x00007f1ca6ed4000)
libtinfow.so.6 => /usr/local/flatcar/usr/lib64/libtinfow.so.6 (0x00007f1ca6e93000)
/usr/local/flatcar/lib64/ld-linux-x86-64.so.2 (0x00007f1ca728c000)

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.

4 participants