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


(tom) #1


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


After change of graphic output, Im not able to boot
Latest status of the testing repository [01 Dec 2017 - 07 Jan 2018]
KDE packages not updating
(tom) #2


“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

Slow startup and freezing graphics during program's start
(Luca Giambonini) #3

or use:

arch-chroot <your mounted filesystem>

(tom) #4

if “arch-install-scripts” are installed

sudo pacman -S arch-install-scripts

(tom) #5

if “arch-install-scripts” are not installed

(tom) #7
sudo pacman -S arch-install-scripts