1. create an autologin getty:
cp /lib/systemd/system/getty@.service /etc/systemd/system/getty1@tty1.service
2. change the "ExecStart" line of /etc/systemd/system/getty1@tty1.service to look like this:
ExecStart=-/sbin/agetty --autologin <username> --noclear %I 38400 linux
3. create a custom getty /etc/systemd/system/getty0@tty1.service:
#This file provides a choice between manual and automatic login
[Unit]
Description=Getty on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html
After=systemd-user-sessions.service plymouth-quit-wait.service
Before=getty.target
Before=getty1@tty1.service
IgnoreOnIsolate=yes
ConditionPathExists=/dev/tty0
[Service]
# An ExecStart command is syntactically required (Why???)
ExecStart=-/usr/bin/true
ExecStop=-/sbin/agetty -p --noclear --timeout 5 %I 38400 linux
Type=oneshot
Restart=no
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
KillMode=process
IgnoreSIGPIPE=no
Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=
KillSignal=SIGHUP
[Install]
Alias=getty.target.wants/getty@tty1.service
4. Enable:
ln -sf /etc/systemd/system/getty1@tty1.service /etc/systemd/system/getty.target.wants/getty1@tty1.service
ln -sf /etc/systemd/system/getty0@tty1.service /etc/systemd/system/getty.target.wants/getty0@tty1.service
systemctl daemon-reload
reboot
Edit: It seems to be possible after all to use "Type=idle" for both services:
1. /etc/systemd/system/getty0@tty1.service:
#This file provides a choice between manual and automatic login
[Unit]
Description=Getty-manual on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html
After=systemd-user-sessions.service plymouth-quit-wait.service
Before=getty.target
IgnoreOnIsolate=yes
ConditionPathExists=/dev/tty0
#This ensures that getty0@tty1.service gets started first (and exclusively):
Conflicts=getty1@tty1.service
[Service]
ExecStart=-/sbin/agetty -p --noclear --timeout 5 %I 38400 linux
ExecStopPost=-/usr/bin/systemctl start getty1@tty1
Type=idle
Restart=no
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
KillMode=process
IgnoreSIGPIPE=no
Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=
KillSignal=SIGHUP
[Install]
Alias=getty.target.wants/getty@tty1.service
2. /etc/systemd/system/getty1@tty1.service:
#This file provides an automatic login
[Unit]
Description=Getty-autologin on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html
After=systemd-user-sessions.service plymouth-quit-wait.service
Before=getty.target
IgnoreOnIsolate=yes
ConditionPathExists=/dev/tty0
[Service]
ExecStart=-/sbin/agetty --autologin <username> --noclear %I 38400 linux
ExecStop=-/usr/bin/systemctl start getty@tty1
Type=idle
Restart=no
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
KillMode=process
IgnoreSIGPIPE=no
Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=
KillSignal=SIGHUP
[Install]
Alias=getty.target.wants/getty@tty1.service
Note that the autologin getty is not restarted; instead it starts a standard getty when it exits.
And no more "Before=" or "After=" except the defaults. The "Conflicts=" condition is sufficient.
I haven't found a solution yet that doesn't rely on agetty's built-in timeout function. A timer file like the following will start the autologin getty regardless of whether you try to log in manually or not:
# /etc/systemd/system/getty1@tty1.timer
[Unit]
Description=Timer for Getty-autologin on %I
[Timer]
OnActiveSec=5
Unit=getty1@tty1.service
[Install]
WantedBy=getty.target
Feel free to experiment.
]]>1. Add "quiet" to GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub to avoid obscuring the login prompt with boot messages, otherwise this will not work.
2. create a file /etc/systemd/system/getty0@tty1.service (replace <username> with the actual user. This file is copied and modified from /usr/lib/systemd/system/getty@.service; I omitted the original comments for brevity's sake):
#This file provides a choice between manual and automatic login
[Unit]
Description=Getty on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html
After=systemd-user-sessions.service plymouth-quit-wait.service
Before=getty.target
Before=getty@tty1.service #Otherwise you won't get the login prompt back after logout
IgnoreOnIsolate=yes
ConditionPathExists=/dev/tty0
[Service]
ExecStart=-/sbin/agetty -p --noclear --timeout 5 %I 38400 linux
ExecStartPost=-/sbin/agetty --autologin <username> --noclear %I 38400 linux
Type=oneshot
Restart=no
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
KillMode=process
IgnoreSIGPIPE=no
Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=
KillSignal=SIGHUP
[Install]
Alias=getty.target.wants/getty@tty1.service
3. To enable it do the following (as root):
ln -sf /etc/systemd/system/getty0@tty1.service /etc/systemd/system/getty.target.wants/getty0@tty1.service
ln -sf /usr/lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
systemctl start getty@tty1.service
After logging out of the manual login, autologin kicks in automatically (but only once).
Disclaimer: This modifies the actual login. Do it only if you can get back in on failure (e.g. chroot from a rescue system)
]]>EDIT: sorry, your comment below is correct.
]]>This is a possible procedure for enabling autologin in archlinux without using a display manager. The procedure described in the "Automatic login to virtual console" ArchWiki has the serious bug that the user gets logged back in automatically at logout, which makes it impossible to log in as another user at the console. A possible (partial) solution is the following:
1. Create a new getty:
cp /usr/lib/systemd/system/getty@.service /etc/systemd/system/getty1@.service #I suppose you can call it whatever you want
2. Modify the following lines in the [Service] section to look like this:
ExecStart=-/sbin/agetty --autologin <username> --noclear %I 38400 linux
Type=oneshot
Restart=no
The [Install] section remains the same:
Alias=getty.target.wants/getty@tty1.service
3. Enable the new service:
ln -sf /etc/systemd/system/getty1@.service /etc/systemd/system/getty.target.wants/getty@tty9.service
systemctl start getty@tty9.service
reboot
This will log the specified user into tty9, and as the service is not restarted, the original getty will be available at logout. I call this solution partial because automatic login cannot be stopped by entering something at the original getty; you have to wait until the login is complete and log out before being able to log in as another user. Also, there is a slight delay before the login prompt reappears.
Does anybody know how to stop this getty@tty9.service by entering keystrokes before it loads? That is, to enable a timeout for manual login? (I mean, short of installing a display manager. I couldn't find anything meaningful in man agetty and man login)
]]>