]> git.ipfire.org Git - thirdparty/mkosi.git/log
thirdparty/mkosi.git
4 years agomkosi: avoid mutable default arguments 743/head
Zbigniew Jędrzejewski-Szmek [Thu, 17 Jun 2021 11:41:58 +0000 (13:41 +0200)] 
mkosi: avoid mutable default arguments

4 years agomkosi: use 'in' in one more place
Zbigniew Jędrzejewski-Szmek [Thu, 17 Jun 2021 11:40:21 +0000 (13:40 +0200)] 
mkosi: use 'in' in one more place

4 years agomkosi: drop unused for_cache parameter
Zbigniew Jędrzejewski-Szmek [Thu, 17 Jun 2021 11:28:48 +0000 (13:28 +0200)] 
mkosi: drop unused for_cache parameter

4 years agomkosi: don't use [] as default argument
Zbigniew Jędrzejewski-Szmek [Thu, 17 Jun 2021 11:22:44 +0000 (13:22 +0200)] 
mkosi: don't use [] as default argument

rpmlint warns that this is dangerous. We don't modify the argument,
so actually this is safe here, but it's still nice to avoid this
potential pitfall.

4 years agomkosi: drop unused root argument
Zbigniew Jędrzejewski-Szmek [Thu, 17 Jun 2021 11:20:24 +0000 (13:20 +0200)] 
mkosi: drop unused root argument

4 years agomkosi: drop python2-style super() args
Zbigniew Jędrzejewski-Szmek [Thu, 17 Jun 2021 11:16:35 +0000 (13:16 +0200)] 
mkosi: drop python2-style super() args

4 years agomkosi: drop unused f from f-strings
Zbigniew Jędrzejewski-Szmek [Thu, 17 Jun 2021 11:16:21 +0000 (13:16 +0200)] 
mkosi: drop unused f from f-strings

Also, drop "+" from between string literals.

4 years agomkosi: don't use bsdtar on mandriva
Lennart Poettering [Wed, 16 Jun 2021 15:33:31 +0000 (17:33 +0200)] 
mkosi: don't use bsdtar on mandriva

Let's simplify things and use GNU tar everywhere, to expose somewhat
systematic behaviour on all distros.

This mirrors what systemd's importd daemon already does: force GNU tar
use even on distros where "tar" resolves to bsdtar.

4 years agoMerge pull request #728 from keszybz/cpio-and-zstd
Daan De Meyer [Wed, 16 Jun 2021 10:04:45 +0000 (11:04 +0100)] 
Merge pull request #728 from keszybz/cpio-and-zstd

cpio and zstd

4 years agoignore return code of fstrim
nopeslide [Fri, 21 May 2021 16:23:31 +0000 (18:23 +0200)] 
ignore return code of fstrim

devices (i.e. virtualized) may not support fstrim operations.

4 years agoFix short-form 'readonly' deprecation
Edwin Kofler [Tue, 8 Jun 2021 06:59:52 +0000 (06:59 +0000)] 
Fix short-form 'readonly' deprecation

4 years agoci: try cpio everywhere we try tar 728/head
Zbigniew Jędrzejewski-Szmek [Tue, 8 Jun 2021 06:58:42 +0000 (08:58 +0200)] 
ci: try cpio everywhere we try tar

4 years agoci: pip install types-dataclasses
Zbigniew Jędrzejewski-Szmek [Wed, 9 Jun 2021 11:57:54 +0000 (13:57 +0200)] 
ci: pip install types-dataclasses

Builds now fail with:

× Run python3 -m mypy mkosi
mkosi/__init__.py:12:1: error: Library stubs not installed for "dataclasses"
(or incompatible with Python 3.6)  [import]
    import dataclasses
    ^
mkosi/__init__.py:12:1: note: Hint: "python3 -m pip install types-dataclasses"
mkosi/__init__.py:12:1: note: (or run "mypy --install-types" to install all missing stub packages)
mkosi/__init__.py:12:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
mkosi/__init__.py:6247:12: error: Too many arguments for "CommandLineArguments"
 [call-arg]
        return CommandLineArguments(**vars(args))
               ^
Found 2 errors in 1 file (checked 3 source files)
Error: Process completed with exit code 1.

4 years agotyping: avoid warning about CompletedProcess.stdin being None
Zbigniew Jędrzejewski-Szmek [Mon, 7 Jun 2021 07:33:45 +0000 (09:33 +0200)] 
typing: avoid warning about CompletedProcess.stdin being None

In this particular case, stdin=subprocess.PIPE was passed, so we know
that .stdin is not None.

https://github.com/python/mypy/issues/10583

4 years agomkosi: rework compression config, add support for zstd
Zbigniew Jędrzejewski-Szmek [Fri, 21 May 2021 12:24:03 +0000 (14:24 +0200)] 
mkosi: rework compression config, add support for zstd

We had --compress and --xz. This is changed to --compress-fs (which is like
the old --compress), --compress-output (which is like --xz, except configurable),
and --compress (which tries to do the right thing depending on the output type).

With zstd, the difference in decompression time is massive:
$ time zstdcat image.cpio.zstd >/dev/null
0.221 s total
$ time xzcat image.cpio.xz >/dev/null
3.592 s total

$ ls -lg image.cpio.* image.cpio
-rw-rw-r-- 1 zbyszek 149408256 May 21 13:56 image.cpio
-rw-r--r-- 1 zbyszek  53032056 May 21 13:57 image.cpio.xz
-rw-r--r-- 1 zbyszek  59085907 May 21 13:49 image.cpio.zstd

v2:
- rename options to --compress-fs and --compres-output, unify handling
  of cpio and tar.

