Autostart X at Login - OpenRC & SystemD

From Manjaro Linux
Jump to: navigation, search
7-Jan-18: Updated OpenRC, added how to set a file
immutable so as to save your /etc/conf.d/agetty.tty1
file from being overwritten during a system update.
Then a 2nd edit on the same day, which shows a much
better way to protect the file, using 
NoUpgrade = etc/conf.d/agetty.tty1

15-Dec-17: Updated the OpenRC section. 
It is now up to date for Artix Linux (at the least).


Auto-Login with either systemd or OpenRC

I've dramatically updated this page, as the info' on how to autostart X at login for those using systemd was badly out of date (it still worked, but thankfully, there are easier ways to do it now). I've removed the systemd information & incorporated a link to the appropriate ArchWiki page.

I've also added a section on how to setup OpenRC to autostart X at login. Both the OpenRC & the systemd method shown on the ArchWiki should work with either WMs or DEs.


How to Auto-Login on an OpenRC system

Note: I tested the following on Artix using the OpenRC init.

To start X automatically:

Make your /etc/conf.d/agetty.tty1 the same as the following:

# Set the baud rate of the terminal line
baud="38400"

# set the terminal type
term_type="linux"

# extra options to pass to agetty for this port
agetty_options="--autologin guest" 

# make agetty quiet
#quiet="no"

Be sure replace guest in the above code, to the user name that you desire to autologin.


Put the following in your ~/.bash_profile :

# Start x on login
if [[ -z $DISPLAY && ! -e /tmp/.X11-unix/X0 ]]; then
   exec startx
fi

Apart from the above, you will just need to use pacman to delete sddm, lightdm or whichever other DM you have installed. After you have done that, the above changes should allow you to boot straight into your WM or DE without any user input (no logging in with user names & passwords).

Note: the above code & information came from the Porteus forum: [1]


If a system update makes you have to startx manually

Thus far, once, I've had an update that overwrote the /etc/conf.d/agetty.tty1 which of course meant that I had to login manually again.

All that was required (in my case) was changing the following line:

agetty_options=""

Back to:

agetty_options="--autologin handy"

So you just have to add --autologin <your.user.name> between the double quotes & your good to go.


Two Methods that will prevent a file being upgraded over

You can stop this from happening in future by using one of the two following methods. I used the first one today, until @thefallenrat pointed me to an ArchWiki page that showed me the 2nd method, which I am now using:


Method 1. Make the agetty.tty1 file immutable

Like this:

$ sudo chattr +i /etc/conf.d/agetty.tty1

If you need to make the file changeable again then do this:

$ sudo chattr -i /etc/conf.d/agetty.tty1

If you want to list the file attributes of a file that is using the second extended file system (which is what the chattr command is using), you use the following command like so:

$ lsattr /etc/conf.d/agetty.tty1

Which will give a result like so:

----i---------e---- /etc/conf.d/agetty.tty1


Method 2. Use the pacman.conf file

(quoted from the Arch Wiki)

To prevent any package from overwriting a certain file,
add the following line to /etc/pacman.conf:

   NoUpgrade = absolute/path/to/file

   Note that the path must not start with a slash. 


So I've uncommented the # NoUpgrade = line in my /etc/pacman.conf & it now looks like this:

NoUpgrade = etc/conf.d/agetty.tty1

So that is a much more Arch way of doing things.


Autostart X at login on a systemd system

Before trying to automatically start .xinitrc file, make sure to have a Proper ~/.xinitrc File.


The most up to date instructions for those systems that use the ever developing systemd can be found here on the ArchWiki: [2]


Other Options that may be very useful

I've not used these methods posted in the forum by Chrysostomus, but I've put a copy of his post here for those that are interested:

Other options for systemd:

- xlogin https://bbs.archlinux.org/viewtopic.php?id=147913&p=3

Other options for systemd and openrc:

-nodm https://wiki.archlinux.org/index.php/Nodm3

Both of these should be faster methods, because they go directly to X without going through Getty. I haven't tested nodm, but at least xlogin is visibly faster. Bspwm edition does not have display manager, so it comes with option to enable auto login with xlogin. I'm considering moving to nodm though, because it hopefully would not depend on systemd.


Support

Following is a link to this page's forum counterpart where you can post any related feedback: [3]