This is useful during development to allow 'import mkosi', for
example to test import functions and such. In the future it'll also
be useful if we grow any unittests.
This is similar to 'mkosi.postinst', but is called in the host. This
makes it much easier to copy-in files. It is also much quicker when
creating images for a foreign architecture.
v2:
- s/postinst2/finalize/g
- call the script first with "build" too
- pass the root directory as $BUILDROOT (like rpmbuild) and not as
a positional argument. (This is easier to consume for scripts and
also easier to extend with additional variables in the future.)
- update to use args_find_path()
For example, snaps have to be generated with "-noappend -no-xattrs
-no-fragments -comp xz". The last argument is configurable through
Compress=xz, but the other ones weren't so far. Let's just override the
mksquashfs executable. To be nice and flexible, 'mkosi.mksquashfs-tool'
will be autodetected. It may be also specified explicitly:
[Output]
Mksquashfs=/some/special/mksquashfs
If specfied explicitly, an argument list may be included:
When args are present, they replace "-noappend" that we add by default.
The arguments for compression (-comp xx) is always added if configured
by Compress=. This makes the two settings orthogonal.
This is actually more readable because the variable name definitions
and paths are defined at one place and not spread over all the itty
bitty functions.
I used '' for the variable names and "" for paths. I think that makes
the two types of arguments a bit more distinguishable.
Lucas De Marchi [Tue, 6 Nov 2018 08:25:36 +0000 (00:25 -0800)]
Fix wrong type to link_output
$ sudo mkosi --default /dev/null -d fedora -r 29 -t directory -p dnf
...
Traceback (most recent call last):
File "/bin/mkosi", line 3959, in <module>
main()
File "/bin/mkosi", line 3949, in main
build_stuff(args)
File "/bin/mkosi", line 3809, in build_stuff
link_output(args, workspace, raw or tar)
File "/bin/mkosi", line 2478, in link_output
os.rename(os.path.join(workspace, "root"), args.output)
File "/usr/lib64/python3.7/posixpath.py", line 80, in join
a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not TemporaryDirectory
luks_setup_all() depends on this function returning None in case
partno is None. Fixing it in the caller overly complicates it.
Let's fix the breakage and maybe later rework the code.
fedora/centos: do no install systemd and passwd by default
There is no reason to require passwd to be installed. Depending on
what the image is used for, user logins through with traditional
authentication might be completely unnecessary. Similarly, systemd is
only useful when the image is to be booted (under qemu or as a
container). But when args.bootable is true, systemd-udev will pull in
systemd anyway. So let's just reduce the packages we always pull in to
the minimum that defines each distro. Any additional packages should
be pulled in through the project configuration.
Dnf data is removed if dnf is not installed into the image, and similarly
for the other tools.
I didn't implement this functionality for Debian/Ubuntu/Arch, because I
don't know enough about those distros, but is should be easy to add.
The arguments that are passwd to build_image() and friends are made
keyword-only. There's now three arguments, and this way there's less
chance of mistake.
v2:
- When deciding whether to keep dnf or rpm data, check if path exists
Checking if the dnf/rpm packages are in the requested list is nice,
but inadequate. For example, somebody could specifyg a @group or just
another package that pulls those in. Checking if the executables are
present in the image would work in those cases too.
Two obvious bugs are fixed:
- boot_packages were always used, because run_build_script was used in a
conditional, but this name wasn't a local variable but the global function, so
it was always true ('run_build_script=True|False' wasn't passed down properly
to invoke_yum()/invoke_dnf()).
- in invoke_yum() xfsprogs wasn't added like in install_dnf().
Generating the list of packages first instead of interleaving that with
other args seems cleaner and easier to debug. The code to do that is now
shared between yum and dnf.
This allows the in-fs compression algorithm to be selected: e.g. zstd
is better in pretty much all cases than zlib or xz. Lz4 might be a
good choice if speed is very important, etc.
Exact algorithms supported by both the tools and the kernel vary, so only
a general check if the algorithm name is known is done.
Note: support for zstd was added to fs/squahsfs in linux v4.13-rc5-4-g87bf54bb43.
But it seems that mksquashfs in F28 does not support zstd. Strange.
Rename RAW_FORMATS to is_disk() and RAW_RW_FS_FORMATS to is_disk_rw()
The new names actually reflect the meaning. I chose "is_disk" over
"is_gpt" because it is more general and will also work if we decide to
generate other disk formats, e.g. ISO images or disks with DOS
partitions.
They are not "raw" in any meaningful way, since the filesystems are
packaged in a disk image with a gpt partition. I know that "raw" comes
from qemu, where it used to mean e.g. not-qcow2, but since we don't
produce qcow2 or any of the other formats, here it is just misleading.
Also, use auto() to number OutputFormat members and don't show compat names
in help output.
v2:
- add .__repr__() and .__str__() and .from_string() to make the --help
output message and the error message when an unknown type is given nicer.
The option is written in a way that allows additional selectors to be added
easily. This patch adds just one: --debug=run, that simply prints all commands
as they are executed similarly to make.
Traceback (most recent call last):
File "/bin/mkosi", line 3767, in <module>
main()
File "/bin/mkosi", line 3757, in main
build_stuff(args)
File "/bin/mkosi", line 3573, in build_stuff
setup_package_cache(args)
File "/bin/mkosi", line 2412, in setup_package_cache
d = tempfile.TemporaryDirectory(dir=os.path.dirname(args.output), prefix=".mkosi-")
File "/usr/lib64/python3.7/tempfile.py", line 788, in __init__
self.name = mkdtemp(suffix, prefix, dir)
File "/usr/lib64/python3.7/tempfile.py", line 366, in mkdtemp
_os.mkdir(file, 0o700)
FileNotFoundError: [Errno 2] No such file or directory: '/home/lucas/p/mkosi/bla/.mkosi-l3oxfchg'
mkosi: strictly require offline operation from systemctl
It's very likely systemctl will run in one of the scripts. Let's always
make sure it never even tries to talk to PID, simply as a matter of
robustness.
Zygmunt Krynicki [Wed, 24 Oct 2018 11:33:09 +0000 (13:33 +0200)]
Add CommandLineArguments type
This patch adds a new type that is the result of parsing command line
arguments via argparse.ArgumentParser.parse_args(). This type will gain
typed attributes that will allow to type check all the functions using
it, gradually, one by one.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
fedora: add new dir and make mkosi.default just a symlink
Contributors from other distros will probably want to add similar
configs, so it makes sense to "demote" the Fedora config. A new dir is
created to avoid cluttering the root directory with those files.
Zygmunt Krynicki [Fri, 19 Oct 2018 13:22:27 +0000 (15:22 +0200)]
Add static type annotations
This patch adds a lot of type annotations, as compatible with mypy
0.620. The type checking is not perfect as many places use loosely typed
argparse.Namespace and I didn't want to introduce any changes there.
Some errors reported by mypy now show missing None checks but I also
decided not to fix them and make the review more complex. This patch
should only annotate types, nothing else.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
By forcing the installation of glibc-minimal-langpack we avoid glibc-all-langpacks
which is quite large. See
https://fedoraproject.org/wiki/Changes/Remove_glibc-langpacks-all_from_buildroot.
While at it, configure the locale as C.utf8 so we don't get the
default which is POSIX.
Add architecture-specific paths before generic ones (they’re more likely
to be correct for the current architecture), and add some paths from the
Arch Linux `ovmf` (“extra” repository) and `edk2-ovmf` (Arch User
Repository) packages.
Chris Patterson [Tue, 13 Feb 2018 16:07:07 +0000 (11:07 -0500)]
mkosi: fix to enable Fedora rawhide support
The Fedora repos require using the release version of 'rawhide' in the URLs,
while mkosi currently forces you to select a specific version number, e.g. 28.
You can not install Fedora '28', but you can install 'rawhide', using the gpg
keys for release version '28'.
These changes:
(1) Assume the latest (known) version when --release=rawhide, but warn the user
(2) Allow user to override a specific rawhide version with the option
--release=rawhide-<version>
Lucas De Marchi [Mon, 8 Oct 2018 23:01:57 +0000 (16:01 -0700)]
Allow to run qemu >= 2.12
While trying to call "mkosi qemu" on a Clear Linux host it reported
qemu: could not load PC BIOS '/usr/share/qemu/OVMF_CODE.fd'
Cross checking with my Fedora host the only real difference I see is the
qemu version. Changing it to pass a pflash drive directly makes it work
and also make it explicit that the it is a readonly device.
By installing glibc-minimal-langpack we avoid the installation of glibc-all-langpacks
(glibc requires glibc-langpack (provided by all langpacks) and suggests
glibc-all-langpacks (so that is the default when there is nothing else to
satisfy the require). By forcing a different langpack package, we avoid the
installation of any others.
git-core is similar to git, but does not pull in some lisp and perl stuff.
kernel-core is similar to kernel, but does not include some fancy drivers.
(The conversion of string concatenation to two writes makes this snippet
more similar to the cmdline snippet below; perhaps we can later refactor
it into a helper function, similar to systemd’s write_string_file().)
Rename "Post Installation Script" to "Postinstall script" (#235)
The short version is pretty well established in packaging world, and
anyway "post-installation" or even "postinstallation" would be more
correct than "post installation" as an adjective.
Before this patch, mkosi wouldn't even run --help on a platform that
wasn't amd64 or arm64. That's unnecessarily harsh, a lot of functionality
is platform-independent and will work anywhere.