Skip to content

Instantly share code, notes, and snippets.

@danielrosehill
Created December 6, 2025 12:40
Show Gist options
  • Select an option

  • Save danielrosehill/1baf71987d4494f20cfed5eee0086370 to your computer and use it in GitHub Desktop.

Select an option

Save danielrosehill/1baf71987d4494f20cfed5eee0086370 to your computer and use it in GitHub Desktop.
Speed Up Linux Boot by Deferring Services Until After Graphical Desktop (KDE Plasma / systemd)

Speed Up Linux Boot by Deferring Services Until After Graphical Desktop

A common cause of slow boot times on Linux desktops is services that block the boot process unnecessarily. Many services (Docker, Samba, databases, etc.) don't need to be running before you reach your desktop—they can start immediately after the graphical environment loads.

This guide explains how to defer services to start after graphical.target on systemd-based systems like Ubuntu with KDE Plasma.

The Problem

When you run systemd-analyze blame, you might see something like:

47s docker.service
37s smbd.service
19s systemd-udev-settle.service
 6s snapper-boot.service
 5s webcam-config.service
 4s nas-mounts.service
 3s postgresql@17-main.service
 3s nfs-server.service

These services block your boot, even though you don't need them until after you're logged in.

The Solution: Defer Services to After graphical.target

Method 1: Drop-in Override (Recommended)

Create a drop-in override file that adds After=graphical.target to any service. This doesn't modify the original service file and survives package updates.

# Create override directory
sudo mkdir -p /etc/systemd/system/SERVICE_NAME.service.d

# Create the override file
sudo tee /etc/systemd/system/SERVICE_NAME.service.d/defer-boot.conf << 'EOF'
[Unit]
After=graphical.target
EOF

# Reload systemd
sudo systemctl daemon-reload

Example: Defer Docker

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/defer-boot.conf << 'EOF'
[Unit]
After=graphical.target
EOF
sudo systemctl daemon-reload

Batch Defer Multiple Services

for service in docker smbd snapper-boot nfs-server postgresql@; do
    sudo mkdir -p /etc/systemd/system/${service}.service.d
    sudo tee /etc/systemd/system/${service}.service.d/defer-boot.conf << 'EOF'
[Unit]
After=graphical.target
EOF
done
sudo systemctl daemon-reload

Method 2: Modify the Service File Directly

For custom services you control, edit the [Unit] section:

[Unit]
Description=My Custom Service
After=network-online.target graphical.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/path/to/script.sh

[Install]
WantedBy=graphical.target

Key changes:

  • Add graphical.target to After=
  • Change WantedBy=multi-user.target to WantedBy=graphical.target

Then reload and re-enable:

sudo systemctl daemon-reload
sudo systemctl reenable my-service.service

Method 3: Timer-Based Services (For Maintenance Tasks)

For periodic maintenance tasks (updates, cleanup), use systemd timers with a boot delay:

# /etc/systemd/system/my-maintenance.timer
[Unit]
Description=Run maintenance after boot
After=graphical.target

[Timer]
OnCalendar=daily
Persistent=true
OnBootSec=5min  # Wait 5 minutes after boot

[Install]
WantedBy=timers.target

Services Safe to Defer

These services typically don't need to run before your desktop is ready:

Service Purpose Safe to Defer?
docker.service Container runtime ✅ Yes
smbd.service Samba file sharing ✅ Yes
nfs-server.service NFS file sharing ✅ Yes
postgresql@.service Database server ✅ Yes
mysql.service Database server ✅ Yes
tor@default.service Tor network ✅ Yes
mpd.service Music player daemon ✅ Yes
cups.service Printing ✅ Yes
snapper-boot.service Btrfs snapshots ✅ Yes
preload.service Readahead (legacy) ✅ Disable entirely

Services NOT to Defer

These are required for the graphical environment:

Service Purpose
NetworkManager.service Network connectivity
dbus.service D-Bus message bus
systemd-logind.service Login management
sddm.service / gdm.service Display manager
polkit.service Authorization

Verifying Your Changes

Check boot time improvement

systemd-analyze

See what's still slow

systemd-analyze blame | head -20

View the critical boot path

systemd-analyze critical-chain

Verify a service has the override

systemctl cat docker.service

You should see your override file listed at the end.

Troubleshooting

Service not starting after boot?

Check if it's enabled and what target it's wanted by:

systemctl is-enabled SERVICE_NAME
systemctl show SERVICE_NAME --property=WantedBy

Remove a defer override

sudo rm /etc/systemd/system/SERVICE_NAME.service.d/defer-boot.conf
sudo rmdir /etc/systemd/system/SERVICE_NAME.service.d 2>/dev/null
sudo systemctl daemon-reload

Check for failed services

systemctl --failed

Real-World Results

On a system with Docker, Samba, PostgreSQL, NFS, and various maintenance services, these changes reduced time-to-desktop from ~2 minutes 45 seconds to under 30 seconds.

All deferred services start immediately once the desktop appears, so they're typically ready within seconds of logging in.


Tested on Ubuntu 25.04 with KDE Plasma on Wayland. Should work on any systemd-based Linux distribution.


This gist was generated by Claude Code. Please verify any information before relying on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment