I'd like to know how to replace a service unit file from a certain package with my own version. That is, I have found some problems in that service unit file and have corrected them. However, with the next update of that package, my changes will be lost.

I am aware that I could modify the original package, work with pinning and so on. But that seems to be overly complicated in this case, and I really would like to get the updates of the respective package in a normal way. It is solely the service unit file which I would like to keep in my corrected version.

The following solution came to my mind:

  • Copy /lib/systemd/system/daemon.service to /etc/systemd/system/my-daemon.service
  • Disable and mask daemon.service so that systemd won't start it anymore, and so that package updates hopefully won't re-enable it
  • Make appropriate corrections in my-daemon.service
  • Enable my-daemon.service

Would this be a reasonable method? Is there an "official" solution to this problem?


By default, systemd will use service file from /usr/lib/systemd/system/daemon.service. However, if it finds the service unit in the /etc/systemd/system/daemon.service, it automatically uses this unit and ignores the default one.

So basically

cp /usr/lib/systemd/system/daemon.service /etc/systemd/system/daemon.service

and make whatever changes you need in the file /etc/systemd/system/daemon.service .

Alternative approach:

If you do not like this or need just some minor edits, you can run systemctl edit daemon.service and make changes there. Those changes get merged to the service unit the systemd will try to run, regardles if the unit is located under /usr/lib/... or /etc/....


If the package-supplied unit file gets updated, those changes will get automatically merged with your adjustments.


If the package-supplied unit file gets updated, those changes will get automatically merged with your adjustments. (No kidding. Sometimes, you really do not want this.)

It is ugly - systemd creates /etc/systemd/system/daemon.overrides.d/ directory where your changes are located. It is a bit funky and easy to miss, so it may bite you in the future.

You cannot replace things this way, only add some new, because overrides are merged into the unit. (Not sure on this though, it is a bit ago I last used this.)

  • Thank you very much, upvoted and accepted. I really didn't know that systemd prefers /etc over /usr (on Debian, /usr/lib). This finally makes a clean solution to my problem possible; I'll take this approach. The alternative solution you gave is interesting as well, and I'll try to remember and take notes just in case I need it later, but for my current problem, I think the first solution you gave is by far better.
    – Binarus
    Mar 27 '20 at 8:41
  • YW. :) I will correct the paths in my answer. Yesterday, I wrote it from top of the head.
    – Fiisch
    Mar 27 '20 at 9:34
  • Thanks again, no problem. I was assuming that you were on another distro where the path may be different :-)
    – Binarus
    Mar 27 '20 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.