1

I have a 15.10 64bit machine with multiple user accounts.
Normally, I select Ubuntu in GRUB, it boots and shows me the login screen, I select an account, enter the password and start my applications.

This is ok and should stay that way, but I would love to have another option in the GRUB menu:

If I select that one, it should boot the same Ubuntu installation, but automatically log into one specific user account (which password-protected) and start a script, which may not be launched if I log in normally.
As the auto-login bypasses the account password, I would also love to password protect this GRUB boot option, so that I have to enter my password (or a different one) into GRUB before it boots this single options.

Is it possible to set something like this up? How would I have to do it?

  • 1
    Dammit. Why are all your questions such that I can think of a way, but I'm too lazy to actually work out the way? See askubuntu.com/a/344359/158442 for GRUB entry, then use kernel parameters systemd.mask to disable LightDM, systemd.wants to enable a custom LightDM service that autologins to your target service and help.ubuntu.com/community/Grub2/… on setting a password to GRUB. – muru Nov 26 '15 at 12:16
  • @muru Unfortunately I have never done anything similar like this yet and have no idea how to make such a custom lightdm... I think I could figure out the rest maybe, but not sure. Would a bounty increase your motivation? :D – Byte Commander Nov 26 '15 at 13:23
  • 1
    No, the problem lies in that I lost all of VMs when I accidentally nuked my OS some time ago. And I haven't bothered to set them up again, since. Maybe I will make the VMs over the weekend and answer this and the iptables one. – muru Nov 26 '15 at 13:25
  • Cool, that would be great. Note that the iptables/apparmor question has a +50 bounty ending in 4 days. – Byte Commander Nov 26 '15 at 13:27
2

Work in progress

This can be accomplished by using:

  1. a custom X session which starts a basic window manager and runs the script
  2. a custom configuration for LightDM which will autologin your user and use the above session
  3. a custom service for LightDM which will use the above configuration
  4. appropriate kernel parameters to disable the normal LightDM service and start the custom one
  5. GRUB configuration to automatically create entries with the above parameters, with password protection

For this example, I will show how to setup a kiosk mode using Google Chrome.

The script

#! /bin/sh
metacity &
while true
do 
    google-chrome --start-maximized
    if zenity --question --text='Do you want to logout?' --title='Logout'
    then
        exit
    fi
done

Keep it at, say /usr/local/bin/chrome-kiosk.sh, make it executable. Note that I use metacity for a simple window manager that provides me with a workable setup without further configuration.

The X session

[Desktop Entry]
Name=Chrome
Comment=This session logs runs a Google Chrome kiosk
Exec=/usr/local/bin/chrome-kiosk.sh
Icon=google-chrome
Type=Application
X-LightDM-DesktopName=Chrome

Save it at /usr/share/xsessions/chrome.desktop. If you use a different script, change at least the Exec line accordingly.

The LightDM configuration

[Seat:*]
autologin-guest=false
autologin-user=username
autologin-user-timeout=0
autologin-session=chrome

Save it as /etc/lightdm/autologin-lightdm.conf. Replace username with your desired user name.

The LightDM service

systemctl cat lightdm.service | 
  sed '/ExecStart/s/$/ --config=/etc/lightdm/autologin-lightdm.conf' |
  sudo tee /etc/systemd/system/autologin-lightdm.service

This creates a custom copy of the default lightdm.service named autologin-lightdm.service at /etc/systemd/system, with the ExecStart line changed to:

ExecStart=/usr/sbin/lightdm --config /etc/lightdm/autologin-lightdm.conf

The kernel paramaters

To test this out, at the GRUB menu, press e to edit the Ubuntu entry. Find the linux line, and append:

systemd.mask=display-manager.service systemd.wants=autologin-lightdm.service

(You can omit the .service extensions.)

Press CtrlX. You should be logged into the user and have a maximized Google Chrome window.

GRUB configuration

TBD.

  • Nice, you finally did it! Were you waiting for the post to get old enough to award you a necromancer badge? ;-) Just kidding, it's fine. – Byte Commander Feb 1 '16 at 18:39
  • But I don't really understand what you want with the kiosk mode etc. I guess my intentions were unclear, I am a very impatient person and always press the power button and walk away until my system has booted (that takes a while). Then I come back, log in, start my applications and walk away again (because it takes another while...). I thought I could save that time and decide already in GRUB that it should log into my user and start my applications. That way, I would not have to return to login and the system would be ready as soon as I come back. – Byte Commander Feb 1 '16 at 18:40
  • @ByteCommander what the script does is up to you. This was my example script, write your own. – muru Feb 2 '16 at 0:04
  • Very interesting. I used this as a guide to set up something similar (two GRUB entries to autologin two different users) with OpenSuSE 13.2 (I know, offtopic for askubuntu.com but I couldn't find this info anywhere else). It all worked fine except that systemd.mask=display-manager.service didn't prevent it from starting (no idea why). So instead I modified display-manager.service to start my own script, which itself greps /proc/cmdline for systemd.wants=foo.service and starts lightdm with the right config. Made me wonder if I could just set my own key=val in the kernel commandline instead :) – David Faure Aug 4 '16 at 9:13
  • Cool coding and my first +1 for WIP Answer :D – WinEunuuchs2Unix Jan 30 '17 at 13:21

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.