Back to Blog
Homelab 3 min read

Cutting the Fat: Turning a Full Pi OS Into a Single-Purpose Appliance

An unused file share and a desktop GUI on a headless server are just attack surface with extra steps. How I stripped both off a live resolver without paging myself or dropping the network.

The cleanest service is the one that isn't running. I'd been carrying a Samba share I never opened and a full desktop environment on a box that hasn't had a monitor plugged into it since the day I imaged it. Neither was doing harm, exactly. Both were listening ports, dependency chains, and update obligations I didn't need. So I cut them — on a live machine, mid-week, without taking DNS down.

Every Listening Port Is a Liability#

Hardening isn't only about firewall rules. It's about how much of the box can fail. A service you don't use can't help you, but it can still be the thing with the CVE, the thing Fail2Ban has to babysit, the thing that fills a log. On a machine that resolves DNS for the whole network, every removable service is removable risk.

Killing the NAS I Never Used#

The file share went first. Stopping and purging the daemon is the easy part; the discipline is cleaning up everything that referenced it. That meant dropping the firewall allows for the share port in three places, pulling that port out of the host firewall, removing it from the admin port group, and deleting the systemd failure hooks that watched the service. Then — and this is the step people skip — verifying the rule actually left the kernel over SSH instead of trusting the controller UI. A rule that's gone from the dashboard but still in iptables isn't gone.

Removing the Desktop on a Headless Box#

The GUI was the bigger cut: the full desktop stack, the browser, the compositor, the VNC server, the whole tail of dependencies behind them — about six hundred megabytes that existed only to render a screen nothing ever looked at. The box already booted to a text target. Pulling the desktop just made the install match how the machine actually lives: console only, reachable by SSH and remote-connect, nothing painting pixels.

The apt-mark Trap#

Here's the one that would have bitten me. The remote-access agent I rely on to reach this box was, as far as the package manager was concerned, only being kept around as a dependency of the desktop stack I was about to remove. Run a naive autoremove and it would have cheerfully uninstalled my way back in. The fix is to pin it first — mark it as manually installed so autoremove treats it as something I want, not orphaned baggage. Pin the lifeline before you cut the rope.

Order of Operations#

The thing that makes this safe on a live box is sequence. Tear services down in an order that doesn't trip your own alarms — stop the watchers before you remove the watched, or you page yourself at two in the morning over a thing you deliberately killed. Guard the services that must survive: the web stack, its process manager, the reverse proxy, the tunnel. Through the whole teardown the website never blinked and not a single managed unit entered a failed state. That's the bar — not "it came back up," but "it never went down."

The Payoff#

What's left is effectively an appliance: DNS, time, monitoring, and the website, and nothing else. No file share, no browser, no desktop, no VNC listener. Smaller service surface, fewer ports, fewer update obligations, less to reason about when something does go wrong. The box now does exactly what it's for and not one thing more, which is the whole point of an appliance and a fair description of what a hardened server should be.