LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-13-2024, 07:53 AM   #1
zzzhhh
LQ Newbie
 
Registered: Dec 2023
Posts: 9

Rep: Reputation: 0
Two questions on entering namespace of systemd


I am studying entering namespace of systemd on Ubuntu 22.04.3 LTS desktop. I wrote a script to test entering namespace of systemd. The whole testing are as follows:

1) Run `sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfig` to install needed packages

2) Add the following snippet at the beginning of `/etc/bash.bashrc` to invoke my script to enter namespace of systemd.
Code:
SYSTEMD_EXE="/lib/systemd/systemd --unit=basic.target"
SYSTEMD_PID="$(ps -eo pid=,args= | awk '$2" "$3=="'"$SYSTEMD_EXE"'" {print $1}')"
echo "@@@@@@@@@@@@@ SYSTEMD_PID is $SYSTEMD_PID @@@@@@@@@@@@@@@@@@"
if [ -z "$SYSTEMD_PID" ] || [ "$SYSTEMD_PID" != "1" ]; then
    sudo sh /home/zh/enternamespace
fi
3) The script `enternamespace` is stored in my home directory. My understanding of entering namespace of systemd is that it is divided into two steps. The first step is to launch `systemd` as a daemon with an isolated namespace. The second step is have a login session enter the namespace. So my script to enter the namespace of systemd is:
Code:
echo "11111111111111111111111111111111111111111111111111111111111111"
SYSTEMD_EXE="/lib/systemd/systemd --unit=basic.target"
SYSTEMD_PID="$(ps -eo pid=,args= | awk '$2" "$3=="'"$SYSTEMD_EXE"'" {print $1}')"
if [ -z "$SYSTEMD_PID" ]; then
    /usr/bin/daemonize /usr/bin/unshare --fork --pid --mount-proc bash -c 'mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc; exec '"$SYSTEMD_EXE"
    while [ -z "$SYSTEMD_PID" ]; do
        echo "Sleeping for 1 second to let systemd settle"    
        sleep 1
        SYSTEMD_PID="$(ps -eo pid=,args= | awk '$2" "$3=="'"$SYSTEMD_EXE"'" {print $1}')"
    done
fi
echo "================ SYSTEMD_PID is $SYSTEMD_PID ================="

echo "2222222222222222222222222222222222222222222222222222"
exec /usr/bin/nsenter -t "$SYSTEMD_PID" -a /bin/login -p -f "$SUDO_USER"
4) Reboot. After rebooting to GNOME desktop, open a terminal.

It works sometimes: https://ibb.co/0hPL5td. But there are two problems I don't understand:
  1. There is a `/run/nologin` file. This file is there to prevent ssh login during booting, which is reasonable. When booting is finished, this file should be deleted so that the Ubuntu OS is ready to accept ssh login. It is the case for normal Ubuntu. I don't understand why `/run/nologin` is still present after booting in my test.
  1. If I login in as a normal user, the system would freeze with an error after a while. But if I log in using Ubuntu's rescue root shell, it will never freeze, though file `/run/nologin` is still there.
    This is a screenshot: https://ibb.co/FXWrTGj.

So I was wondering if you can please help me with these two questions. Thank you.

Last edited by zzzhhh; 01-13-2024 at 07:57 AM.
 
Old 01-18-2024, 04:51 AM   #2
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,809

Rep: Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209
I think a /run/nologin should never be there.
When ssh.service (sshd) is started it should work immediately.

/etc/nologin or /run/nologin are created by an administrator if a reboot is scheduled, e.g. the shutdown command does it.

Something is wrong on your system. It looks like a shutdown command runs during startup.
 
1 members found this post helpful.
Old 01-19-2024, 12:34 AM   #3
zzzhhh
LQ Newbie
 
Registered: Dec 2023
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MadeInGermany View Post
I think a /run/nologin should never be there.
When ssh.service (sshd) is started it should work immediately.

/etc/nologin or /run/nologin are created by an administrator if a reboot is scheduled, e.g. the shutdown command does it.

Something is wrong on your system. It looks like a shutdown command runs during startup.
I gave the whole steps to reproduce the problem, why didn't you follow it to see /run/nologin there instead of just "thinking"?

Nothing is wrong on my system. Maybe something is wrong with your mind simulation an actual Linux system.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LibreOffice: entering text in a two-column single line newbiesforever Linux - Software 1 07-28-2018 08:01 PM
LXer: The Story Behind ‘init’ and ‘systemd’: Why ‘init’ Needed to be Replaced with ‘systemd’ in Linu LXer Syndicated Linux News 1 04-07-2017 11:33 PM
LXer: Why pro-systemd and anti-systemd people will never get along LXer Syndicated Linux News 0 05-15-2015 11:44 PM
LXer: Is systemd as bad as boycott systemd is trying to make it? LXer Syndicated Linux News 0 09-03-2014 05:50 PM
Boot Delay 30min: systemd-analyze blame systemd-tmpfiles-setup.service BGHolmes Fedora 0 07-27-2011 09:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration