How to start a simple systemd-nspawn container (for system rescue)


the limitation first: wifi connection doesn’t andwork this means you can’t download packages in the systemd-nspawn container. if lan connection to the internet works i don’t know .

systemd-nspawn can be used for namespace container for debugging, testing, building and for system rescue as chroot replacement.

i want to describe how to use systemd-nspawn for maintain a “dead” system:

  1. boot a live system, open a konsole and use root privileges
  2. mount every relevant partition
#in my example im using partitions for /home /boot and / on /dev/sda and / is on /sda2
mount /dev/sda2 /mnt
mount /dev/sda1 /mnt/boot
mount /dev/sda2 /mnt/home
  1. start the container
systemd-nspawn -D /mnt

and you can boot the “dead” system if you want

systemd-nspawn -D /mnt -b
  1. do the maintain
#pacman -Syuu
#or what else
  1. shut down the container

but if you had booted the kernel



“update-grub” will fail in a systemd-nspawn container if you want to rewrite grub configuration and also the “grub-install” command.

you doesn’t need a chroot environment for “grub-install” but for “update-grub” you need a traditional chroot

<mount your filesystem>
sudo mount --bind /dev /mnt/dev
sudo mount --bind /sys /mnt/sys
sudo mount --bind /proc /mnt/proc
sudo mount --bind /run /mnt/run 
#and for connection to the internet
sudo mount -o bind /etc/resolv.conf /mnt/etc/resolv.conf
sudo chroot /mnt /bin/bash

or use:

arch-chroot <your mounted filesystem>

1 Like

if “arch-install-scripts” are installed

sudo pacman -S arch-install-scripts

if “arch-install-scripts” are not installed

sudo pacman -S arch-install-scripts