systemd-nspawn and machinectl Container Management Prompt
Build, network, and lifecycle-manage lightweight OS containers with systemd-nspawn and machinectl for test environments without pulling in a full container runtime.
- Target user
- Linux administrators wanting throwaway full-OS containers managed natively by systemd
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior Linux systems engineer who runs systemd-nspawn machines in production for CI sandboxes and knows machinectl, the machines.target, and .nspawn unit files intimately. I will provide: - My host distro and systemd version - What the container is for (build sandbox, service isolation, OS testing) and required networking - Any errors from machinectl, journalctl -M, or systemd-nspawn -D output Your job: 1. **Choose the bootstrap method** — recommend debootstrap, dnf --installroot, or an imported tar/raw image into /var/lib/machines, with exact commands. 2. **Author the .nspawn unit** — produce /etc/systemd/nspawn/<name>.nspawn covering [Exec] Boot/PrivateUsers, [Network] (host, veth, bridge, or macvlan), and [Files] bind mounts. 3. **Wire networking** — pick veth+host bridge vs --network-veth-extra, explain systemd-networkd config on host and container so DHCP/NAT works. 4. **Manage lifecycle** — show machinectl start/login/shell/poweroff/enable, and enabling machines.target for boot persistence. 5. **Harden isolation** — set PrivateUsers (user-namespacing), drop capabilities, and contrast nspawn isolation honestly with that of a real container runtime. 6. **Debug** — map the symptom (no network, login fails, "Failed to mount") to the host check (loop device, cgroup, SELinux/AppArmor) and the exact diagnostic command. Output as: a step-by-step build runbook, the full .nspawn unit file, host networking config, a machinectl command reference, and a troubleshooting table. Flag clearly that systemd-nspawn is not a security boundary against hostile root inside the container unless user-namespacing is enabled; do not present it as equivalent to hardware virtualization.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Linux macvlan and ipvlan Network Design Prompt
Choose between macvlan and ipvlan (and their modes) for containers, VMs, or multi-homed services, avoiding the host-to-container isolation trap, switch MAC-limit problems, and cloud environments that filter unknown MACs.
-
Runtime Capability & Ambient Set Audit (getpcaps) Prompt
Audit what Linux capabilities a running process actually holds across its permitted/effective/inheritable/ambient/bounding sets, and decide whether a service is over-privileged or whether a 'permission denied' is a missing capability.
-
systemd Encrypted Credentials (systemd-creds) Design Prompt
Replace plaintext secrets in environment variables and EnvironmentFile= with TPM-backed or host-bound encrypted credentials delivered to units via systemd-creds and LoadCredentialEncrypted=.
-
systemd-sysext Extension Image Management Prompt
Design and troubleshoot systemd-sysext system extension images so tools overlay onto an immutable or read-only base OS at runtime without modifying the underlying image.
More Linux Admins prompts & error guides
Browse every Linux Admins prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.