v3:
- use tar --use-compress-program= instead of subprocess.Popen()

v4:
- rebased after the backend.py split

4 years agomkosi: add support for building cpio archives
Zbigniew Jędrzejewski-Szmek [Fri, 21 May 2021 05:54:00 +0000 (07:54 +0200)] 
mkosi: add support for building cpio archives

This may be useful to create initramfs images, see
https://github.com/keszybz/mkosi-initrd.

I also tried an implementation using libarchive. The code was a little
bit simpler, but unfortunately the generated archive wasn't to the
kernel's liking. I think both the compressio options *and* the
underlying cpio format were a bit different. I think we should just accept
that the kernel is only tested with the specific output produced by cpio
with some specific settings.

4 years agomkosi: add variant of subprocess.Popen() that does not wait
Zbigniew Jędrzejewski-Szmek [Fri, 21 May 2021 05:54:00 +0000 (07:54 +0200)] 
mkosi: add variant of subprocess.Popen() that does not wait

We had run() which was a wrapper around subprocess.run().
This addes spawn(), which starts the process and does not wait for it.

v2:
- run() is changed to be call spawn() and wait and throw an exception
  if check is True.

v3:
- run() is a completely separate function again.

  It turns out that run() does a bunch of handling of input and output
  that would need to be recreated. In the end, the duplication of
  logging is a smaller issue than fiddling with input and output
  encodings.

v4:
- rebased

4 years agomkosi: fix alignment of Packages: line
Zbigniew Jędrzejewski-Szmek [Sat, 5 Jun 2021 13:05:18 +0000 (15:05 +0200)] 
mkosi: fix alignment of Packages: line

It was indented by two less.

4 years agomkosi: kill /usr/share/locale when installing Fedora
Zbigniew Jędrzejewski-Szmek [Fri, 21 May 2021 11:53:20 +0000 (13:53 +0200)] 
mkosi: kill /usr/share/locale when installing Fedora

Even with glibc-minimal-langpack, we still get ~30 MB of files
there with systemd + dependencies.

4 years agomkosi: reword error messages a bit
Zbigniew Jędrzejewski-Szmek [Fri, 21 May 2021 05:53:38 +0000 (07:53 +0200)] 
mkosi: reword error messages a bit

4 years agoMerge pull request #729 from behrmann/split_part1
Zbigniew Jędrzejewski-Szmek [Fri, 11 Jun 2021 07:19:32 +0000 (09:19 +0200)] 
Merge pull request #729 from behrmann/split_part1

Split precursor

4 years agoMerge pull request #730 from keszybz/help-pretiffication
Zbigniew Jędrzejewski-Szmek [Fri, 11 Jun 2021 06:50:09 +0000 (08:50 +0200)] 
Merge pull request #730 from keszybz/help-pretiffication

mkosi: do not repeat option lists in help output

4 years agoAdd typing to make mypy happy 730/head
Zbigniew Jędrzejewski-Szmek [Sun, 6 Jun 2021 17:41:32 +0000 (19:41 +0200)] 
Add typing to make mypy happy

Co-authored-by: Jörg Behrmann <behrmann@physik.fu-berlin.de>
4 years agomkosi: do not repeat option lists in help output
Zbigniew Jędrzejewski-Szmek [Sat, 5 Jun 2021 15:04:26 +0000 (17:04 +0200)] 
mkosi: do not repeat option lists in help output

--- /tmp/out1 2021-06-05 17:01:24.327828067 +0200
+++ /tmp/out2 2021-06-05 17:01:32.367897483 +0200
@@ -59,21 +59,19 @@
   --version             show program's version number and exit

 Distribution:
-  -d {fedora,debian,ubuntu,arch,opensuse,mageia,centos,centos_epel,clear,photon,openmandriva}, --distribution {fedora,debian,ubuntu,arch,opensuse,mageia,centos,centos_epel,clear,photon,openmandriva}
+  -d, --distribution {fedora,debian,ubuntu,arch,opensuse,mageia,centos,centos_epel,clear,photon,openmandriva}
                         Distribution to install
-  -r RELEASE, --release RELEASE
+  -r, --release RELEASE
                         Distribution release to install
-  -m MIRROR, --mirror MIRROR
-                        Distribution mirror to use
+  -m, --mirror MIRROR   Distribution mirror to use
   --repositories REPOS  Repositories to use
   --architecture ARCHITECTURE
                         Override the architecture of installation

 Output:
-  -t {directory,subvolume,tar,cpio,gpt_ext4,gpt_xfs,gpt_btrfs,gpt_squashfs,plain_squashfs}, --format {directory,subvolume,tar,cpio,gpt_ext4,gpt_xfs,gpt_btrfs,gpt_squashfs,plain_squashfs}
+  -t, --format {directory,subvolume,tar,cpio,gpt_ext4,gpt_xfs,gpt_btrfs,gpt_squashfs,plain_squashfs}
                         Output Format
-  -o PATH, --output PATH
-                        Output image path
+  -o, --output PATH     Output image path
   --output-split-root PATH
                         Output root or /usr/ partition image path (if --split-
                         artifacts is used)

… and so on.

4 years agofactor out leaf functions that will be needed for separating out distributions 729/head
Joerg Behrmann [Fri, 4 Jun 2021 15:24:43 +0000 (17:24 +0200)] 
factor out leaf functions that will be needed for separating out distributions

This reuses knowledge gained from #715. The functions included here are needed
to when distributiosn are moved to their own subpackages. This change has no
functional changes.

4 years agocapitalise arg_debug to show it's a global variable
Joerg Behrmann [Fri, 4 Jun 2021 15:03:22 +0000 (17:03 +0200)] 
capitalise arg_debug to show it's a global variable

