Script nvidia.shutdown recreated after update

An error message flashed up on the screen when I shut down the PC. The message said it was definitely due to the script /usr/lib/systemd/system-shutdown/nvidia.shutdown, so I removed it, and the message was gone. However, every time I did an update, this script was created automatically and the message appeared again. How can I prevent this script from being recreated after an update?

I used to create the script following this post, but I deleted it some time ago when it was no longer necessary. I also followed this post to find out that the script is owned by nvidia-utils 510.73.05-1. Do I have to remove the script every time after an update to fix it? Why was the script included in nvidia-utils even it was not needed anymore? Please share your thoughts if you have any ideas on this issue. Thank you!

system info:

Kernel: 5.17.9-1-MANJARO arch: x86_64 bits: 64 compiler: gcc v: 12.1.0
Desktop: Xfce v: 4.16.0 tk: Gtk v: 3.24.29 info: xfce4-panel wm: xfwm
    v: 4.16.1 vt: 7 dm: LightDM v: 1.30.0 Distro: Manjaro Linux base: Arch Linux

In your first link, there is an explanation on why this script was proposed.
If it is indeed no longer necessary (I must admit that I do not get any error messages on shutdown here) please kindly contact the nvidia-utils 510.73.05-1 maintainer (for example, by writing an issue report at Issues · Packages / Extra / nvidia-utils · GitLab) to have that script removed again.

1 Like

Worth a try would be this:

sudo mkdir -pv /etc/systemd/system-shutdown
sudo touch  /etc/systemd/system-shutdown/nvidia.shutdown

Since /usr/lib/systemd/ will be overwritten on every update, the custom dir would be /etc/systemd/. That one gets not overwritten. By creating a similiar dir path, but creating an empty file, it should priorize the one at /etc over /usr/lib.

i have the same nvidia.shutdown, and i never created it :thinking: however i dont see any messages …

Me neither. As I originally proposed the script, I’m indeed curious on what error messages it produces.

You never mentioned what this error says.

Source of information?

Yes as others asked, what is the exact error message you say it produces on your computer (but apparently not on all the other Nvidia users computers).

If OP has the same error log on shutdown as I do (I am pretty sure that it is), then the exact error message would be: /usr/lib/systemd/system-shutdown/nvidia.shutdown failed with exit status 1.

This happens always before shutdown, but sometimes the PC takes 2 seconds, other times 2 mins until the message is displayed for 2 seconds and then shutdowns completely.

1 Like

Same error on my machine. Laptop computer with Intel HD 4600 + GeForce GT 730M GPU. I use optimus-manager, tipically set on Intel.

1 Like

Maybe you can all give relevant journal logs of when it happens so maybe something can be found about your issue.

The message was /usr/lib/systemd/system-shutdown/nvidia.shutdown failed with exit status 1. After I updated to the latest version (Linux 5.17.4-1), two more lines were displayed above:

Broadcast message from xxx@xxx-pc on pts/0 (date & time):
The system is going down for poweroff NOW!
[some numbers][some numbers]/usr/lib/systemd/system-shutdown/nvidia.shutdown failed with exit status 1

Thanks for your reply. I tried what you suggested, but it didn’t work. It seems /usr/lib/systemd/system-shutdown/nvidia.shutdown would still be run on shutdown.

That’s because I removed the script and didn’t produce anything undesired.

The message was /usr/lib/systemd/system-shutdown/nvidia.shutdown failed with exit status 1. After I updated to the latest version (Linux 5.17.4-1), two more lines were displayed above:

Broadcast message from xxx@xxx-pc on pts/0 (date & time):
The system is going down for poweroff NOW!
[some numbers][some numbers]/usr/lib/systemd/system-shutdown/nvidia.shutdown failed with exit status 1

Thank you. How can I create or output the journal logs for shutdown?

That’s exactly the message. But it always takes 1 or 2 seconds to disappear on the monitor of my PC.

FYI, I’ve dropped the nvidia.shutdown script with the 515.57-1 update (currently only in the unstable branch).

Consequently, that error it was supposed to prevent, is back:

[35509.312925] sd-umoun[56020]: Failed to unmount /oldroot: Device or resource busy
[35509.317505] sd-umoun[56021]: Failed to unmount /oldroot/sys: Device or resource busy
[35509.322349] shutdown[1]: Failed to finalize file systems, ignoring.

Looks like it is not needed on all machines and produces an error when it is not needed (i.e. /oldroot already unmounted).
Hence, it might make sense to check in the script if /oldroot is still mounted before trying to unload the modules.

What? :face_with_raised_eyebrow:

You got the story completely wrong, you have the error because there is no more the file that was unloading Nvidia modules at shutdown. Personally I will recreate the file so this error stops coming back.

To recreate it click here

Create the shutdown script

sudo nano /usr/lib/systemd/system-shutdown/nvidia.shutdown

with the following content

#!/bin/sh
#
# Remove all Nvidia modules on shutdown to avoid errors like
#
# sd-umoun: Failed to unmount /oldroot: Device or resource busy
# sd-umoun: Failed to unmount /oldroot/sys: Device or resource busy
# shutdown: Failed to finalize file systems, ignoring.
#
for MODULE in nvidia_drm nvidia_modeset nvidia_uvm nvidia
do
rmmod $MODULE
done

and make the script executable

sudo chmod +x /usr/lib/systemd/system-shutdown/nvidia.shutdown

Guess you also got at least me wrong.
In a nutshell: After introduction of that script in the driver package, there were some user complaints about the script exiting with exit code 1 (meaning that there is either no /oldroot or the modules are already unloaded).
As a consequence, the package maintainer decided to withdraw the script - which, of course, causes that error with /oldroot being busy to recur on my machine.

Hence, for wider use of that script, it might make sense to introduce a check if unloading the modules is necessary at all, for example like this:

for MODULE in nvidia_drm nvidia_modeset nvidia_uvm nvidia
   do
       if lsmod | grep "$MODULE" &> /dev/null ; then
          rmmod $MODULE
       fi
   done  

Checking for the loaded modules one by one may look a bit cumbersome but unfortunately, it does not seem possible to check for the presence of /oldroot as this mountpoint is not visible to commands like mount or mountpoint.