Slow boot - pkgfile-update.service takes 14 seconds

My PC has a SSD and has always been really fast to boot, but lately it takes much more time…
systemd-analyze

Startup finished in 2.041s (kernel) + 24.315s (userspace) = 26.357s 
graphical.target reached after 13.028s in userspace.

Can anyone please advise on how can I fix/improve the services that are taking up more time?

systemd-analyze blame

14.204s pkgfile-update.service
 7.289s updatedb.service
 3.290s dev-sda1.device
 3.194s NetworkManager-wait-online.service
 3.019s cups.service
 2.132s nmb.service
 1.841s libvirtd.service
 1.767s systemd-random-seed.service
 1.589s ModemManager.service
 1.501s polkit.service
 1.402s systemd-udevd.service
 1.372s avahi-daemon.service
 1.348s dbus.service
 1.301s systemd-logind.service
 1.281s systemd-machined.service
 1.019s udisks2.service
 1.002s systemd-journal-flush.service
  977ms NetworkManager.service
  817ms smb.service
  801ms systemd-tmpfiles-setup-dev.service
  593ms tlp.service
  534ms systemd-modules-load.service
  501ms lvm2-monitor.service
  486ms logrotate.service
  408ms systemd-tmpfiles-setup.service
  370ms colord.service
  310ms user@1000.service
  230ms accounts-daemon.service
  219ms lightdm.service
  164ms upower.service
  159ms bluetooth.service
  147ms systemd-udev-trigger.service
  128ms systemd-tmpfiles-clean.service
  112ms systemd-journald.service
  102ms systemd-sysctl.service
   99ms ufw.service
   97ms modprobe@fuse.service
   55ms systemd-binfmt.service
   45ms dev-hugepages.mount
   44ms dev-mqueue.mount
   43ms systemd-update-utmp.service
   42ms sys-kernel-debug.mount
   41ms sys-kernel-tracing.mount
   40ms kmod-static-nodes.service
   38ms modprobe@configfs.service
   38ms modprobe@drm.service
   31ms systemd-remount-fs.service
   21ms pamac-daemon.service
   21ms user-runtime-dir@1000.service
   18ms rtkit-daemon.service
   11ms systemd-user-sessions.service
    7ms proc-sys-fs-binfmt_misc.mount
    4ms alsa-restore.service
    4ms sys-fs-fuse-connections.mount
    2ms tmp.mount
    1ms sys-kernel-config.mount

systemd-analyze plot > plot.svg

IIRC that service is reliant on internet connectivity, thus internet speed.

Please provide the output of:

systemd-analyze critical-chain pkgfile-update.service

…and:

systemctl cat pkgfile-update.service

The solution here fixed it for me on one of my computers:

1 Like
The time when unit became active or started is printed after the "@" character.
The time the unit took to start is printed after the "+" character.