4 years agotyping: use generics in @dictify type annotations
Zbigniew Jędrzejewski-Szmek [Thu, 3 Jun 2021 15:29:57 +0000 (17:29 +0200)] 
typing: use generics in @dictify type annotations

Instead of saying that it only works for [str, str], say it can create
a mapping of any two types. I verified that if I add a generator of a
different type, everything works as expected and mypy can detect type
mismatches.

I still don't know how to say that the wrapper takes the same
arguments as the decorated function. It would require a type
metavariable that would mean "some set of args and kwargs", and I
don't think there is syntax for anything like this.

4 years agoMerge pull request #724 from keszybz/drop-packages
Daan De Meyer [Thu, 3 Jun 2021 18:30:42 +0000 (19:30 +0100)] 
Merge pull request #724 from keszybz/drop-packages

mkosi: stop automatically inserting packages

4 years agomkosi: make run_pacman() function top-level 724/head
Zbigniew Jędrzejewski-Szmek [Tue, 25 May 2021 14:56:23 +0000 (16:56 +0200)] 
mkosi: make run_pacman() function top-level

No need to have this function dynamic.

4 years agomkosi: sort packages in installation list
Zbigniew Jędrzejewski-Szmek [Tue, 25 May 2021 14:48:57 +0000 (16:48 +0200)] 
mkosi: sort packages in installation list

It looks nice if the command line is tidy and the same on repeated
invocations. Plain sorted() would put '(' first, but conceptually it's
nice to have it last, so one can think "this will be installed if
those other things are listed first". The installer does not care of
course.

4 years agomkosi: optionally insert less packages automatically
Zbigniew Jędrzejewski-Szmek [Mon, 24 May 2021 12:42:39 +0000 (14:42 +0200)] 
mkosi: optionally insert less packages automatically

systemd, systemd-udev and some other packages were always
automatically inserted since the first version of mkosi. But this
approach is too heavy in some cases. To allow more flexibility while
maintaining backwards compat, this patch does two interleaved changes:

1. BasePackages=yes|no|conditional is added.

  With BasePackages=yes, we get status quo ante.

  With BasePackages=no, only packages specified by the user are
  installed.

  With BasePackages=conditional, on rpm systems, packages are
  installed if the matching base package would be installed. On
  deb/arch/… systems, equivalent to BasePackages=yes. (In other words,
  only rpm supports this natively. I'm not aware of similar
  functionality in other installers. install_arch() tries to achieve
  something similar by comparing package sets.)

  The default is "yes", to preseve unchanged behaviour by default.

2. Various packages that were installed unconditionally are converted
  to be conditional.

  This way we make more cases work automatically out of the box
  (e.g. the user only needs to specify 'systemd', not the
  subpackages), but allow deps to be cut down.

Looking at some concrete examples in Fedora:

- dracut: dracut is only necessary if using an initrd (and of
  course only if the initrd image is generated using dracut, and only
  if it is generated locally). But even for bootable images, a kernel
  with no initramfs might be enough. Or when using kvm, a direct
  kernel boot with an externally-provided kernel+initrd, etc.
  So pulling in dracut and dependencies is often not necessary.

- kernel-modules: despite the name, actually basic modules are in
  kernel-core. And kernel-modules is non-core modules. (And yes,
  kernel-modules-extra is extra-non-core-modules, and
  kernel-modules-internal is something else yet again).

- kernel-core: as with dracut, having a kernel image is not necessary
  in many scenarios.

- systemd: on big example where it's not useful is systemd itself.
  When using mkosi to build a systemd test image from sources,
  installing the system package forces all deps to be installed, which
  might not be desired. Dropping systemd from the installation list
  makes mkosi useful for non-systemd stuff (some container types or
  non-systemd inits).

  When installing systemd from sources, we do *not* want subpackages like
  systemd-udev to be installed. Having a mix of systemd-from-sources and
  a different compilation of systemd-udev-from-distro is likely to cause
  linking issues and other incompatibilities.

- grub* / systemd-boot: people might want to use grub even if sd-boot
  is available, etc.

For conditionalization, why do it using rpm syntax, and not interally
in code? For some cases, the effect is almost the same. But in other
cases, the installer has more information. For example, glibc usually
is not specified explicitly, but is pulled in through deps. We want
glibc-minimal-langpack only if something else pulls in glibc, and we
cannot resolve this from inside mkosi. But even for other packages,
the user might use a meta-package or a package group or a file path or
a virtual provide, and we cannot know in general what package will be
used to resolve the dependency. Using boolean dependencies makes this
much more reliable.

4 years agoopensuse: install "openssh-server", not "o", "p", "e", …
Zbigniew Jędrzejewski-Szmek [Tue, 25 May 2021 14:24:50 +0000 (16:24 +0200)] 
opensuse: install "openssh-server", not "o", "p", "e", …

4 years agophoton: install user-specified packages too
Zbigniew Jędrzejewski-Szmek [Tue, 25 May 2021 14:24:13 +0000 (16:24 +0200)] 
photon: install user-specified packages too

I assume this was an uninteded omission.

4 years agomkosi: allow inline comments (but only with "#")
Zbigniew Jędrzejewski-Szmek [Fri, 21 May 2021 14:06:58 +0000 (16:06 +0200)] 
mkosi: allow inline comments (but only with "#")

For example, it's super useful to comment on a list of packages:

Packages=
        glibc-minimal-langpack    # avoid pulling in other glibc langpacks
        less                      # this makes 'systemctl' much nicer to use ;)

;-comments are not allowed, because the colon doesn't stand out
enough. I was considering also adding comment_prefixes=('#',) to
disallow ;-comments everywhere, but that'd be a compatibility break
which I don't see enough justification for.

