Dear list,

In the past,
if I wanted to clone a baremetal server to another server,
I just copied its root directory (/) and chrooted to it.
Then, I could run services via old sysv init scripts.
(/etc/init.d/service start/stop/status)

It is no longer the case now with debian 12,
(surely even before debian 12)
and I've been advised to look into machineclt and systemd-nspawn.

I have absolutely no experience in running containers,
systemd or otherwise,
and I'm not sure how this all works with nspawn,
but I created a symlink to the location of the cloned server inside of 
/var/lib/machines/
(as /var/lib/machines/clone-messagerie)
so that machinectl can find it,
then started the machine with

  $ machinectl start clone-messagerie


then tried to login to the cloned host via


  $ machinectl login clone-messagerie


I got different results depending on the tries,
not sure what action did I do that changed the results.
So, the first time I had this error:


   # machinectl login clone-messagerie
   Failed to get login PTY: Connection timed out
   #


After a restart of the machine (machinectl stop/start)
I get this:


  # machinectl login clone-messagerie
  Failed to get login PTY: There is no system bus in container clone-messagerie.
  #


machinectl status shows that systemd is running inside of payload,
not as pid 1 though,
and shows systemd-nspawn in the supervisor section.


  # machinectl status clone-messagerie
  clone-messagerie(823952398253425ab703ecef4bdd936e)
             Since: Tue 2025-02-11 13:55:25 CET; 1min 39s ago
            Leader: 171516 (systemd)
           Service: systemd-nspawn; class container
              Root: /mnt/anciennevar/clone-messagerie
             Iface: ve-clone-me-Nbp
                OS: Debian GNU/Linux 8 (jessie)
    UID Shift: 38928384
              Unit: systemd-nspawn@clone-messagerie.service
                    ├─payload
                    │ ├─171516 /lib/systemd/systemd
                    │ ├─171582 /lib/systemd/systemd-journald
                    │ ├─171825 /usr/bin/freshclam -d --foreground=true
                    │ ├─171826 /usr/sbin/atd -f
                    │ ├─171829 /usr/sbin/cron -f
                    │ ├─171892 /usr/sbin/irqbalance 
--pid=/var/run/irqbalance.pid
                    │ ├─171896 /usr/sbin/opendkim -x /etc/opendkim.conf -u 
postfix -P /var/run/opendkim/opendkim.pid
                    │ ├─171907 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 112:119
                    │ ├─172096 /usr/sbin/apache2 -k start
                    │ ├─172136 /usr/sbin/apache2 -k start
                    │ ├─172139 /usr/sbin/apache2 -k start
                    │ ├─172141 /usr/sbin/apache2 -k start
                    │ ├─172142 /usr/sbin/apache2 -k start
                    │ ├─172143 /usr/sbin/apache2 -k start
                    │ ├─172318 /usr/bin/python /usr/bin/fail2ban-server -b -s 
/var/run/fail2ban/fail2ban.sock -p /var/run/fail2ban/fail2ban.pid
                    │ ├─172714 /usr/sbin/rsyslogd -n
                    │ ├─172716 /usr/sbin/acpid
                    │ └─172721 /usr/sbin/sshd -D
                    └─supervisor
                      └─171514 systemd-nspawn --quiet --keep-unit --boot 
--link-journal=try-guest --network-veth -U --settings=override 
--machine=clone-messagerie
Feb 11 13:56:41 messagerie-recup systemd-nspawn[171514]: [ OK ] Started LSB: starts FusionInventory Agent.
  Feb 11 13:56:41 messagerie-recup systemd-nspawn[171514]: [  OK  ] Started 
LSB: Apache2 web server.
  Feb 11 13:56:41 messagerie-recup systemd-nspawn[171514]: [  OK  ] Started 
LSB: Starts and daemonize Glances server.
  Feb 11 13:56:41 messagerie-recup systemd-nspawn[171514]: [  OK  ] Started 
LSB: disk temperature monitoring daemon.
  Feb 11 13:56:41 messagerie-recup systemd-nspawn[171514]: [  OK  ] Started 
LSB: Start NTP daemon.
  Feb 11 13:56:41 messagerie-recup systemd-nspawn[171514]: [  OK  ] Started 
LSB: Starts amavisd-new mailfilter.
  Feb 11 13:56:41 messagerie-recup systemd-nspawn[171514]: [  OK  ] Started 
LSB: Start/stop fail2ban.
  Feb 11 13:56:41 messagerie-recup systemd-nspawn[171514]: [  OK  ] Started 
Permit User Sessions.
  Feb 11 13:56:41 messagerie-recup systemd-nspawn[171514]: [  OK  ] Started 
Initialize hardware monitoring sensors.
  Feb 11 13:56:41 messagerie-recup systemd-nspawn[171514]: [  OK  ] Started 
System Logging Service.
  #


The funny thing is that systemd-nspawn -bM clone-messagerie works just fine.


  # systemd-nspawn -bM clone-messagerie
  Spawning container clone-messagerie on /mnt/anciennevar/clone-messagerie.
  Press ^] three times within 1s to kill container.
  systemd 215 running in system mode. (+PAM +AUDIT +SELINUX +IMA +SYSVINIT 
+LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR)
  Detected virtualization 'systemd-nspawn'.
  Detected architecture 'x86-64'.
Welcome to Debian GNU/Linux 8 (jessie)! Set hostname to <messagerie-prep>.
  Failed to install release agent, ignoring: No such file or directory

...


  [  OK  ] Stopped OpenBSD Secure Shell server.
           Starting OpenBSD Secure Shell server...
  [  OK  ] Started OpenBSD Secure Shell server.
           Stopping OpenBSD Secure Shell server...
  [  OK  ] Stopped OpenBSD Secure Shell server.
           Starting OpenBSD Secure Shell server...
  [FAILED] Failed to start OpenBSD Secure Shell server.
  See 'systemctl status ssh.service' for details.
Debian GNU/Linux 8 messagerie-prep console messagerie-prep login: root
  Password:
  Last login: Sun Feb  9 17:04:50 CET 2025 on pts/0
  Linux messagerie-prep 5.10.0-27-amd64 #1 SMP Debian 5.10.205-2 (2023-12-31) 
x86_64
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  ^                                           ^
  ^    ceci est la machine messagerie-prep    ^
  ^                                           ^
  ^                                           ^
  ^ C'est une machine virtuelle qui se trouve ^
  ^ sur vSphere 1 (10.10.10.41)               ^
  =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  root@messagerie-prep[10.10.10.20][CHROOT] ~ #





So I really don't understand why machinectl fails where systemd-nspawn works.
I thought they were two different tools with the same purpose,
but apparently I am missing something?

Best,



--
yassine -- sysadm
http://about.me/ychaouche
Looking for side gigs.

Reply via email to