Posts: 146
Eperbab
Joined: 10 Dec 2012
#1
I'm trying to automatically start a desktop environment without login, or running any display manager in the background.
My goal is to better understand how things are working.

OK, so .. If I understand correctly:

- /etc/inittab specifies the default runlevel, in our case 5 and runs level S ( links in /etc/rcS.d)
- when entering runlevel 5, /etc/init.d/rc runs links named"SXXscriptname" in /etc/rc5.d
(links pointing to script files in /etc/init.d )
- one of the scripts is handling the display manager (start/stop service)

I'm using lightdm & Mate, but xfce is easier to start, therefore I tried this:
- renamed S21lightdm to K21lightdm in /etc/rc5.d and /etc/rcS.d
- Made a copy of /etc/init.d/lightdm script named nodm in the original directory
- added a link to nodm in /etc/rc5.d
- run 'update-rc.d lightdm defaults' and 'update-rc.d nodm defaults' as root
- edited the nodm script:

Code: Select all

#! /bin/sh
### BEGIN INIT INFO
# Provides:          no dm
# Should-Start:      console-screen kbd acpid dbus hal consolekit
# Required-Start:    $local_fs $remote_fs x11-common
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: No Display Manager
# Description:       Debian init script for No Display Manager
### END INIT INFO
#
# Author:       Eperbab
#               
#

echo"No DM"
set -e

PATH=/sbin:/bin:/usr/sbin:/usr/bin

#/bin/su - enzo -c"sudo -n startxfce4"
#exec sudo -u enzo startxfce4
#exec startxfce4
/bin/su - enzo -c"startxfce4"
exit 0


Now I have the following problems:
- /bin/su - enzo -c"sudo -n startxfce4" will not start xfce, because user 'enzo' needs to be prompted for sudo, -n not supported
- exec sudo -u enzo startxfce4 will not start xfce, because user 'enzo' doesn't have the privilege to start X
- /bin/su - enzo -c"startxfce4" will not start xfce, because user 'enzo' doesn't have the privilege to start X
- exec startxfce4 starts XFCE .. as root. I don't want to surf the web as superuser.

Interestingly, If I log in to console as 'enzo', and run startxfce4 from there without sudo, then it starts propely.
I guess it has something to do with duplicated lightdm start in rcS.d and rc5.d, and I need some orientation at this point.
(help, please.. )

*** Update: Since I am able to manually start xfce/mate from tty1, I decided to modify the nodm script, so it logs in to tty1 as user.

Code: Select all

#! /bin/sh
### BEGIN INIT INFO
# Provides:          no dm
# Should-Start:      console-screen kbd acpid dbus hal consolekit
# Required-Start:    $local_fs $remote_fs x11-common
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: No Display Manager
# Description:       Debian init script for No Display Manager
### END INIT INFO
#
# Author:       Eperbab

echo"No DM"
set -e

PATH=/sbin:/bin:/usr/sbin:/usr/bin
/bin/login -f enzo tty1 </dev/tty1 >/dev/tty1 2>&1

exit 0
As a next step I added this to ~/.bashrc:

Code: Select all

if ["$(tty)" ="/dev/tty1" ] ; then
startx
fi
It works, but.. if I replace"startx" with"exec mate-session" ,then it won't start. Also tried to run"exec startxfce4", and at first it worked, but I accidentally run"exec mate-session" while xfce was running. This time it started!
Now if - after restarting PC - I start xfce, then mate also starts.
And the"switch off" button is greyed out. I can only log out.
Image
Any idea?
Last edited by Eperbab on 03 Aug 2013, 20:32, edited 1 time in total.
Posts: 1,308
BitJam
Joined: 31 Aug 2009
#2
First I suggest starting X as a normal user running xinit:

Code: Select all

xinit [desktop] -- :<display>
where [desktop] is the desktop program you want to run such as xfce and <display> is usually either 0 or 1. It specifies which virtual console to open X on: 0 --> vt7 and 1 --> vt8. You can have xcfc automatically added to your .xinitrc file with the update-default-desktop program. Make sure this works from a virtual console as user enzo.

Next, instead of dealing with /etc/init.d scripts, I would suggest that you"sacrifice" one of the virtual consoles for this task. Let's use tty3. Edit /etc/inittab and change the line that starts with"3:" to:

Code: Select all

3:2345:respawn:/usr/sbin/autologin tty3 login -f enzo
This will automatically open up a bash shell in vc3 (get to it with <ctrl><alt><f3>). Use"sudo telinit q" to get the init process to reread the /etc/inittab file. Log into vc3 and then exit from the shell. If the above line works then every time you exit you should get back to a shell without having to enter your username and password.

