Fix system hanging on reboot or shutdown with /oldroot message caused by Nvidia

February 10, 2022 - Reading time: 2 minutes

Over the years there was no real solution for this sporadic issue where the system would hang for a minute or more, when trying to reboot or shutdown, with warning messages about /oldroot file system. The issue was completely random, you could not have it for weeks, then it could suddenly appear for no obvious reason.

It was known to be linked to the Nvidia drivers but no one could really tell why, many people claimed they had the solution by adding the Nvidia modules to be early loaded in mkinitcpio config, others with some other random voodoo, but none worked. They thought it worked because the issue is sporadic, and there is no consistency so they might had luck and on their subsequent tests there was no issue, but this had nothing to do with their "solution".

Here is the proper way to deal with that issue (a workaround until Nvidia or Systemd change things has said here), it is to unload the Nvidia modules when shutting down, with the help of a systemd script. Solution was provided on Manjaro forum from the findings of people on Arch linux forum.

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

The issue is now fixed, Nvidia driver isn't blocking anything on reboot or shutdown now.