NimbUx
Posts: 30
Joined: Fri Jan 03, 2020 10:33 am

terminate "X", go to console runlevel 3 (or 1)

Thu Jan 16, 2020 8:18 pm

From the Rasbian desktop, what's the simplest/approved way to exit the GUI, terminate "X" properly and be transported to a Linux console? I have faint old memories of typing Control-Alt-Backspace to exit X11, which for some reason does not work on this new thing. Also,

Code: Select all

sudo init 3
is not accepted, I guess everything's been polluted by "systemd" nowadays :=(

Matter of fact, I did find an - apparently - operational way, viz :

Code: Select all

sudo systemctl isolate runlevel3.target
Is that uh, thing, above, the recommended command ? Why is there not a menu item in the graphical shudown applet to help dummies terminate the GUI properly, exiting to a console ?

GlowInTheDark
Posts: 184
Joined: Sat Nov 09, 2019 12:14 pm

Re: terminate "X", go to console runlevel 3 (or 1)

Thu Jan 16, 2020 8:24 pm

First and most obvious question is, as always: Why do you want to do this? That, as always, determines what sort of answer you're hoping for.

Second, systemd's got nothing to do with it. (And I'm no fan of systemd)

Third, you can do: Ctrl/Alt/F2 to get to a console, but, as I'm sure you're aware, X will still be running - and you can get back to it with Ctrl/Alt/F7

Note: As far as I know, Raspbian (even in Buster) still uses tty7 for the X GUI. Some of the more hyper-modern Linux distros now run the X GUI on tty1 instead. Arch for Arm (available for the RPi) is one such distro.

Fourth, Ctrl/Alt/Backspace can be re-enabled via a setting in raspi-config (unless they've taken it out recently, been a while since I checked). But note that the desktop would just auto-start itself, so it's not of much use.

Fifth, you might want to go into raspi-config and tell it to boot to command line instead of booting to desktop. That may be the overall solution to your issue (whatever it may be).

NimbUx
Posts: 30
Joined: Fri Jan 03, 2020 10:33 am

Re: terminate "X", go to console runlevel 3 (or 1)

Thu Jan 16, 2020 10:11 pm

GlowInTheDark wrote:
Thu Jan 16, 2020 8:24 pm
First and most obvious question is, as always: Why do you want to do this? That, as always, determines what sort of answer you're hoping for.
(snipped)

Well, let me disagree here. I was hoping for a precise question to a precise answer. The "why" has little to do with an expected answer. There could be multiple reasons, one might want to terminate X, work at a console for a while, then maybe startx once more. Out of your five points, only point 4, reenabling ctrl-alt-bsp, came near to an answer albeit almost useless as you don't tell how that's done. Please do not try to extrapolate through mind-reading : second guessing and telepathy do
not work :=)

To reiterate : how best to terminate a session of X11 cleanly ? Is ctrl-alt-backspace (if somehow magically enabled) safe ? What about the "systemctl" command I found and proposed in the O.P ? Is that one safe also, as in properly terminating X and cleaning dependent processes ?

NimbUx
Posts: 30
Joined: Fri Jan 03, 2020 10:33 am

Re: terminate "X", go to console runlevel 3 (or 1)

Fri Jan 17, 2020 10:22 am

I've searched and 'trialled' quite a few ways, I'm reporting here - for lack of a better authoritative answer -
what I've found to be the softest sweetest nicest route. Let's restate the posed question :
Assume : user ("pi") is initially logged in and using the GUI.
Assume: this is the one and only open X-session (local or remote). I did not investigate multiple users/X-sessions/ssh etc...

Goal : terminate the X-session, logout the user, stop X-server all cleanly and orderly.

Proposed Method :
1. go to virtual terminal (already logged in as 'pi') : Ctrl Alt F1
2.Type :

Code: Select all

