No shutdown button on Linux Mint

Looking for the missing red button that turns off your system? See how to get it back.

It may happen that some random day you are working on your computer and then wanting to turn it off just to find that there is no shutdown button, just like in the following image:

Where is the shutdown button?
Where is the shutdown button?

Let’s try to understand what happened and how to get the button back where it belongs.

The cause

For my scenario, I did screw up during some updates :) On a tiny box with Linux Mint installed, I decided to enable Unattended/automatic updates so the people using the computer did not need to worry about them. However, during a maintenance, I had the need to force a system shutdown due instability (the plain ol’ good sudo poweroff). The problem was unattended updates were running at the same time leaving the system with some broken updates.

After a restart, I tried to run run sudo dpkg --configure -a to solve the broken packages. While this step was easy and worked great, there was still a problem: the power off button was missing, leaving me unable to (properly) shutdown the system.

The problem is that these unattended upgrades perform some configuration changes on the system to ensure updates are installed. One of the configurations is to block the shutdown option in order to prevent an user to power off the system when the updates were taking place. At least for users that follow the green path, unlike me.

The solution

After some hours digging the web and tired of people suggesting adding a workaround icon to overcome the issue (they were still trying to help anyways with a valid workaround, but I just did not accept it as a proper solution), I took a look at update manager source code to see how it works. Found a automatic_upgrades.py script that is pretty self explanatory on how it blocks the shutdown option:

pkla_source = "/usr/share/linuxmint/mintupdate/automation/99-mintupdate-temporary.pkla"
pkla_target = "/etc/polkit-1/localauthority/90-mandatory.d/99-mintupdate-temporary.pkla"
try:
    power_supply_file = open(power_connectfile)
    powersupply = power_supply_file.read()[0]=='1'
    power_supply_file.close()
except:
    powersupply = True
    log.write(power_connectfile+" not found. Ignore power supply check.")
if powersupply:
    try:
        # Put shutdown and reboot blocker into place
        os.symlink(pkla_source, pkla_target)
    except:
        pass

What this code does is: if the system is connected to a power supply (opposed to running on battery), it copies the file 99-mintupdate-temporary.pkla to the /etc/polkit-1/... directory. Long story short, what it does is to create a System Policy to forbid the shutdown option from being applied.

Further analyzing the script we can also see that when finishing the updates the script attempts to remove this file so the shutdown option would be back again:

 try:
     # Remove shutdown and reboot blocker
     os.unlink(pkla_target)
 except:
     pass

The problem? When I forced the system shutdown the script did not had time to finish, so it did not reach this instruction. The solution? Just remove the file by yourself:

sudo rm /etc/polkit-1/localauthority/90-mandatory.d/99-mintupdate-temporary.pkla

Try to shutdown the system again (properly I mean). Notice the red Shutdown button is back and you can turn the computer off as usual.