Linux systemd nspawn Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
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
- Understanding systemd-nspawn
- systemd-nspawn Installation
- Creating Containers
- Running Containers
- 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 [email protected]
Summary
This guide covered systemd-nspawn usage, container creation, and lightweight virtualization for Arch Linux, CachyOS, and other distributions.
Next Steps
- machinectl Guide - Container management
- Virtualization - Virtualization guide
- Docker Guide - Docker containers
- systemd-nspawn Documentation:
man systemd-nspawn
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.