4 years agoMerge pull request #720 from keszybz/two-refactorings-and-a-bugfix
Daan De Meyer [Mon, 24 May 2021 08:50:59 +0000 (09:50 +0100)] 
Merge pull request #720 from keszybz/two-refactorings-and-a-bugfix

Some refactorings and bugfixes

4 years agomkosi: move two dynamically created methods to class level 720/head
Zbigniew Jędrzejewski-Szmek [Fri, 21 May 2021 13:51:35 +0000 (15:51 +0200)] 
mkosi: move two dynamically created methods to class level

4 years agoman: regerate man page
Zbigniew Jędrzejewski-Szmek [Sun, 23 May 2021 09:17:26 +0000 (11:17 +0200)] 
man: regerate man page

4 years agodocs: use backticks around --options
Zbigniew Jędrzejewski-Szmek [Sun, 23 May 2021 09:15:56 +0000 (11:15 +0200)] 
docs: use backticks around --options

Without this, pandoc renders "--" as "–".

4 years agomkosi: fix TypeError on unknown output format
Zbigniew Jędrzejewski-Szmek [Sat, 22 May 2021 20:43:42 +0000 (22:43 +0200)] 
mkosi: fix TypeError on unknown output format

Traceback (most recent call last):
  File "/usr/lib64/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/zbyszek/src/mkosi/mkosi/__main__.py", line 31, in <module>
    main()
  File "/home/zbyszek/src/mkosi/mkosi/__main__.py", line 11, in main
    args = parse_args()
  File "/home/zbyszek/src/mkosi/mkosi/__init__.py", line 5283, in parse_args
    args = parse_args_file_group(argv, default_path)
  File "/home/zbyszek/src/mkosi/mkosi/__init__.py", line 5320, in parse_args_file_group
    return parser.parse_args(argv_post_parsed)
  File "/usr/lib64/python3.9/argparse.py", line 1818, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib64/python3.9/argparse.py", line 1851, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib64/python3.9/argparse.py", line 2060, in _parse_known_args
    start_index = consume_optional(start_index)
  File "/usr/lib64/python3.9/argparse.py", line 2000, in consume_optional
    take_action(action, args, option_string)
  File "/usr/lib64/python3.9/argparse.py", line 1912, in take_action
    argument_values = self._get_values(action, argument_strings)
  File "/usr/lib64/python3.9/argparse.py", line 2444, in _get_values
    self._check_value(action, value)
  File "/usr/lib64/python3.9/argparse.py", line 2496, in _check_value
    if action.choices is not None and value not in action.choices:
  File "/usr/lib64/python3.9/enum.py", line 373, in __contains__
    raise TypeError(
TypeError: unsupported operand type(s) for 'in': 'str' and 'EnumMeta'

With the patch:
usage: mkosi [-h] [--version]
             ...
             {build,clean,help,summary,genkey,bump,serve,build,shell,boot,qemu,ssh} ...
mkosi: error: argument -t/--format: unknown Format: 'asfd'

It would be nice to also get rid of the list of options in the help
message: it's not helpful to the user at all.

4 years agomkosi: rewrite os-release parsing
Zbigniew Jędrzejewski-Szmek [Fri, 21 May 2021 11:51:51 +0000 (13:51 +0200)] 
mkosi: rewrite os-release parsing

This used the code from https://github.com/systemd/systemd/pull/19686,
except that walrus is removed for python3.7 compatibility.

4 years agomkosi: make one os.walk() more like the others
Zbigniew Jędrzejewski-Szmek [Fri, 21 May 2021 05:46:55 +0000 (07:46 +0200)] 
mkosi: make one os.walk() more like the others

We currently have three very similar loops, let's avoid unnecessary
shortening of variable names in one.

4 years agomkosi: fix inverted conditions for package metadata removal
Zbigniew Jędrzejewski-Szmek [Fri, 21 May 2021 11:52:16 +0000 (13:52 +0200)] 
mkosi: fix inverted conditions for package metadata removal

The same (wrong) pattern was used in a few places. And I think 'not any(…)' is
more natural in this can than 'all(not …)'.

4 years ago[unified_kernel_install] Really pick a default prefix name
Paymon MARANDI [Thu, 29 Apr 2021 22:50:48 +0000 (18:50 -0400)] 
[unified_kernel_install] Really pick a default prefix name

with empty string for args.image_id we end up with an odd looking
BOOT_BINARY which results in calling dracut as such:

dracut: Executing: /usr/bin/dracut --uefi --kver 5.11.17-gentoo-dist
--kernel-image /usr/src/linux-5.11.17-gentoo-dist/arch/x86/boot/bzImage
--kernel-cmdline "rhgb selinux=0 audit=0 rw" --force
/efi/EFI/Linux/-5.11.17-gentoo-dist.efi

-n test's for _none_ empty string; -z for an empty one.

4 years agoFix: comma-delimited-list in docs examples for {,Build}Packages=
Tj [Thu, 29 Apr 2021 15:53:27 +0000 (16:53 +0100)] 
Fix: comma-delimited-list in docs examples for {,Build}Packages=

4 years agoMerge pull request #711 from behrmann/housekeeping
Daan De Meyer [Thu, 29 Apr 2021 21:09:57 +0000 (22:09 +0100)] 
Merge pull request #711 from behrmann/housekeeping

assorted housekeeping

4 years agofedora: bump default version to 34 711/head
Joerg Behrmann [Thu, 29 Apr 2021 14:29:49 +0000 (16:29 +0200)] 
fedora: bump default version to 34

4 years agofedora: add key for Fedora Linux 34
Joerg Behrmann [Thu, 29 Apr 2021 14:27:16 +0000 (16:27 +0200)] 
fedora: add key for Fedora Linux 34

4 years agomageia: remove workaround for dracut < 045
Joerg Behrmann [Thu, 29 Apr 2021 12:19:29 +0000 (14:19 +0200)] 
mageia: remove workaround for dracut < 045

According to https://pkgs.org/search/?q=dracut the smallest dracut version
available now is 046.

4 years agomkosi: trim file system after finishing all writes
Lennart Poettering [Fri, 16 Apr 2021 19:17:48 +0000 (21:17 +0200)] 
mkosi: trim file system after finishing all writes

This is not really about actually generating sparse images, but about the
side effect that unused blocks will appear as zero, and thus the images
will be able to compress better.

Fixes: #678
4 years agomkosi: make workspace dir configurable and discover mkosi.workspace/
Lennart Poettering [Fri, 16 Apr 2021 16:37:07 +0000 (18:37 +0200)] 
mkosi: make workspace dir configurable and discover mkosi.workspace/

So far we determined the workspace directory from $TMPDIR and /var/tmp
if that wasn't set. In some cases this is less than ideal though, in
particular if one wants to build a btrfs image but /var/tmp is not
btrfs. In that case it makes sense to always use a local workspace dir.
This adds support for this:

WorkspaceDirectory= + --workspace-dir= may not be used to configure it
explicitly.

if "mkosi.workspace/" exists, we use it automatically.

Otherwise we use TMPDIR and /var/tmp as fallback.

4 years agomkosi: fix fs superblock metadata for root fs in UsrOnly= mode
Lennart Poettering [Fri, 16 Apr 2021 16:55:11 +0000 (18:55 +0200)] 
mkosi: fix fs superblock metadata for root fs in UsrOnly= mode

4 years agomkosi: don't bother with btrfs subvolumes if the rootfs is generated
Lennart Poettering [Fri, 16 Apr 2021 16:39:28 +0000 (18:39 +0200)] 
mkosi: don't bother with btrfs subvolumes if the rootfs is generated

4 years agoRevert "[usr_only] compensate for corner cases"
Lennart Poettering [Fri, 16 Apr 2021 18:37:50 +0000 (20:37 +0200)] 
Revert "[usr_only] compensate for corner cases"

This reverts commit f0386b00cfd2c897cbbaad50b0e717e7221676bc.

4 years agomkosi: fix extraction of partitions
Lennart Poettering [Fri, 16 Apr 2021 19:20:50 +0000 (21:20 +0200)] 
mkosi: fix extraction of partitions

Add missing ","

4 years ago[usr_only] compensate for corner cases
Paymon MARANDI [Sat, 10 Apr 2021 17:50:05 +0000 (13:50 -0400)] 
[usr_only] compensate for corner cases

i kept hitting this with OutputFormat.gpt_btrfs.
maybe the logic of including usr_only in minimize cases requires
revisiting? maybe "/usr" itself can be a subvol?

4 years agoalways use same tagline "Build Bespoke OS Images"
Lennart Poettering [Fri, 16 Apr 2021 15:36:13 +0000 (17:36 +0200)] 
always use same tagline "Build Bespoke OS Images"

Follow-up for b365720596d6ec6c54b3c5fe10d793e5596eeda6: two cases were
missed.

4 years agoMerge pull request #693 from poettering/roothash-suffix-fix
Daan De Meyer [Fri, 16 Apr 2021 10:56:32 +0000 (11:56 +0100)] 
Merge pull request #693 from poettering/roothash-suffix-fix

mkosi: some fixes for UsrOnly= + other follow-ups

4 years agoReplace "legacy-free" with "bespoke" in descriptions
Zbigniew Jędrzejewski-Szmek [Thu, 15 Apr 2021 07:31:07 +0000 (09:31 +0200)] 
Replace "legacy-free" with "bespoke" in descriptions

Since the introduction of grub2 support, legacy-free is not really true.

  bespoke
    adj 1: (of clothing) custom-made [syn: {bespoke}, {bespoken},
           {made-to-order}, {tailored}, {tailor-made}]

    Any product that is special in some way, individually created for
    a specific user or system, as opposed to generic or off-the-shelf.

In the text, say "customized" to avoid repeating the same word.

Also "systemd based" → "systemd-based", "-" → "—" where appropriate.

4 years agomkosi: in UsrOnly=yes mode, generate a mount.usr= kernel cmdline switch 693/head
Lennart Poettering [Wed, 7 Apr 2021 12:43:05 +0000 (14:43 +0200)] 
mkosi: in UsrOnly=yes mode, generate a mount.usr= kernel cmdline switch

So far, we relied on gpt-auto's logic to automatically find the root fs
on the image. This is not supported for finding the /usr partition
though, hence generate a mount.usr= kernel cmdline option to address
this.

(And it's unlikely we'll add auto-discovery for /usr, since we cannot
realistically decide whether its worth waiting for /usr. After all we
*know* we can't proceed without a rootfs, hence it makes sense to
generically wait for one if we never got one configured one. But a /usr
partition is an optional thing, hence it doesn't make sense to wait for
it if we didn#t get told about it)

4 years agomkosi: rework how we pass roothash/usrhash/other metadata to kernel-install
Lennart Poettering [Wed, 7 Apr 2021 12:23:04 +0000 (14:23 +0200)] 
mkosi: rework how we pass roothash/usrhash/other metadata to kernel-install

Previously, we'd replace the main kernel-install script with one
generated by mkosi and pass the roothash/usrhash as final argument on
the command line. That's less than ideal though, since it collides with
the documented way kernel-install dropins are called (those arguments
are initrds, not root hashes according to the docs). Moreover, it leaves
no nice way to pass usrhash vs. roothash or pass other information.

Let's fix this all, by changing the script to look for the roothash in
$ROOTHASH and the usrhash in $USRHASH. Then pass these env vars when
invoking the script, and drop any additional arguments.

Also, add the $IMAGE_ID and $IMAGE_VERSION in a similar fashion and then
use those preferably to name the generated kernel images.

With all this in place we are fully "standards-compliant" again,
matching the documented kernel-install drop-in API, the kernel images
are named a lot more nicely, and the usrhash logic starts working too.

4 years agomkosi: change /root/dest --bind= line to match the others
Lennart Poettering [Thu, 1 Apr 2021 15:26:08 +0000 (17:26 +0200)] 
mkosi: change /root/dest --bind= line to match the others

4 years agomkosi: make sure to mount /root/ from outside if UsrOnly=
Lennart Poettering [Thu, 1 Apr 2021 14:34:10 +0000 (16:34 +0200)] 
mkosi: make sure to mount /root/ from outside if UsrOnly=

When using mkosi in build script mode we copy stuff into /root/, as
that's where we build things in. In UsrOnly= mode that directory is not
persistent though, which makes the excercise pointless. Hence, in
UsrOnly= mode let's mount /root/ from a persistent directory from our
workspace.

4 years agomkosi: fix suffix for roothash file
Lennart Poettering [Thu, 25 Mar 2021 08:50:35 +0000 (09:50 +0100)] 
mkosi: fix suffix for roothash file

The file is supposed to be called .usrhash if we do a build without a
root dir. At least that's what systemd's automatic discovery looks for,
see:

https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RootHash=

4 years agomkosi: add new initrd-usr-fs.target to initrd
Lennart Poettering [Thu, 1 Apr 2021 13:29:45 +0000 (15:29 +0200)] 
mkosi: add new initrd-usr-fs.target to initrd

This is a recent addition in systemd, required to make cases work where
the initrd creates a root fs on first boot and images are initially
shipped without one.

(See https://github.com/systemd/systemd/pull/19234)

While we are at it, let's order the list of extra initrd files
alphabetically.

4 years agomkosi: insert rootfs in read-only mode if that's requested, not only if squashfs
Lennart Poettering [Thu, 25 Mar 2021 20:38:53 +0000 (21:38 +0100)] 
mkosi: insert rootfs in read-only mode if that's requested, not only if squashfs

4 years agomkosi: drop unused argument from make_verity()
Lennart Poettering [Fri, 26 Mar 2021 09:14:30 +0000 (10:14 +0100)] 
mkosi: drop unused argument from make_verity()

4 years agoMerge pull request #692 from poettering/versioning
Daan De Meyer [Wed, 14 Apr 2021 23:16:03 +0000 (00:16 +0100)] 
Merge pull request #692 from poettering/versioning

simple image ID/versioning

4 years agodoc: document the new image identification/versioning features 692/head
Lennart Poettering [Thu, 18 Mar 2021 20:04:20 +0000 (21:04 +0100)] 
doc: document the new image identification/versioning features

4 years agomkosi: if we have an image id (any maybe image version) use it to label partitions
Lennart Poettering [Thu, 25 Mar 2021 19:43:49 +0000 (20:43 +0100)] 
mkosi: if we have an image id (any maybe image version) use it to label partitions

This makes a lot of conceptual sense (since labels probably should
better declare what you find *in* a partition instead of just a
description of the type of it, because we already can generate that
automatically from the GPT UUID).

But it's also useful in conjunction with systemd's logic of always
picking the newest version of a root partition to mount in
systemd-nspawn and related commands, i.e.

https://github.com/systemd/systemd/pull/18958

On top of that this is useful in combination with SplitArtifacts=as then
the partitions and the split files will carry the same (except for the
suffix).

4 years agomkosi: add "image-id" concept in addition to "image-version"
Lennart Poettering [Thu, 25 Mar 2021 16:58:10 +0000 (17:58 +0100)] 
mkosi: add "image-id" concept in addition to "image-version"

A previous commit added an image version concept. Let' build on that and
add "image-id" too to match this systemd PR:

https://github.com/systemd/systemd/pull/19093

The image ID is used for naming the enerating artifacts if that's not
explicitly set (instead of the generic "image" as before) and is passed
to th build scripts via an IMAGE_ID env var matching the IMAGE_VERSION
the earlier commit added.

The idea is that the image version and ID passed here is ultimately
written to /etc/os-release by the build script (possibly mangled) and
the mkosi concepts for this hence ultimately propagate into the image
itself in some form even if not 1:1 (depending on the project of
course).

4 years agomkosi: add new --auto-bump switch for automatically bumping version after each succes...
Lennart Poettering [Thu, 18 Mar 2021 19:40:28 +0000 (20:40 +0100)] 
mkosi: add new --auto-bump switch for automatically bumping version after each successful build

Often it make sense to combine "build" and "bump" into one, so that the
a series of builds comes with a linearly increasing series of version
numbers. Add a new switch --auto-bump for that (or -B in short).

4 years agomkosi: add "mkosi bump" verb for bumping the image version
Lennart Poettering [Thu, 18 Mar 2021 19:12:53 +0000 (20:12 +0100)] 
mkosi: add "mkosi bump" verb for bumping the image version

This is a simple verb that reads the image version, and increases the
last dot-separated component of it by one and writes it to
mkosi.version. It's supposed to be a very simple call only for linear
version bumps. For anything more complex people should manually edit the
file or override it temporarily via --image-version= or so.

4 years agomkosi: add very simple image versioning concept
Lennart Poettering [Thu, 18 Mar 2021 17:54:35 +0000 (18:54 +0100)] 
mkosi: add very simple image versioning concept

This adds a "image version" concept to mkos. Via the
ImageVersion=/--image-version= settings or the `mkosi.version` file a
version string may be defined. This is used for two things:

1. It is included in the (default) output filename. i.e. instead of
   "image.raw" the files will be called "image-0.1.raw" for a version of
   "0.1" and so on.

2. It is passed as IMAGE_VERSION to the build script (the script could
   use it and patch it into /etc/os-release or so for example)

(In case you wonder why this is called ImageVersion=/--image-version=
instead of just Version=/--version, that's because there's already a
command line switch for the latter that prints mkosi's own version
number)

Fixes: #626
4 years agoMerge pull request #688 from poettering/split-generated-pure
Daan De Meyer [Wed, 14 Apr 2021 18:40:49 +0000 (19:40 +0100)] 
Merge pull request #688 from poettering/split-generated-pure

optionally write out rootfs/verity/kernel as split out files in GPT images

4 years agomkosi: let's generate the bmap output file name without ".raw.xz" too 688/head
Lennart Poettering [Thu, 18 Mar 2021 15:57:09 +0000 (16:57 +0100)] 
mkosi: let's generate the bmap output file name without ".raw.xz" too

Let's reuse our nice generic infrastructure for generating output file
names.

4 years agomkosi: optionally, also write rootfs/verity/kernel into split out files
Lennart Poettering [Thu, 18 Mar 2021 15:56:13 +0000 (16:56 +0100)] 
mkosi: optionally, also write rootfs/verity/kernel into split out files

This is useful for A/B update systems where we want to update the root
fs/verity partition/kernel only but leave the rest in tact.

Fixes: #625
4 years agomkosi: don't make efivarfs.ko a hard dep
Lennart Poettering [Thu, 18 Mar 2021 15:52:14 +0000 (16:52 +0100)] 
mkosi: don't make efivarfs.ko a hard dep

Some distros build this as kmod, others build it in. Hence only package
it up if it exists, i.e. pull it in weakly only.

(Quite frankly, distros that don't build it in are stupid, they should
fix that, it's needed almost always and is tiny.)

Follow-up for 9244e1dcdc056a7e9c457222a858a852a7965078

4 years agomkosi: fix bootable + verity /usr/ builds
Lennart Poettering [Thu, 18 Mar 2021 15:53:43 +0000 (16:53 +0100)] 
mkosi: fix bootable + verity /usr/ builds

This fixes two issues with UsrOnly=yes builds that are bootable and have
verity:

1. use the right partition type uuid for the verity partition
2. fix the umount path when we invoke dracut in a /usr-only build, since
   "umount --recursive" insists on having a mount point at the specified
   path, which we previously didn't necessarily. Let's add a bind mount
   on itself there to address this.

A follow-up for: #676

4 years agoAttempt to retry the SSH connection if the veth/SSH server is not up yet
Frantisek Sumsal [Tue, 23 Mar 2021 15:55:48 +0000 (16:55 +0100)] 
Attempt to retry the SSH connection if the veth/SSH server is not up yet

This commit introduces a new option `--ssh-timeout=` to allow setting
a timeout for which `mkosi` will attempt to retry the SSH connection in
case the link not properly set up yet (e.g. when running `mkosi qemu` and
`mkosi ssh` in a script, the veth may not be configured yet, causing the
ssh connection to fail).

Fixes: #684
4 years agomkosi: insert generated file systems sparsely
Lennart Poettering [Thu, 18 Mar 2021 15:54:11 +0000 (16:54 +0100)] 
mkosi: insert generated file systems sparsely

Let's lower our disk footprint a bit, by copying in file systems
sparsely.

4 years agoAllow overriding the SSH key pair
Frantisek Sumsal [Tue, 16 Mar 2021 18:01:46 +0000 (19:01 +0100)] 
Allow overriding the SSH key pair

Allow using a pre-defined SSH key pair instead of generating a new one.
This should be useful, for example, in CI environments, where the images
are built and used at different times, and using the same SSH key pair
across multiple images is more convenient.

4 years agomkosi: add UsrOnly= setting for generating images with only a /usr/ partition
Lennart Poettering [Thu, 11 Mar 2021 21:59:57 +0000 (22:59 +0100)] 
mkosi: add UsrOnly= setting for generating images with only a /usr/ partition

This adds a new boolean option that changes our image layout slightly:
instead of include the whole root fs in the image, we just pack up the
/usr/ subtree.

This has two usecases:

1. Truly stateless systems that come up pristine on every single boot,
   where /etc and /var are populated by tmpfiles/sysusers and related
   calls

2. Systems that are shipped without root fs, but where systemd-repart
   adds one in, with a locally generated encryption key and so on. (this
   doesn't work fully yet, because of some initrd issues, will look at
   this later.)

A companion PR on the systemd side is: https://github.com/systemd/systemd/pull/18958

Fixes: #634
(This incorporates many fixes by @behrmann. Thank you!)

4 years agoInclude `systemd.volatile` infrastructure in initrd
Nicolas Trangez [Thu, 11 Mar 2021 13:37:49 +0000 (14:37 +0100)] 
Include `systemd.volatile` infrastructure in initrd

For the `systemd.volatile=...` feature to work, the
`systemd-volatile-root` generator and `systemd-volatile-root.service`
service are required to be present. Booting a read-only image generated
by `mkosi` (e.g., `gpt_ext4` built with the `--read-only` flag, or a
`gpt_squashfs` image) with a volatile but mutable overlay is useful, so
we need to provide these files in the `initrd` Dracut generates.

Hence, adding both files to `DRACUT_SYSTEMD_EXTRAS`.

Fixes: #674
See: https://github.com/systemd/mkosi/issues/674

4 years agomkosi: add fedora 33 gpg key hash
Lennart Poettering [Tue, 9 Mar 2021 13:34:56 +0000 (14:34 +0100)] 
mkosi: add fedora 33 gpg key hash

4 years agoMerge pull request #671 from mrc0mmand/doc-fixes
Daan De Meyer [Fri, 5 Mar 2021 14:48:44 +0000 (14:48 +0000)] 
Merge pull request #671 from mrc0mmand/doc-fixes

A couple of doc fixes

4 years agoPass the list of choices to argparse.Action 671/head
Frantisek Sumsal [Fri, 5 Mar 2021 12:06:12 +0000 (13:06 +0100)] 
Pass the list of choices to argparse.Action

This way our custom ListAction action can properly generate a list of
choices in the help message when the metavar is not defined:

Before:
$ mkosi --help
...
  --debug SELECTOR      Turn on debugging output

After:
$ mkosi --help
...
  --debug {run,build-script,workspace-command}
                          Turn on debugging output

4 years agoDocument the --prepare-script config file counterpart
Frantisek Sumsal [Fri, 5 Mar 2021 12:04:38 +0000 (13:04 +0100)] 
Document the --prepare-script config file counterpart

4 years agoMerge pull request #663 from liam-mcb/encrypted-squashfs
Daan De Meyer [Thu, 4 Mar 2021 11:34:07 +0000 (11:34 +0000)] 
Merge pull request #663 from liam-mcb/encrypted-squashfs

Fix encrypted gpt_squashfs

4 years agoFix generated root partition being too small for encrypted images. 663/head
Liam McBirnie [Sun, 28 Feb 2021 20:43:27 +0000 (21:43 +0100)] 
Fix generated root partition being too small for encrypted images.

Building encrypted minimized or squashfs images was failing
at the 'dd' command in 'insert_partition' with the
error 'No space left on device'.
Increasing the luks overhead from 2MB to 16MB allows enough space.
16MB was found to be the smallest overhead which wouldn't fail.

4 years agoFix incorrect arguments given to 'luks_format_root'.
Liam McBirnie [Sun, 28 Feb 2021 20:31:00 +0000 (21:31 +0100)] 
Fix incorrect arguments given to 'luks_format_root'.

Commit 99453d9c added a 'cached' parameter to the 'luks_format_root'
command but didn't add the paramter to where the command is called
inside 'insert_partition'.
This patch sets 'cached' to False and fixes 'inserting_generated_root'
which should be True.

4 years agoReread partition table after inserting partition.
Liam McBirnie [Sun, 28 Feb 2021 20:24:40 +0000 (21:24 +0100)] 
Reread partition table after inserting partition.

Fixes issue where the sfdisk command fails to re-read the partition
table when creating a squashfs image with encrypted data.
This is because the encrypted data partition is mounted so sfdisk gives
the warning 'Device or resource busy'.
This causes the 'dd' command failing because it can't find the newly
created partition.

4 years agoMerge pull request #670 from behrmann/cosmetics
Daan De Meyer [Tue, 2 Mar 2021 19:06:13 +0000 (19:06 +0000)] 
Merge pull request #670 from behrmann/cosmetics

Cosmetics

4 years agoci: add isort 670/head
Joerg Behrmann [Tue, 2 Mar 2021 17:27:44 +0000 (18:27 +0100)] 
ci: add isort

4 years agoblack: bump code style to py37
Joerg Behrmann [Tue, 2 Mar 2021 17:27:26 +0000 (18:27 +0100)] 
black: bump code style to py37

4 years agomkosi: add new simple "serve" verb for serving built images via HTTP
Lennart Poettering [Tue, 2 Mar 2021 16:34:30 +0000 (17:34 +0100)] 
mkosi: add new simple "serve" verb for serving built images via HTTP

If found this quite useful for testing things with "machinectl pull-tar"
and "machinectl pull-raw": add a tiny HTTP server that can serve the
generated output once it#s done. Love the simplicity of this:

```
mkosi -i -f serve
```

and then

```
machinectl pull-raw http://localhost:8081/image.raw --verify=checksum
```

4 years agomkosi: explicitly flush SHA256SUMS file
Lennart Poettering [Tue, 2 Mar 2021 16:32:07 +0000 (17:32 +0100)] 
mkosi: explicitly flush SHA256SUMS file

Apparently we have to flush things explicitly after writing it,
otherwise things remain buffered by python IO and the SHA256SUMS file
will remain empty on disk.

4 years agomkosi: fix minor typo in docs
Lennart Poettering [Tue, 2 Mar 2021 16:37:21 +0000 (17:37 +0100)] 
mkosi: fix minor typo in docs

4 years agomkosi.md: update documentation to match https://github.com/systemd/mkosi/pull/462
Eduard Tolosa [Tue, 2 Mar 2021 08:42:42 +0000 (03:42 -0500)] 
mkosi.md: update documentation to match https://github.com/systemd/mkosi/pull/462

4 years agomkosi: fix table indenting of summary output
Lennart Poettering [Tue, 2 Mar 2021 16:30:32 +0000 (17:30 +0100)] 
mkosi: fix table indenting of summary output

4 years agoOpenMandriva: support more architectures, and install systemd-networkd if requested...
tpgxyz [Fri, 26 Feb 2021 15:11:41 +0000 (16:11 +0100)] 
OpenMandriva: support more architectures, and install systemd-networkd if requested by options