Now make a little shell script at /usr/local/bin/my-xinit that starts up X the way you want it:

Code: Select all

#!/bin/sh
/usr/bin/xinit xfce -- :1
Make sure you run"chmod a+x /usr/local/bin/my-xinit". You can test the script by running it from a virtual console.

Now replace the 3: line in inittab with:

Code: Select all

3:2345:respawn:/usr/sbin/autologin tty3  /bin/su -c /usr/local/bin/my-xinit enzo
so it runs the my-xinit script as enzo instead of opening up a login shell. Run"sudo telinit q" again then switch to vt3 and run"exit". If it all works then X will start up when you do this.

I tested this on my Gentoo system. It is possible things are slightly different in antiX but the idea is the same. The format of the inittab line might be a little different and the locations of some programs may be different. This should be easy to debug because you can test the parts separately and you don't have to reboot to try it. You can have your normal X session running in vt7 while you test the new system in vt8.

Once it is all working, edit your menu.lst to boot into runlevel 3 to keep the normal desktop manager from starting. The way it is set up now, X will automatically restart whenever you exit from it. You can change this by adding a few more lines to my-xinit. This may not be the"best" or most secure approach but it is easy and flexible.

I've been wanting to offer an option to replace SLiM with a text based desktop-manager. It would use some of the ideas here. Instead of immediately running xinit, the script would first prompt with a list of desktop programs to run.
Posts: 146
Eperbab
Joined: 10 Dec 2012
#3
During the tests I managed to screw up my default user's home - mate always starts if X starts, regardless choosen desktop. My mistake. But I continued testing with enzo2 user.

So this method works:

Steps 1-4 perform autologin, 5-6 run the requested environment. If you don't need the autologin feature, then skip steps 2-3 and 4B.

Step 1. The display manager should not start.
Options:
1. uninstall the display manager or
2. edit /etc/rc5.d and rcS.d as root. In case of the lightdm display manager I renamed S21lightdm to K21lightdm in /etc/rc5.d and /etc/rcS.d. Do the same with your display manager. Numbers after S may vary.

Step 2. Add my nodm script to /etc/init.d , and make it rwx for root (set the executable bit).
Replace"enzo2" everywhere in the script with the username who should autologin.

Code: Select all

#! /bin/sh
### BEGIN INIT INFO
# Provides:          no dm
# Should-Start:      console-screen kbd acpid dbus hal consolekit
# Required-Start:    $local_fs $remote_fs x11-common
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: No Display Manager
# Description:       Debian init script for No Display Manager
### END INIT INFO
#
# Author:       Eperbab

echo"No DM"
set -e

PATH=/sbin:/bin:/usr/sbin:/usr/bin
/bin/login -f enzo2 tty1 </dev/tty1 >/dev/tty1 2>&1
#/usr/sbin/autologin tty1  /bin/su -c /home/enzo2/.zsession enzo2

exit 0
Remark: the commented '/usr/sbin/autologin..' line also works. Feel free to comment '/bin/login/..' and uncomment '/usr/sbin/autologin..'.

Step 3. Add a link of nodm script to /etc/rc5.d . Use the numbers of your display manager, or any free two digit number. In my case it was S21nodm.

Step 4. Update init config:
A, if you have chosen option 2 in step 1: Run 'update-rc.d lightdm defaults' as root. Replace"lightdm" with your dm.
B, Run 'update-rc.d nodm defaults' as root. So nodm script will run propely.

Step 5. Edit ~/.profile for the user who will autologin. Add this to the end of the file:

Code: Select all

if ["$(tty)" ="/dev/tty1" ] ; then
exec ~/.zsession
fi
So if the user logs in to tty1, then the (not yet created) script ~/.zsession will run. If anything goes wrong with the script, the user will be logged off automatically at tty1. Troubleshooting: In this case hit Ctrl+alt+F2 and log into tty2. The .zsession script will not run there. Run 'startx', 'xinit' or things like 'xinit rox-fluxbox -- :0' etc.

Step 6. Create the script ~/zsession for the user who will autologin. Make it executable. It will start xinit. Replace"mate" with your prefferred choice. Valid choices are listed in ~/.xinitrc. e.g." Rox-fluxbox|rox-fluxbox)" means you can select rox-fluxbox. (with OR without capital R)

Code: Select all

#!/bin/sh
/usr/bin/xinit mate -- :0
Special thanks to BitJam. Without his post I would not post it here.

