Skip to content

Linux systemd nspawn Guide

Mattscreative edited this page Dec 5, 2025 · 2 revisions

Linux systemd-nspawn Guide

Complete beginner-friendly guide to systemd-nspawn on Linux, covering Arch Linux, CachyOS, and other distributions including container creation, lightweight virtualization, and systemd containers.


Table of Contents

  1. Understanding systemd-nspawn
  2. systemd-nspawn Installation
  3. Creating Containers
  4. Running Containers
  5. Troubleshooting

Understanding systemd-nspawn

What is systemd-nspawn?

systemd-nspawn creates lightweight containers.

Features:

  • Lightweight: Minimal overhead
  • systemd integration: Uses systemd
  • Container creation: Create containers
  • Isolation: Process isolation

Why it matters:

  • Lightweight virtualization: Lightweight containers
  • systemd integration: Integrated with systemd
  • Development: Useful for development

systemd-nspawn Installation

Install systemd

Arch/CachyOS:

# systemd-nspawn is part of systemd
# Usually pre-installed

# Verify
systemd-nspawn --version

Creating Containers

Create Container

Basic usage:

# Create container directory
sudo mkdir -p /var/lib/machines/container

# Install system in container
sudo pacstrap /var/lib/machines/container base

Boot Container

Start container:

# Boot container
sudo systemd-nspawn -D /var/lib/machines/container

# Starts container

Running Containers

With Network

Network access:

# With network
sudo systemd-nspawn -D /var/lib/machines/container --network-bridge=br0

# --network-bridge = bridge network

With Bind Mounts

Mount directories:

# With bind mount
sudo systemd-nspawn -D /var/lib/machines/container --bind=/path/to/dir

# Mounts directory in container

Troubleshooting

Container Not Starting

Check permissions:

# Verify directory
ls -la /var/lib/machines/container

# Check systemd
systemctl status systemd-nspawn@container.service

Summary

This guide covered systemd-nspawn usage, container creation, and lightweight virtualization for Arch Linux, CachyOS, and other distributions.


Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally