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.
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.
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.
Frantisek Sumsal [Mon, 22 Feb 2021 21:42:59 +0000 (22:42 +0100)]
Check if btrfs is available before trying to unlink a subvolume
otherwise the output is full of pointless errors on certain systems
(like CentOS 8, which doesn't support btrfs):
# mkosi --force --debug run --qemu-headless=true build
‣ Removing output files...
+ btrfs subvol show /home/vagrant/mkosi/mkosi.output/fedora.raw
‣ Error: btrfs not found in PATH.
...
‣ Configuring serial tty (ttyS0)...
‣ Cleaning dnf metadata......
+ btrfs subvol show /var/tmp/mkosi-polqexiq/root/var/log/dnf.log
‣ Error: btrfs not found in PATH.
+ btrfs subvol show /var/tmp/mkosi-polqexiq/root/var/cache/dnf
‣ Error: btrfs not found in PATH.
+ btrfs subvol show /var/tmp/mkosi-polqexiq/root/var/log/dnf.librepo.log
‣ Error: btrfs not found in PATH.
+ btrfs subvol show /var/tmp/mkosi-polqexiq/root/var/log/hawkey.log
‣ Error: btrfs not found in PATH.
+ btrfs subvol show /var/tmp/mkosi-polqexiq/root/var/lib/dnf
‣ Error: btrfs not found in PATH.
+ btrfs subvol show /var/tmp/mkosi-polqexiq/root/var/log/dnf.rpm.log
‣ Error: btrfs not found in PATH.
‣ Cleaning rpm metadata......
+ btrfs subvol show /var/tmp/mkosi-polqexiq/root/var/lib/rpm
‣ Error: btrfs not found in PATH.
‣ Resetting machine ID...
...
Frantisek Sumsal [Thu, 25 Feb 2021 15:33:48 +0000 (16:33 +0100)]
Allow overriding # of CPUs and amount of RAM for qemu guests
This commit introduces two options - `--qemu-smp` and `--qemu-mem` - which
can be used to override the default number of CPUs and amount of RAM for
guests started via the `qemu` verb.
This commit extends CommandLineArguments with all necessary fields
from the argument parser, removes the inheritance from argparse.Namespace
and fixes all resulting typing errors.
We try to stick to typing only changes as much as possible to reduce the
chance of breaking something (although there are a few non-typing changes
where doing so made things easier).
Because we use a dataclass now for the CommandLineArguments class, we
up the required python version to 3.7.
After:
sudo mkosi -d centos -r 7 --bootable --force
‣ Error: Sorry, CentOS 7 does not support unified kernel images. You must use --without-unified-kernel-images.
Michal Koutný [Fri, 12 Feb 2021 17:01:45 +0000 (18:01 +0100)]
openSUSE: Fix autologin setup
The distro PAM config resides under /usr/etc and customizations are
supposed to be under /etc. Use the distro file as a template for the
autologin customization.
Daan De Meyer [Wed, 3 Feb 2021 23:12:54 +0000 (23:12 +0000)]
qemu: Add secure boot support
Adds support for booting OVMF firmware blobs with secure boot
support.
We have to point qemu to an OVMF vars file to get this working.
Currently, we point directly at the vars file in /usr/share but
add the readonly flag so we make sure we don't modify it. I'm
hoping this means the UEFI variable changes in the VM will be
ephmeral instead of writes to these variables failing when the
readonly flag is set. If readonly means we can't enroll secure-boot,
we'll need to make a copy of the VARS file and store it somewhere so
we can remove the readonly flag.
Daan De Meyer [Wed, 3 Feb 2021 22:03:15 +0000 (22:03 +0000)]
qemu: Use q35 machine
This is necessary for booting with secure boot enabled in QEMU.
Switching to q35 somehow changed the boot order causing us to drop
into the EFI shell at boot. To fix this, I switched from virtio-blk
to virtio-scsci-pci (which is supposed to be the future anyway)
which allows us to set bootindex to override the boot order.
Joerg Behrmann [Sat, 23 Jan 2021 17:50:36 +0000 (18:50 +0100)]
mkosi: switch to RawConfigParser instead of ConfigParser
To allow for expanding systemd.unit like specifier like %u for user, we have to
disable the basic interpolation that configparser allows, because it too uses %
as its specifier.
Daan De Meyer [Sat, 23 Jan 2021 20:36:40 +0000 (20:36 +0000)]
Add support for passing arguments to the build command
Aside from environment variables, it's also useful to be able to
pass arguments to the build script. For example, in systemd we can
use this to pass the target to build to the build script. Build
scripts determine how the passed arguments are interpreted, mkosi
just passes them on.
Michal Koutný [Thu, 21 Jan 2021 17:52:43 +0000 (18:52 +0100)]
UEFI boot: make sure efivarfs loaded in initrd
The efivarfs is needed in order to GPT root partition discovery work.
Without efivarfs initrd won't be able to switch to the real root.
Add the module regardless of hostonly or distro configuration because
dracut takes into account info from the build host and not the target
distro. Adding a module that's already included in dracut's list makes
no harm.
Daan De Meyer [Thu, 21 Jan 2021 19:23:28 +0000 (19:23 +0000)]
Drop networkd not running to a warning instead of a fatal error
Without networkd, the veth link won't come up properly on the host
but that doesn't prevent mkosi boot or mkosi qemu from working so
let's drop those messages to warnings instead of fatal errors.
Daan De Meyer [Tue, 12 Jan 2021 20:36:16 +0000 (21:36 +0100)]
Remove "complete" steps from output
The next step start message implies the end of the previous step so
there's no real benefit to printing a complete message for every step.
Let's remove the message and only print a "complete" message if the
caller of complete_step() has provided a custom "complete" message.
Daan De Meyer [Sat, 9 Jan 2021 15:52:48 +0000 (16:52 +0100)]
Cache more operations
Let's cache all steps that write data directly from the config file.
This improves consistency overall and reduces noise in the output
when doing incremental builds.
Daan De Meyer [Sat, 9 Jan 2021 14:28:33 +0000 (15:28 +0100)]
Only print step execution messages if we're executing them
Replace some usage of completestep decorator with complete_step
contextmanager so we only print the step message after checking
if we actually need to execute the step.
Daan De Meyer [Fri, 15 Jan 2021 20:04:45 +0000 (21:04 +0100)]
Cache sshd enable step
We can't cache the ssh-keygen step easily because it outputs a
file on the host. However, we can cache the enable sshd step as
it only affects the image and not the host.
Daan De Meyer [Thu, 14 Jan 2021 20:18:03 +0000 (21:18 +0100)]
Don't cache --ssh setup step
Caching the SSH step is non-trivial because it adds an extra file
(the private key file) that has to be taken into account in the
caching logic. For now, let's not cache the step and silence the
stdout of the ssh-keygen command instead.
Daan De Meyer [Wed, 6 Jan 2021 17:17:11 +0000 (18:17 +0100)]
Remove "quiet" and "rhgb" from default kernel cmdline
We seem to be running into boot issues semi-regularly in CI because
of the usage of systemd.volatile=overlay. These issues are hard to
debug because we silence boot output by default. Let's enable boot
output by default so we have an easier time debugging these issues
when they occur. Also, mkosi boot shows the same output on
container startup anyway so this brings qemu more in line with mkosi
boot as well.
Daan De Meyer [Tue, 5 Jan 2021 21:07:50 +0000 (22:07 +0100)]
Search for "mkosi.default.d" relative to working directory
Searching for the mkosi.default.d dir relative to the file passed
via --default makes it almost impossible to share common settings
between multiple configs when using --default as simply specifying
a config file via --default changes the location where common configs
are searched. Instead, let's simply look for mkosi.default.d in the
mkosi working directory regardless of the path passed to --default.
Daan De Meyer [Sun, 27 Dec 2020 17:47:49 +0000 (18:47 +0100)]
Arch: Remove network configuration
Let's pull Arch in line with the other distros and not do any network
configuration. If needed, we can add this back, but let's do it behind
an option that we implement for all distros so we at least have uniformity
between distros.
Daan De Meyer [Fri, 25 Dec 2020 15:49:33 +0000 (16:49 +0100)]
Drop centos from CI (but not centos_epel)
centos_epel should be sufficient testing for centos as well. By
dropping centos, we can test SSH in CI without needing extra logic
to exclude centos from the SSH tests because networkd isn't available
on stock centos without epel.
Luca Boccassi [Wed, 23 Dec 2020 19:39:47 +0000 (19:39 +0000)]
Debian: ensure efivars.ko is installed if uefi is used
When --hostonly is used, efivars.ko is missing and thus the bootloader
cannot get the UUID of the EFI partition and fails to pivot root.
Specify it manually with add_drivers+=efivarfs if building for Debian
with EFI.
Daan De Meyer [Wed, 23 Dec 2020 14:23:48 +0000 (15:23 +0100)]
Skip output clean/check when using --skip-final-phase
When using --skip-final-phase, we're not touching any of the output
artifacts so it doesn't make sense to clean the previous output artifacts
or block execution if they already exist.
Daan De Meyer [Mon, 21 Dec 2020 15:46:36 +0000 (16:46 +0100)]
Make --autologin work even when a root password is set
Currently, --autologin still asks for a password if the root
password is not explicitly deleted. By adding some PAM short circuit
rules for the relevant TTYs, we avoid PAM asking for the root password
when a user logs in on either pts/0 (nspawn) or ttyS0 (QEMU with
--qemu-headless).
Daan De Meyer [Mon, 21 Dec 2020 14:42:21 +0000 (15:42 +0100)]
Add --source-file-transfer-final option
When debugging in the final image using a debugger, the debugging
experience is greatly improved by having the source files available.
--source-file-transfer-final does exactly what --source-file-transfer
does but applies to the final image instead of the bulid image. While
supporting 'mount' might be possible, we don't do so yet because
the use case is unclear and configuring QEMU to pass through
folders is non-trivial.
Daan De Meyer [Mon, 21 Dec 2020 12:44:01 +0000 (13:44 +0100)]
Change --source-file-transfer default to copy-git-others
I've gotten bitten multiple times by the fact that by default,
untracked files in git are not copied into the build image. Let's
fix this by changing the --source-file-transfer default to
copy-git-others. This adds any untracked files to the build image
(but still excludes ignored files).
ValdikSS [Sun, 20 Dec 2020 12:23:02 +0000 (15:23 +0300)]
Add option to strip SELinux file context from tar'ed files
This option removes (or not includes) SELinux xattrs into output tar archive.
This is a hack as mkosi does not properly support SELinux contexts. See #130.
The patch adds `--tar-strip-selinux-context` flag and `TarStripSELinuxContext` configuration file option.
Peter Hutterer [Thu, 17 Dec 2020 00:13:12 +0000 (10:13 +1000)]
Fix flake8 warnings
These are all whitespace fixes with a few exceptions:
- one "if not foo is None" -> "if foo is not None"
- one f"static string" changed to "static string"
- two "except Something as e" changed to "except Something" where e isn't
being used
Flake8 errors disabled:
501: line too long
504: line break after binary operator
741: ambiguous variable name
Flake8 errors left after this patch:
E241 multiple spaces after ','
F541 f-string is missing placeholders
Both of the above warnings are triggered by lines that are better left as-is
for consistency with the surrounding code.
Peter Hutterer [Wed, 16 Dec 2020 23:43:51 +0000 (09:43 +1000)]
Add backticks around the workspace command error
Better visual separation between the actual command and the full sentence.
We'll never have backticks in our command so unlike other quotes we don't have
to worry about escaping them, and at this point we're all used to backticks
for markdown anyway.
Daan De Meyer [Mon, 14 Dec 2020 22:19:22 +0000 (22:19 +0000)]
Explicitly specify dracut filesystem when using --hostonly-initrd
It seems dracut includes the host's filesystem when building a
hostonly image and not the image's filesystem. This causes issues
when these two don't match. Include the correct one explicitly
as a workaround.
Daan De Meyer [Fri, 11 Dec 2020 20:14:33 +0000 (20:14 +0000)]
Redirect non-redirected subprocesses output to stderr except build-script
When running a language server via mkosi, communication with the editor
is done via mkosi's stdin/stdout. If the client reads output from mkosi's
subprocesses instead of LSP json messages from stdout, it won't recognize
the output and crash. To make the language server integration work when the
build image needs to be built from scratch, we redirect all non-redirected
output from subprocesses to stderr except for the build-script. This way,
we can get progress output from mkosi right in the editor without breaking
the language server integration.
The split was already quite arbitrary in the first place. All of mkosi's messages
go to stderr and most subprocess output went to stdout. Instead, let's define
the split between stdout/stderr a bit more so we can take advantage of it.
Only the build script gets to write to stdout which simplifies language server
usage with mkosi.
Daan De Meyer [Sat, 12 Dec 2020 22:31:51 +0000 (22:31 +0000)]
Add --install-directory option
While binaries can already be retrieved using the --build-directory
option. Sometimes it's a lot easier to have access to the installed
contents instead. --install-directory allows accessing the contents
of /root/dest from the build container outside of the build image.
Daan De Meyer [Sat, 12 Dec 2020 23:00:22 +0000 (23:00 +0000)]
Create /usr/include with correct mode when --include-directory is used
Currently, when we're using --include-directory, /usr/include is created
by mount_bind() which creates /usr with 0700 (because makedirs mode
only applies to the leaf directory). Create /usr/include explicitly with
the correct mode to avoid permission warnings from pacman.
Daan De Meyer [Sat, 12 Dec 2020 22:55:36 +0000 (22:55 +0000)]
Empty include directory before installing to it
Pacman (and probably other package managers as well) expect
/usr/include to be empty when we're bootstrapping so let's make
sure we empty the directory before installing to it.
Daan De Meyer [Sat, 12 Dec 2020 14:19:41 +0000 (14:19 +0000)]
CI: Install mkosi explicitly
Since we'll soon be installing the latest stable version with the
action, let's modify CI already to do an explicit install that
installs mkosi with the latest changes from the PR.