Remarks: ~/.zsession could be the place to create a text base login manager script. In this case"mate" can be replaced by a parameter defined by the script. The nodm script may wait x seconds for a valid username, and login that user. Since every user can have his/her own ~/.zsession script, this solution would be a fully functional multiuser friendly login manager solution.

Remaining problems: shutdown button doesn't work (greyed out or not avalaible) in big desktop environments like mate or xfce.
AntiX shutdown script should be added to the GUI manually.

Screenshots:
/bin/login way:
Image
/usr/sbin/autologin way:
Image
Last edited by Eperbab on 05 Aug 2013, 15:50, edited 2 times in total.
Posts: 1,308
BitJam
Joined: 31 Aug 2009
#4
I'm glad you got it to work. Here are a couple of thoughts:
Eperbab wrote:Step 1. The display manager should not start.
Options:
1. uninstall the display manager or
2. edit /etc/rc5.d and rcS.d as root.
A third option is to boot into runlevel 3 by adding the boot parameter"3". If you send xinit":1" instead of":0" then there will be no conflict if you omit the"3"; both X servers will run on different vt's.

IMO, the Debian init.d scripts system is a big pain and quite brain-dead. YMMVG. That's why it seemed so much simpler to just modify one of the inittab entries. Also, I am concerned about a possible fight between the init process and your script over control of tty1 but maybe it's not an issue. ISTM that if you want to run something specific in a virtual console than the standard procedure is to modify inittab.

BTW: My first idea was similar to what you did. I used autologin in inittab to autologin to tty3 and then in .bashrc if I detected we were in tty3 then I would run xinit. IoW, with your modified .profile, you should be able to get by with just an autologin on the tty that you want to use. I suggest using something other than tty1 so you don't lose the boot messages. ISTM the approach of detecting the tty in a startup scripts like .bashrc or .profile was more fragile and complicated than the method I eventually suggested.

The important thing is that you got it working to your satisfaction. Congrats.
Posts: 146
Eperbab
Joined: 10 Dec 2012
#5
Thanks. The other motivation to not use a DM was that I have an outdated, not supported hardware (Radeon 9200 SE + non-standards compliant TV-monitor), and according to my experiments I have two options to run lightdm/kdm/gdm/etc:
A, If I set"options radeon modeset=0" in /etc/modeprobe.d/radeon-kms.conf, then lightdm runs propely, X starts, but tty1-6 doesn't show up. I have to kill X with with ctrl+alt+backspace to see the terminals.
B, After modeset=1 lightdm starts but won't show up, and X crashes, but tty1-6 is visible.

Now the nodm script logs me in to tty1 and ~/.profile loads the environment, so X starts propely and tty1-6 are also visible.
And now that I can switch again between terminal and X (like in the good old days with Ubuntu 6.05), I can start again several X paralel.
Just for fun:
Image

The only remaining task is to make a shutdown script and a shutdown button on the upper panel. The default shutdown button doesn't work without a DM. (xfce/mate/..)
Posts: 1,308
BitJam
Joined: 31 Aug 2009
#6
Eperbab wrote:The only remaining task is to make a shutdown script and a shutdown button on the upper panel. The default shutdown button doesn't work without a DM. (xfce/mate/..)
Have you tried the /usr/local/bin/exitantix.sh script?

If you don't want all the options it gives you, it should be easy to pare it down. On non-live systems it executes:

"sudo halt" and"sudo reboot"

to shutdown and reboot the system.
Posts: 146
Eperbab
Joined: 10 Dec 2012
#7
Yes, I have found it before reading your reply.
I have remembered that there is an antix script, so started a fluxbox session, and did a 'ps -eF >~/procX.txt' with and without the antix exit script running. Checked the lists with diffuse, and found the difference:

Code: Select all

enzo      3710  3426  0  1686  1300   0 19:49 ?        00:00:00 /bin/bash /usr/local/bin/exitantix.sh
enzo      3727  3710  1  7794  9412   0 19:49 ?        00:00:00 gtkdialog --program LOGOUT
Tested the first one in virtual terminal, than created a .desktop file with the command '/bin/bash /usr/local/bin/exitantix.sh' and moved it to /home/common/exit_antix folder. Made it executable to the users group. Then I moved it with mouse to the upper panel, so a link was created there.
It looks like this now:
Image
Posts: 146
Eperbab
Joined: 10 Dec 2012
#8
Just realised that automount usb devices also doesn't work without a display manager. Followed the 99-usbstorage.rules trick from here:
========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"antix.freeforu ms.org/mounting-usb-devices-in-rox-t3048.html"
linktext was:"link"
====================================