1

After a preseed installation of ubuntu (or any linux dist) I want to display a message/warning for the user that some installation or configuration is happening during the first boot. Unfortunately anything related to x11 isn't going to work due to security restrictions (root cannot display for a user).

I decided to use dialog for this reason with a self-destroying service (best method I found so far).

The service is trying to execute the following script (replaced with a sleep because it's not relevant). I am trying to change to tty2 to display the dialog, doing some driver installation (which can't be compiled during the preseed), adding printers, etc pp.

Using a VM in virtual box this is working perfectly fine. Unfortunately, using machines, this doesn't work. It changes to tty2 but all I get is a black screen (in this case for the duration of the sleep) before it switches to the login manager.

This works using XDM/SDDM in the Before-Statement but not with GDM3 and it needs to work with the latter.

I tried adding display-manager in the Before-Statement and several services listed in display-manager.service but wasn't successful. It may be due to the nature of the gdm3-binary itself.

Question: How can I delay the gdm/display-manager.service upstart until my service finishes? Or are there better methods to display a warning until my script is done?

The service

[Unit]
Description=FirstBoot
Wants=network-online.target
After=getty@tty2.service plymouth-quit.service network.target network-online.target
Before=gdm3.service
Requires=cups.service

[Service]
Type=oneshot
ExecStart=/bin/bash /home/admin00/firstboot.sh
ExecStop=/bin/systemctl disable firstboot.service
ExecStopPost=/bin/sh -c 'rm /etc/systemd/system/firstboot.service'
StandardInput=tty
TTYPath=/dev/tty2
TTYReset=yes
TTYVHangup=yes

[Install]
WantedBy=multi-user.target

The script

#!/bin/bash
ABSOLUTE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"

if ! chvt 2 &>/dev/null; then
    break
fi

(
sleep 30s
) | dialog --title "IT Afterconfiguration" --infobox "\n           P L E A S E\n             W A I T\n\n  Your system is being configured" 8 40

dialog --no-cancel --no-ok --pause '   Continuing in ...' 6 27 5 --

rm -rf $ABSOLUTE_PATH
Sefer
  • 21

2 Answers2

0

You could set Type=oneshot in your service and set RemainAfterExit=yes.

Type=oneshot makes sure that the "I am ready"-signal is only sent after the service finished (and not only started) and that should make gdm3 wait due to the Before=-statement in your service. You need the RemainAfterExit-statement so that the service is set to active after it ran (and not just dead).

See Type=-descriptions in detail here

Side note: The default Type, if unset, is simple, i.e. so the next process/service will be let off the leash once your process started.

FelixJN
  • 13,566
  • My service is already òneshot as you can see above. But I will try it with RemainAfterExit tomorrow and give feedback! Thanks for the reply. – Sefer Aug 04 '19 at 23:04
  • Unfortunately this didn't change it. Still getting a black screen until it finished before going to the login manager. – Sefer Aug 05 '19 at 09:06
  • @Sefer I missed the oneshot, sorry. But I don't understand you fully. The question explicitly asks for delaying it? – FelixJN Aug 06 '19 at 10:05
  • It is about delaying it or finding a proper way to display a dialog/application before the login/desktop-manager comes up. This is problematic with gdm/lightdm/lxdm since (using my approach above) I will get a black screen until the script is done, after that you see a part of the dialog, some systemd executions and it switches to the login managers tty. As I said it works without any problem with sddm/xdm but I tried it for testing purposes. My "solution" is adding a short sleep after gdm is started and manually change back to tty1 when the script is done (see my answer) – Sefer Aug 06 '19 at 13:41
  • @Sefer Sorry for the late answer. OK, I get you. I think one of the problems might be that your WantedBy= should rather be graphical.target instead of multiuser.target. That way the system is up except for the graphical desktop. See target units here - not tested, though. You could display a non-GUI message there. – FelixJN Sep 06 '19 at 10:31
0

I decided to try it with After=gdm.service and this seems to be working. There are probably some things being started / modified on boot using gdm which I weren't able to figure out. Therefore I went with the After-Statement.

For this to work properly I had to add another chvt at the end of the script to get back to tty1 for the login manager.

Maybe it's useful to add a little sleep ExecStartPre. Testing this with a virtual machine in parallels, it is too fast and would skip back to the login manager immediately otherwise. I guess it depends on the machine used.

Service

# Using gdm/lightdm/lxdm, the dialog script needs to be started After=gdm.service, else you receive a blank screen
# With sddm/xdm you can start the dialog script i.e. Before=sddm.service

[Unit]
Description=FirstBoot
Wants=network-online.target cups.service
After=getty@tty2.service plymouth-quit.service network.target network-online.target cups.service gdm.service

[Service]
Type=oneshot
ExecStart=/bin/bash /home/admin00/firstboot.sh
ExecStop=/bin/systemctl disable firstboot.service
ExecStopPost=/bin/sh -c 'rm /etc/systemd/system/firstboot.service'
StandardInput=tty
TTYPath=/dev/tty2
TTYReset=yes
TTYVHangup=yes

[Install]
WantedBy=multi-user.target

Script

#!/bin/bash
ABSOLUTE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"

#Change to tty2 to display the dialog
if ! chvt 2 &>/dev/null; then
    break
fi

(
script stuff
) | dialog --title "IT Afterconfiguration" --infobox "\n           P L E A S E\n             W A I T\n\n  Your system is being configured" 8 40

dialog --no-cancel --no-ok --pause '   Continuing in ...' 6 27 5 --
clear

rm -rf $ABSOLUTE_PATH

#Change back to tty1 / login manager
if ! chvt 1 &>/dev/null; then
        break
fi
Sefer
  • 21