`-network-online.target @2.255s
  `-NetworkManager-wait-online.service @1.868s +386ms
    `-NetworkManager.service @1.760s +106ms
      `-dbus.service @1.687s +69ms
        `-basic.target @1.683s
          `-sockets.target @1.683s
            `-virtlogd.socket @1.683s
              `-sysinit.target @1.679s
                `-systemd-update-done.service @1.673s +5ms
                  `-ldconfig.service @1.330s +342ms
                    `-local-fs.target @1.328s
                      `-run-credentials-systemd\x2dtmpfiles\x2dsetup.service.mount @1.344s
                        `-local-fs-pre.target @439ms
                          `-systemd-tmpfiles-setup-dev.service @392ms +46ms
                            `-systemd-sysusers.service @355ms +36ms
                              `-systemd-remount-fs.service @318ms +27ms
                                `-systemd-journald.socket @302ms
                                  `--.mount @284ms
                                    `--.slice @283ms

# /usr/lib/systemd/system/pkgfile-update.service
[Unit]
Description=pkgfile database update
RequiresMountsFor="/var/cache/pkgfile"
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/pkgfile -u
Nice=19
StandardOutput=null
StandardError=journal
PrivateTmp=yes
PrivateDevices=yes
CapabilityBoundingSet=
NoNewPrivileges=yes

I saw your post before posting mine, and I believe it’s something different because you had a service failure, and my service does not fail, it just takes too long

Try the following:

  1. Edit the service:
sudo systemctl edit pkgfile-update.service
  1. Add the following to the line starting with After:
 nss-lookup.target

So that it becomes:

After=network-online.target nss-lookup.target
  1. Save and exit the editor.

Reload the unit configurations:

systemctl daemon-reload
  1. Restart the service
systemctl restart pkgfile-update.service
  1. Say a little prayer, do a little dance, and reboot to check.

If it worked, heap on the praise. If it didn’t, however, well…luckily I think I’m halfway across the world from you.

1 Like

ooops… got this after editing and saved the file
sudo systemctl edit pkgfile-update.service
Editing "/etc/systemd/system/pkgfile-update.service.d/override.conf" canceled: temporary file is empty.

Urgh.

Create this directory:

sudo mkdir /etc/systemd/system/pkgfile-update.service.d

Then create the file:

sudo touch /etc/systemd/system/pkgfile-update.service.d/override.conf

Followed by trying the edit again.

If that doesn’t work, I can’t help 'til tomorrow, sorry.

See

No worries, this is not urgent. I appreciate your help. See you tomorrow.

ricardo@WorkStation2:~$ sudo mkdir /etc/systemd/system/pkgfile-update.service.d
ricardo@WorkStation2:~$ sudo touch /etc/systemd/system/pkgfile-update.service.d/override.conf
ricardo@WorkStation2:~$ sudo systemctl edit pkgfile-update.service
Editing "/etc/systemd/system/pkgfile-update.service.d/override.conf" canceled: temporary file is empty.

Could this be related to nano? (see below override file name is weird).

That’s just a temporary filename.

I think @Mirdarthos meant sudo systemctl edit pkgfile-update.service --full, as their instructions should work for that.

However if you’re going to override partially, you need to put it between the comments. I’ve never overridden a service this way before but I think this should do it. :crossed_fingers:

### Editing /etc/systemd/system/pkgfile-update.service.d/override.conf
### Anything between here and the comment below will become the new contents of the file

[Unit]
After=nss-lookup.target


### Lines below this comment will be discarded

https://unix.stackexchange.com/questions/398540/how-to-override-systemd-unit-file-settings

1 Like
This is the manual, unnecessary method, I have figured out the how to do it the better way, described below.

I have done one or two before, and both work fine. I describe the method I used on my Ubuntu server above and used the manual way on my Manjaro PC. So let’s do it that way:

  1. Create the directory for the override file:
    The directory can be found in the error:
 Editing "/etc/systemd/system/pkgfile-update.service.d/override.conf" canceled: temporary file is empty.

So the directory is /etc/systemd/system/pkgfile-update.service.d, so let’s create it:

sudo mkdir /etc/systemd/system/pkgfile-update.service.d
  1. And let’s move to it:
cd /etc/systemd/system/pkgfile-update.service.d
  1. Now let’s create the override.conf file:
sudo touch override.conf
  1. Now edit the file.
    Use any editor you wish, I’m using `nano``.
sudo nano override.conf
  1. Add the following text to the file:
[Unit]
After=network-online.target nss-lookup.target
  1. Save, Ctrl+OY, and exit, Ctrl+XY.
    I used nano as example, but use the editor you prefer.

  2. Reload the SystemD configuration files:

sudo systemctl daemon-reload
  1. (Just for giggles, not strictly necessary.) Restart the service:
sudo systemctl restart pkgfile-update.service
  1. reboot you computer and check now.

Edit:

After learning how to do it this way, it sort of makes sense why it didn’t work the first time. It also makes this much easier. After some searching, I came across this page, where the last comment states:

For clarification, this is a really common error to run into. When you run systemd edit, everything is commented out INCLUDING THE SECTIONS. If a user isn’t paying attention, its easy to add a valid rule under a commented out section, which will result in this “semi misleading” error. It’s not that the temporary file is empty, the file doesn’t have any uncommented sections.

So, it turns out the [Sections] must also be un-commented. So edit the .service unit again:

sudo systemctl edit pkgfile-update.service

There is a line:

### Anything between here and the comment below will become the new contents of the file

…followed by a few blank lines, and then the line:

### Lines below this comment will be discarded

So it’s obvious, when you look at it with more than a passing glance as to why we got the above error. So, copy and paste the line beginning with After from below that last line, to between those 2 lines mentioned above, and remove the comment at the start of the line. Also add the [Unit] section heading above it, so the file now looks like this:

GNU nano 7.1                                                                            /etc/systemd/system/pkgfile-update.service.d/.#override.conf6cc0056fc45b7088
### Editing /etc/systemd/system/pkgfile-update.service.d/override.conf
### Anything between here and the comment below will become the new contents of the file

[Unit]
After=network-online.target nss-lookup.target

### Lines below this comment will be discarded

### /usr/lib/systemd/system/pkgfile-update.service
# [Unit]
# Description=pkgfile database update
# RequiresMountsFor="/var/cache/pkgfile"
# After=network-online.target
# Wants=network-online.target
#
# [Service]
# Type=oneshot
# ExecStart=/usr/bin/pkgfile -u
# Nice=19
# StandardOutput=null
# StandardError=journal
# PrivateTmp=yes
# PrivateDevices=yes
# CapabilityBoundingSet=
# NoNewPrivileges=yes

When done save, Ctrl+OY, and exit, CtrlCtrl+XX.

When exited, the configuration must be updated. (Yeah, I checked to make sure. But it can’t do harm anyway.)

