New life for an old laptop as a Linux home server

Last edited on 2024-07-26 Tagged under  #homeServer   #laptop   #debian   #linux 

You might have something in mind that would benefit from having an "always-on, always-available" computer.

For myself, it started with a desire for network-attached storage for automatic daily backups of the contents of my home directory.

Home servers can be so useful, and I especially like the idea of using older laptops in that role.

Something like a Raspberry Pi is certainly a popular alternative, but one big advantage of the laptop option is I already have one not being used! You might also have a spare laptop, or know where to get one for little to no cost.

While 10-year old laptops or chromebooks with limited amounts of RAM might struggle with modern desktop tasks, they can still deliver plenty of power for running a few services as a personal home server. They also include all sorts of things already built-in that would be extras on the Pi: a case, display, keyboard, multiple ports, and storage. Laptops are designed to be frugal with power and - if the battery still holds a charge - come equipped with their own built-in UPS!

Why buy new when there is a steady stream of cheap and cheerful computer castoffs that have plenty of life left in them? Its not like landfills need the business.

So this is the plan: Pick a laptop. For my current laptop home server project, I'm restoring a circa-2013 Thinkpad X230 to active duty. Install a stable Linux distribution like Debian and gain access to tens of thousands of software packages with the ability to host all kinds of services.

This is how I do it...

1. Install Debian

Installation and basic setup of an encrypted, minimal, console-only base configuration of Debian 12 aka "Bookworm". Read more

2. System configuration

2.1 Reserved IP address

Our new home server should use a reserved IP address so its hosted network services can easily be found.

Display all detected network interfaces on the server along with their IP and MAC addresses:

ip addr

Most home routers come with an installed DHCP (Dynamic Host Control Protocol) server, and allow configuration via a web console. I login to the control panel of the modem-router provided by my ISP and navigate to the DHCP settings, where I reserve an IP address that is attached to the MAC address of the network interface on the home server.

Debian's network interfaces can be auto-enabled and brought up or down with sudo ifup <interface> and sudo ifdown <interface> using the settings in /etc/network/interfaces.

Example: An entry for an ethernet interface to auto-connect at boot:

# The primary network interface
allow-hotplug enp0s25
iface enp0s25 inet dhcp

2.2 SSH keys

Disable password logins and switch to SSH key-based authentication for greater security and non-interactive access. Read more

2.3 Remote unlock

When I encrypt the root partition on my home server, I need to supply the passphrase at boot to unlock the system for startup to continue and reach login. All well and good if I'm sitting in front of the machine with a keyboard and display.

For my home server tucked away, however, I use Dropbear + SSH to remotely unlock the device. Read more

2.4 Terminal multiplexer

Useful on desktops and especially on servers, tmux launches a session in the console that can be divided into multiple windows and panes (multiplexing).

Where it really makes a difference from simply opening multiple terminals or logins, though, is the ability to detach/re-attach sessions. Login to the server, open several windows, run ongoing processes, detach session, logout, login, re-attach session, and restore your working environment!

sudo apt install tmux

Links: Getting started with tmux, and my own tmux config.

2.5 Package and security updates

On my daily desktop, I do manual updates. However, on servers, once you get into several devices and/or infrequent logins, upgrading can quickly get repetitive and timely security updates may be put off.

I use unattended-upgrades to automate the process. Read more

2.6 Logwatch

Keep an eye on the server with logwatch, which sifts through the system logs and emails reports.

sudo apt install logwatch bsd-mailx

Create the cache directory:

sudo mkdir /var/cache/logwatch

Configuration file is /usr/share/logwatch/default.conf/logwatch.conf. Don't modify this file. Copy the file and make any changes there:

sudo cp /usr/share/logwatch/default.conf/logwatch.conf /etc/logwatch/conf/logwatch.conf

The only setting I change is Output, which by default is set to stdout. I change this to mail:

Output = mail

Test to stdout:

sudo logwatch --detail Low --output stdout --range today

A daily cron job is placed in /etc/cron.daily/00logwatch, which emails a daily report of yesterday's activity to root, which is forwarded to my username.

Read the reports by running:

mail

2.7 Process viewer

