Cyberithub

[Solved] "Failed to restart snapd.mounts-pre.target: Operation refused"

Advertisements

In this article, we will see how to solve Failed to restart snapd.mounts-pre.target: Operation refused, unit snapd.mounts-pre.target may be requested by dependency only (it is configured to refuse manual start/stop) error. Many times, you might have noticed that whenever you try to install snapd package on your Ubuntu/Debian based linux systems, you always get this error on the output. Last night, I also faced the same issue. So I started troubleshooting the error and after a while, I understood the root cause. At this time, I also decided to write an article about this so that it will help you folks as well.

 

[Solved] "Failed to restart snapd.mounts-pre.target: Operation refused"

[Solved] "Failed to restart snapd.mounts-pre.target: Operation refused"

Also Read: [Solved] "aria2c: command not found" error

Advertisements

As I was explaining, something similar happened to me as well when I tried installing snapd package on my Ubuntu 22.04 LTS system from default ubuntu repo using sudo apt install snapd command as you can see below.

cyberithub@ubuntu:~$ sudo apt install snapd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
snapd
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 23.8 MB of archives.
After this operation, 102 MB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 snapd amd64 2.58+22.04.1 [23.8 MB]
Fetched 23.8 MB in 11s (2,245 kB/s)
Selecting previously unselected package snapd.
(Reading database ... 234352 files and directories currently installed.)
Preparing to unpack .../snapd_2.58+22.04.1_amd64.deb ...
Unpacking snapd (2.58+22.04.1) ...
Setting up snapd (2.58+22.04.1) ...
snapd.failure.service is a disabled or a static unit not running, not starting it.
snapd.snap-repair.service is a disabled or a static unit not running, not starting it.
Failed to restart snapd.mounts-pre.target: Operation refused, unit snapd.mounts-pre.target may be requested by dependency only (it is configured to refuse manual start/stop).
See system logs and 'systemctl status snapd.mounts-pre.target' for details.
Could not execute systemctl: at /usr/bin/deb-systemd-invoke line 142.
Processing triggers for gnome-menus (3.36.0-1ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3) ...

While above error could occur due to many reasons but most of the time it is because the previous installation of snapd was not removed properly, the remnants of last configuration still remains. Hence throwing Failed to restart snapd.mounts-pre.target: Operation refused, unit snapd.mounts-pre.target may be requested by dependency only (it is configured to refuse manual start/stop) error on output.

Advertisements

So to fix the problem, you have to remove all the left over configuration files using sudo apt purge snapd command. If you are looking to remove all the dependencies as well then use sudo apt purge snapd --auto-remove command as shown below.

NOTE:

Advertisements
Please note that below command will forcefully remove the span and all the packages installed via snap. So please be careful before running below command.
cyberithub@ubuntu:~$ sudo apt purge snapd --auto-remove
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
snapd*
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
After this operation, 102 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 234444 files and directories currently installed.)
Removing snapd (2.58+22.04.1) ...
Warning: Stopping snapd.service, but it can still be activated by:
snapd.socket
Processing triggers for gnome-menus (3.36.0-1ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3) ...
(Reading database ... 234351 files and directories currently installed.)
Purging configuration files for snapd (2.58+22.04.1) ...
Stopping snap-bare-5.mount
Stopping unit snap-bare-5.mount
Waiting until unit snap-bare-5.mount is stopped [attempt 1]
snap-bare-5.mount is stopped.
Removing snap bare and revision 5
Removing snap-bare-5.mount
Stopping snap-core-15925.mount
Stopping unit snap-core-15925.mount
Waiting until unit snap-core-15925.mount is stopped [attempt 1]
snap-core-15925.mount is stopped.
Removing snap core and revision 15925
Removing snap-core-15925.mount
Stopping snap-core-16091.mount
Stopping unit snap-core-16091.mount
Waiting until unit snap-core-16091.mount is stopped [attempt 1]
...............................................................

After successfully removing all the configuration remnants, you can now try to install snapd again by using sudo apt install snapd command. This time you will notice that there will be no Failed to restart snapd.mounts-pre.target: Operation refused, unit snapd.mounts-pre.target may be requested by dependency only (it is configured to refuse manual start/stop) error on the output.

cyberithub@ubuntu:~$ sudo apt install snapd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
snapd
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 23.8 MB of archives.
After this operation, 102 MB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 snapd amd64 2.58+22.04.1 [23.8 MB]
Fetched 23.8 MB in 16s (1,491 kB/s)
(Reading database ... 234348 files and directories currently installed.)
Preparing to unpack .../snapd_2.58+22.04.1_amd64.deb ...
Unpacking snapd (2.58+22.04.1) ...
Setting up snapd (2.58+22.04.1) ...
snapd.failure.service is a disabled or a static unit, not starting it.
snapd.mounts-pre.target is a disabled or a static unit, not starting it.
snapd.mounts.target is a disabled or a static unit, not starting it.
snapd.snap-repair.service is a disabled or a static unit, not starting it.
Processing triggers for gnome-menus (3.36.0-1ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3) ...

You can also verify the running status of snapd daemon by using systemctl status snapd command as shown below. It should show you in active and running state. This confirms that snapd package installed successfully without any error.

Advertisements
cyberithub@ubuntu:~$ systemctl status snapd
● snapd.service - Snap Daemon
     Loaded: loaded (/lib/systemd/system/snapd.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2023-10-03 23:36:51 IST; 28s ago
TriggeredBy: ● snapd.socket
   Main PID: 68839 (snapd)
      Tasks: 10 (limit: 4542)
     Memory: 104.3M
        CPU: 11.513s
     CGroup: /system.slice/snapd.service
             └─68839 /usr/lib/snapd/snapd

Oct 03 23:36:40 ubuntu systemd[1]: Starting Snap Daemon...
Oct 03 23:36:41 ubuntu snapd[68839]: overlord.go:272: Acquiring state lock file
Oct 03 23:36:41 ubuntu snapd[68839]: overlord.go:277: Acquired state lock file
Oct 03 23:36:41 ubuntu snapd[68839]: patch.go:64: Patching system state level 6 to sublevel 1...
Oct 03 23:36:41 ubuntu snapd[68839]: patch.go:64: Patching system state level 6 to sublevel 2...
Oct 03 23:36:41 ubuntu snapd[68839]: patch.go:64: Patching system state level 6 to sublevel 3...
Oct 03 23:36:41 ubuntu snapd[68839]: daemon.go:247: started snapd/2.60.3 (series 16; classic) ubuntu/22.04 (amd64) linux/6.2.0-32-generic.
Oct 03 23:36:42 ubuntu snapd[68839]: daemon.go:340: adjusting startup timeout by 1m45s (pessimistic estimate of 30s plus 5s per snap)
Oct 03 23:36:42 ubuntu snapd[68839]: backends.go:58: AppArmor status: apparmor is enabled and all features are available (using snapd provided apparmor_pars>
Oct 03 23:36:51 ubuntu systemd[1]: Started Snap Daemon.

Hopefully, above solution would be enough to solve your Failed to restart snapd.mounts-pre.target: Operation refused, unit snapd.mounts-pre.target may be requested by dependency only (it is configured to refuse manual start/stop) error as well.

Leave a Comment