sudo systemctl daemon-reload

You can now check if it worked:

systemctl cat pkgfile-update.service

At the bottom of the output, it should state:

# /etc/systemd/system/pkgfile-update.service.d/override.conf
[Unit]
After=network-online.target nss-lookup.target

It should now be safe to either restart the service:

sudo systemctl restart pkgfile-update.service

…or reboot the PC. When done, check the status that everything’s in order:

$ systemctl status pkgfile-update.service                                                                                                                                                                                                            
○ pkgfile-update.service - pkgfile database update
Loaded: loaded (/usr/lib/systemd/system/pkgfile-update.service; static)
Drop-In: /etc/systemd/system/pkgfile-update.service.d
└─override.conf
Active: inactive (dead) since Fri 2022-12-23 10:43:47 SAST; 30min ago
TriggeredBy: ● pkgfile-update.timer
Main PID: 16225 (code=exited, status=0/SUCCESS)
CPU: 106ms

Dec 23 10:43:46 Mirdarthos-PC systemd[1]: Starting pkgfile database update...
Dec 23 10:43:47 Mirdarthos-PC systemd[1]: pkgfile-update.service: Deactivated successfully.
Dec 23 10:43:47 Mirdarthos-PC systemd[1]: Finished pkgfile database update.

Note the Drop-In: /etc/systemd/system/pkgfile-update.service.d section shows it’s being over-wridden.


Note:

I noticed pkgfile-update.service is triggered by pkgfile-update.timer, which has a target of WantedBy=multi-user.target. And, according to this page that is:

Set up a non-graphical multi-user system.

Meaning, AFAIK, it’ll only happen during the startup process when logging in. So, it might not have a big, or any really, influence on your startup time.

2 Likes

It’s probably running because it missed a run whilst the system was off.

I think this should work. :crossed_fingers:

sudo systemctl edit pkgfile-update.timer --full

Change the file like this.

[Unit]
Description=pkgfile database update timer

[Timer]
OnCalendar=daily
AccuracySec=6h
Persistent=no
OnBootSec=2min

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload

2 mins may be overkill but it should wait until after you’ve booted from now on.

systemd/Timers - ArchWiki


@Mirdarthos

Perhaps check “Example 2. Overriding vendor settings” from the link below. I think you’re re-adding network-online.target a second time, not sure if it matters though.

https://www.freedesktop.org/software/systemd/man/systemd.unit.html

I don’t either…

:man_shrugging:

Edit:

I suspect you are right. But I, personally, don’t have any way to test it right now, so I’m going to leave it be, for now at least.

Done! And now it’s booting super fast again, look:

systemd-analyze

Startup finished in 1.136s (kernel) + 5.992s (userspace) = 7.128s 

systemd-analyze blame

3.434s nmb.service
1.359s systemd-random-seed.service
 897ms systemd-binfmt.service
 795ms cups.service
 757ms dev-sda1.device
 447ms tlp.service
 381ms libvirtd.service
 344ms NetworkManager-wait-online.service
 343ms ModemManager.service
 314ms systemd-modules-load.service
 226ms systemd-udev-trigger.service
 183ms systemd-journald.service
 160ms systemd-udevd.service
 150ms udisks2.service
.
.
.

systemctl status pkgfile-update.service

* pkgfile-update.service - pkgfile database update
     Loaded: loaded (/usr/lib/systemd/system/pkgfile-update.service; static)
    Drop-In: /etc/systemd/system/pkgfile-update.service.d
             `-override.conf
     Active: inactive (dead)
TriggeredBy: * pkgfile-update.timer

Do you advise me to still do this step? Boot time is now normal, but perhaps I should still do this step?

I personally don’t think it’s necessary. Won’t do any harm, but not necessary.

1 Like

Thank you so much @Mirdarthos and @dmt for your help. This issue was very weird to me, I have 2 more computers with Manjaro, and only this one was having this problem… so to me the cause remains a mistery.

Welp. Mistery solved. Apparently. Now at least you know what to look for should one of the other PCs start acting up.

1 Like

pkgfile is used for zsh’s command not found handler. The pkgfile timer runs the service daily, or at the next boot should the system be off when it’s meant to run.

So the cause is presumably leaving the pc off for a day or more. The service updates the package databases so 14s seems fairly reasonable, I just timed it at ~10s but of course it may vary.

AKAIK zsh (actually manjaro-zsh-config) is the only thing in a default install that depends on pkgfile.

If you don’t use the pkgfile version of zsh’s command not found handler and don’t use pkgfile for anything else, then you might as well disable the timer.

sudo systemctl disable pkgfile-update.timer

If you do use it and don’t want the occasional slow boot then override the timer instead (or maybe the service, but I’m not sure that will do much).

If you don’t mind the odd slow boot then just leave it.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.