The top command displays Linux processes, and one of the first packages I install on a fresh install of Linux is the enhanced, interactive htop viewer. Looks good and easy to use: see CPU and MEMORY usage at a glance, system load and uptime, kill wonky processes, and more!

sudo apt install htop

Link: A Guide to the htop command in Linux

3. Laptop configuration

3.1 Turn off backlight

Install vbetool to control the laptop's display backlight:

sudo apt install vbetool

Turn off the backlight with the command:

sudo vbetool dpms off

3.2 Disable suspend-on-close

In normal operation, closing the laptop lid would suspend the system. Not what we want for our laptop home server!

To enable the server to continue operating on lid closure, set /etc/systemd/logind.conf to ignore the action, changing:

#HandleLidSwitch=suspend

...to...

HandleLidSwitch=ignore

Restart systemd-logind.service:

sudo systemctl restart systemd-logind.service

Note: I keep my laptop lid open. I've noted the machine runs a bit cooler by dissipating heat through the keyboard.

3.3 Battery

Current wisdom holds that for a laptop connected to AC power 100% of the time, its a good idea to set the battery charge "ceiling" to less than 100% in order to extend the health and lifespan of the battery. Read more

4. Services

4.1 Automatic daily backups

A backup you don't have to think about is a backup that gets done. Read more

4.2 RSS reader

Newsboat is an RSS feed reader that runs in a console.

sudo apt install newsboat

Run program (and leave running inside tmux):

newsboat

Create a list of feeds to track in ~/.newsboat/urls. A few items to add to this file:

  • Generate a combined list of unread posts from all feeds:
"query:Unread Articles:unread = \"yes\""
  • Reddit feeds can be created by copying the URL and adding .rss; give a custom_name to a feed by adding "~<custom_name>". Example:
https://www.reddit.com/r/debian.rss "~r/debian"
  • To subscribe to a Youtube channel:
    1. Open a YT channel's VIDEOS page
    2. Use the browser's page source view option, and search for channelId and <string>, where <string> in this example is UCxQKHvKbmSzGMvUrVtJYnUA
    3. Add link https://www.youtube.com/feeds/videos.xml?channel_id=<string> to file. Example:
* https://www.youtube.com/feeds/videos.xml?channel_id=UCxQKHvKbmSzGMvUrVtJYnUA "~yt/LearnLinuxTv"

4.3 Dynamic DNS

My home server sits behind a router assigned a dynamic IP address by my Internet Service Provider (ISP).

If I want to remotely SSH into my server, I can use a Dynamic DNS (DDNS) service to create a domain name, automatically update the IP address whenever it changes, and redirect traffic to the new location.

I use the free DDNS service provided by Duck DNS, which permits the creation of up to five domains in the format <subdomain_name>.duckdns.org.

See the install instructions for setting up a cron job on the server that polls the external IP address assigned by the ISP, and notifies Duck DNS of the current address.

Use Network Address Translation (NAT) on the home router to setup port forwarding, which forwards traffic directed at one of the router's ports to the listening port on the home server.

5. Resources

  • Debian Reference
    • Broad overview of system administration for non-developers.
  • Debian Package Tracker
    • A searchable interface that packs a lot of information about a given package on a single page.
  • The Debian Administrator's Handbook by RaphaĆ«l Hertzog and Roland Mas
    • In-depth guide to becoming a Debian power-user/sysadmin. Read online or download the ebook.
  • Mastering Ubuntu Server - Fourth Edition by Jay LaCroix
    • Except for the mention of a few Ubuntu-specific items, this excellent guide is equally relevant to putting together a Debian server.
  • The Linux Command Line
    • Command line use, programs, and shell scripting. Free ebook download.
  • Learn Linux TV
    • YouTube channel with Linux tutorials, reviews, etc. Produced by the author of Mastering Ubuntu Server.
  • ArchWiki
    • Written with Arch Linux in mind, but contains many excellent HOWTOs relevant to all Linux distros.

You can like, share, or comment on this post on Mastodon 💬

Thanks for reading! Read other posts?

« Previous: Set charging thresholds on Linux laptops to extend battery lifespans