$ sudo systemctl stop lightdm 
This command will terminate the GUI session orderly (i.e. no need for user to have closed apps and saved files manually in my testing; but be cautious, I'm offering no guarantee nor warranty !), and stop X altogether.
System still is in runlevel 5 (aka "target" in systemd parlance...) So I suggest typing now :
3.

Code: Select all

$ sudo runlevel 3
Done ! If you later want to go back to the point from which you started (restart X and a new interactive session), simplest way, you'd type :
4.

Code: Select all

$ sudo init 5
Works for me. Comments, additions, corrections... warnings if any, wanted and accepted !
Last edited by NimbUx on Fri Jan 17, 2020 12:17 pm, edited 1 time in total.

User avatar
PeterO
Posts: 5315
Joined: Sun Jul 22, 2012 4:14 pm

Re: terminate "X", go to console runlevel 3 (or 1)

Fri Jan 17, 2020 10:38 am

Goal : terminate the X-session, logout the user, stop X-server all cleanly and orderly.
You've moved the goal posts ! No mention of logging out before!

It would be much simpler to login to the CLI first. Then start X with "startx". Then just use the "Shutdown" menu (which will have an "Exit to command line" option) to stop X and press Crtl-D at the command prompt to logout !

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

NimbUx
Posts: 30
Joined: Fri Jan 03, 2020 10:33 am

Re: terminate "X", go to console runlevel 3 (or 1)

Fri Jan 17, 2020 12:15 pm

PeterO wrote:
Fri Jan 17, 2020 10:38 am
You've moved the goal posts !
I don't think so, Peter...
No mention of logging out before!
Wasnt'it at least implicit if not evident ? Cf. first post up in thread asking for 'approved' ways to 'exit the GUI, terminate "X" properly and be transported to a Linux console'? For me, "exit the GUI' properly does contain an (implicit or explicit) logout !
It would be much simpler to login to the CLI first. Then start X with "startx". Then just use the "Shutdown" menu (which will have an "Exit to command line" option) to stop X and press Crtl-D at the command prompt to logout !
That procedure does not solve the problem as posed in the O.P. as you'd have to change the permanent type of start up option first. Saying it"s "simpler" therefore appears irrelevant. What we might ask for is to have a similar "Exit to command line" button added to the shutdown menu also in the case of automaticly booted GUI which would accomplish what I have described in my tentative self-reply.

BTW, PeterO, I don't know if the command I gave (to stop the X-server) would play nicely IF given from an X-terminal. in the previous post detailing my so-called solution, I have played safe by doing it from a virtual console. Do you happen to know whether it would work properly from an X-term ?

User avatar
PeterO
Posts: 5315
Joined: Sun Jul 22, 2012 4:14 pm

Re: terminate "X", go to console runlevel 3 (or 1)

Fri Jan 17, 2020 12:27 pm

Whatever.......
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

GlowInTheDark
Posts: 184
Joined: Sat Nov 09, 2019 12:14 pm

Re: terminate "X", go to console runlevel 3 (or 1)

Fri Jan 17, 2020 12:31 pm

PeterO wrote:
Fri Jan 17, 2020 12:27 pm
Whatever.......
Yes, my reaction as well.

Something that PeterO and I can agree on. A rarity.

It would be nice to know what problem OP is actually trying to solve.

NimbUx
Posts: 30
Joined: Fri Jan 03, 2020 10:33 am

Re: terminate "X", go to console runlevel 3 (or 1)

Fri Jan 17, 2020 12:45 pm

GlowInTheDark wrote:
Fri Jan 17, 2020 12:31 pm
[It would be nice to know what problem OP is actually trying to solve.
Problem entirely contained in the first 1 and a half lines of post #1.
Problem solved - to the satisfaction of the O.P at least- and
a solution has been provided in post #4, above - for others' aedification, and/or comments.

What is your problem, GTD ? Please erase your pointless addition to this thread
and I'll be sure to erase this even more pointless one. "Whatever"....
:=)

NimbUx
Posts: 30
Joined: Fri Jan 03, 2020 10:33 am

Re: terminate "X", go to console runlevel 3 (or 1)

Fri Jan 17, 2020 2:27 pm

Now to add something useful again (imho) to the thread, in my certainly incomplete testing it looks like, yes! the command :

Code: Select all

sudo systemctl stop lightdm 
can also be given in a "terminal" on the X-desktop and shuts down properly the applications, logs out the user, and terminates "X" altogether. Not needing step 1 of the above solution.

If confirmed and sanctionned by a Gnu-Linux-X11 guru, this means the process can be easily scripted and converted to a GUI-user friendly "point and click" shortcut, not needing memorisation effort of arcane system control commands :=)

Oh ! And as to the "why" might we want to shutdown "X" completely rather than leaving it full up while working at a virtual console, as if it was not very evident - there are several good reasons, some maintenance operations simply require X not be running ; that set aside, why leave X to run, sucking a load of resources in power, memory, CPU, and GPU once we have no more need for its service ! Not the least, "X" has been known for being one of the most insecure component of the GNU-Linux software system, why leave it to run when not in use, especially on systems which are often permanently connected, to one or more LANs and WANs ?

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12513
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: terminate "X", go to console runlevel 3 (or 1)

Fri Jan 17, 2020 5:34 pm

It seems the attitude in this thread is really bad, and no I'm not starting to point to anyone, if you feel spoken to.... :evil:

It seems you are all interacting badly. all of you please behave.

Return to “Beginners”