| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
| |
unpfs now listens on a Unix socket next to Firecracker's vsock uds_path,
where Firecracker forwards the guest's connections to vsock port 564.
The kernel's 9P client can't use vsock itself, so the guest's
xchg.service connects with socat and hands the socket to mount
(trans=fd). xchg no longer depends on the network: no TCP ports, no
firewall rules, no waiting for DHCP.
|
| |
|
|
|
|
|
|
|
|
| |
The run script starts unpfs (as the user) on 172.16.0.1, port 5640 plus
the tap's number, and tells the guest to mount it at /xchg via
systemd.mount-extra on the kernel command line. VMs started in the same
directory share xchg, writes land on the host right away, and nothing is
lost when a guest doesn't shut down cleanly. No more debugfs rdump.
The cut-down kernel gets 9P as modules.
|
| |
|
|
|
|
| |
It forwards to the servers in the host's resolv.conf and listens only on
fcbr0, so it doesn't get in the way of a resolver on the host's loopback.
The service is renamed from fcbr0-dhcp to fcbr0-dnsmasq.
|
| |
|
|
|
| |
The guest's resolv.conf and the DHCP server now point at 172.16.0.1, so
the host's resolver has to answer there.
|
| |
|
|
|
|
|
|
|
|
| |
host.nix now makes a bridge fcbr0 with a number of tap devices (default 8)
and runs a dnsmasq of its own for DHCP. The run script takes the first
tap device it can lock and derives the guest MAC from its number. The
guest uses DHCP, with the MAC as client identifier, as the machine-id
(and thus the default DUID) is the same in every VM.
host.nix now takes { user, taps ? 8 } instead of just the user.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When starting, PID 1 asks /dev/console for its terminal type (see
main.c, unless TERM or systemd.tty.term.console is on the kernel command
line), which costs the 333ms timeout twice, in the initrd and again
after switching root:
[0.161825] systemd[1]: IPE support is disabled in the kernel, ignoring: ...
[0.495506] systemd[1]: Failed to query /dev/console for terminfo: Operation not supported
...
[1.051161] systemd[1]: IPE support is disabled in the kernel, ignoring: ...
[1.385218] systemd[1]: Failed to query /dev/console for terminfo: Operation not supported
Pass systemd.tty.term.console along with systemd.tty.term.ttyS0, and
fall back to "dumb" without $TERM, as then nobody would answer either.
|
| |
|
|
|
|
|
| |
After switching root, systemd runs 15 generators before it loads any
units, each a separate process loading libsystemd-shared from the store
image. Only fstab and getty generate anything here; the others report
things like "not an EFI boot" or "sshd is not installed".
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In the initrd, NixOS Activation spends ~0.1s before its first output and
~0.15s in total, running prepare-root and the activation script in bash
from the (cold) store image:
[0.907724] Starting NixOS Activation...
[1.009663] booting system configuration /nix/store/...
[1.054987] Finished NixOS Activation.
nixos-init does the same from a single program. perlless already
gives us what it requires: systemd in the initrd, an overlay /etc and
userborn.
Mount the store with nodev,nosuid right away, so nixos-init doesn't
have to remount it.
|
| |
|
|
|
|
|
|
|
|
|
|
| |
Creating the ten setuid wrappers takes ~130ms and is the last thing
sysinit.target waits for:
[1.896068] Starting Create SUID/SGID Wrappers...
[2.025499] Finished Create SUID/SGID Wrappers.
[2.027817] Reached target System Initialization.
The only wrapper needed during boot is unix_chkpwd, for the autologin,
so order the wrappers before systemd-user-sessions.service instead.
|
| |
|
|
|
|
|
|
|
|
| |
With an empty /var on every boot, systemd-journal-catalog-update and
systemd-update-done run every time (ConditionNeedsUpdate=/var), and
they're in the critical path to sysinit.target. Suppress them.
Keep the journal in /run, so systemd-journal-flush has nothing to do, and
drop pam_lastlog2 from login, which also gets rid of
lastlog2-import.service.
|
| |
|
|
|
|
|
|
|
| |
With a tmpfs root, every boot is a first boot, which makes systemd
apply presets and commit a transient machine-id.
There's no display, so the getty on tty1 only opens a session nobody
sees. The serial getty is pulled in by systemd-getty-generator, not
by getty.target.wants.
|
| |
|
|
|
|
|
|
|
|
| |
Passing the terminal size didn't help: the serial login still completes
~0.39s after the getty started. Unless systemd.tty.term.ttyS0 is on
the kernel command line, systemd also asks the terminal for its type
(via DCS +q, see query_term_for_tty in src/basic/terminal-util.c),
which many terminals don't answer, so it waits for the 333ms timeout.
Pass $TERM along with the size.
|
| |
|
|
|
|
| |
Fixes:
evaluation warning: 'system' has been renamed to/replaced by 'stdenv.hostPlatform.system'
|
| |
|
|
|
|
|
|
|
|
| |
debugfs' rdump tries to restore the owner of every file it extracts,
which fails when not running as root:
dump_file: Operation not permitted while changing ownership of xchg.new//boot.txt
The files end up owned by the user running the VM, which is what we
want, so drop these messages.
|
| |
|
|
|
|
|
|
|
|
| |
Firecracker can't share directories, so run-firecracker-vm copies the
directory xchg (in the current working directory) into an ext4 image
before booting, and replaces it with the image's contents when the
guest exits. The guest automounts the image at /xchg.
Changes made in the guest only arrive if it exits cleanly (e.g. via
reboot), as debugfs doesn't replay the ext4 journal.
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
When starting the serial getty, systemd asks the terminal for its size
via ANSI sequences and waits up to 333ms for an answer (see
CONSOLE_ANSI_SEQUENCE_TIMEOUT_USEC in src/basic/terminal-util.c). The
journal shows the serial login completing ~0.4s after the getty started,
while the getty on tty1 took 0.08s.
systemd skips the query if systemd.tty.rows.ttyS0 and
systemd.tty.columns.ttyS0 are on the kernel command line, so take them
from the terminal run-firecracker-vm is started from. This also gives
the guest the right terminal size.
|
| |
|
|
|
|
|
|
| |
Building the erofs image takes ~2.5s, as long as the guest's initrd.
Keep the image of the last closure in $XDG_CACHE_HOME/run-firecracker-vm,
named by the hash of the store path list, and rebuild it only when the
closure changes. Older images get deleted; running VMs keep theirs
open.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
systemd processes at most 5 mount events per second (see
src/core/mount.c). Booting from a tmpfs root with an erofs store and
an overlay /etc exceeds that, and each time the next mount waits for
the next one-second window. The boot journal shows three such stalls,
two of them exactly one second apart:
[0.789652] Finished Virtual Console Setup.
[1.588264] Mounting /sysroot...
[1.675477] initrd-parse-etc.service: Triggering OnSuccess= dependencies.
[2.588523] Mounting /run/nixos-etc-metadata...
[3.799810] Finished Virtual Console Setup.
[4.446154] Mounting /run/wrappers...
The limit can be overridden via PID 1's environment, which the kernel
populates from unrecognized command line parameters. A burst of 0
disables it. systemd passes its original environment on when
switching root, so this covers the initrd and stage 2.
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
Give the guest a virtio-net interface backed by the host tap device
fctap0, with a static address (172.16.0.2/24, gateway 172.16.0.1) set up
by systemd-networkd, and 9.9.9.9 as nameserver.
host.nix is a NixOS module for the host that creates fctap0, owned by
the given user, and NATs it:
imports = [ (import ./host.nix "tv") ];
Firecracker refuses to start if fctap0 doesn't exist.
|
| |
|
|
|
|
|
|
|
|
|
| |
Import the minimal and perlless profiles, and turn off what a throwaway
VM with a read-only store doesn't need: firewall (which also failed to
start with the cut-down kernel), timesyncd (kvm-clock keeps time), nscd,
sudo and setuid wrappers, coredumps, oomd, TPM2, fstrim, lvm, bcache,
kexec, containers, lingering, nano, fuse and switch-to-configuration.
This shrinks the guest closure from 709 MiB to 560 MiB with the default
kernel, most of what's left being kernel modules, systemd and glibc.
|
| |
|
|
|
|
|
|
|
|
|
|
| |
kernel.nix builds Linux 6.18 with Firecracker's recommended guest
configuration (resources/guest_configs/microvm-kernel-ci-x86_64-6.18.config),
plus erofs as a module. Use it with
nix-build --arg kernelPackages 'import ./kernel.nix {}'
Everything Firecracker needs is built in, so NixOS' default initrd
modules (ahci, efivarfs, ...) don't exist; allowMissingModules lets the
initrd build anyway.
|
| |
|
|
| |
8250.nr_uarts=1 stops probing of the legacy ports of ttyS1..ttyS3.
|
| |
|
|
|
| |
Default to linuxPackages_latest, which matches a host running the
latest kernel from the same channel, so no extra kernel gets built.
|
|
|
Boot a NixOS guest in Firecracker and drop into a root shell on ttyS0.
Firecracker can't share directories with the guest (no 9p or
virtio-fs), so the host store is exposed as a read-only block device:
run-firecracker-vm packs the guest system's closure, plus the closures
of any store paths given as arguments, into a temporary erofs image,
which the guest mounts at /nix/store. Root is a tmpfs.
|