Build your own datacenter with PXE and Alpine

Who needs docker when you can run old laptops as blade servers

I have recently developed a slight obsession over Alpine Linux. Everyone who had worked with Docker containers has probably read Alpine somewhere. Alpine Linux is so damn small and fast and by default it runs from RAM and is therefore perfect for docker containers or Rasberry Pis. Alpine has become my preffered image for Raspberry Pis because of its RAM disk root partition that only stores changes when you issue the lbu commit command and therefore doesnt corrupt SD cards when the Pi loses power.

The Homelab datacenter

Coffee table server

Just like every homelab enthusiast I love to play with hardware for fun and to learn more for my job as a sysadmin. I have experience with Windows Server and PXE booting but have never done that with linux. I started my carreer by running webservers on old ThinkPads with broken displays from under by bed and I always loved the idea of laptops as servers since they had UPS, display and keyboards builtin.

A new project was born.

The Goal: PXE booting Alpine with network or local storage, custom configs and optional GUI

Step 2: Setting up Server 1

Let's install all needed packages first, then create the folders we need to store our files.
If you already have a webserver running, you don't need lighttpd. Just make sure to point some web directory to /srv/pxe/

If you don't have a key in ~/.ssh/ you need to generate one with ``ssh-keygen``` before running the last line in the script above. This will enable you to log into your PXE booted images without a password.

Setting up NFS

We'll configure Server 1 to grant access to everyone on the local subnet (192.168.1.0/24 for me) because we're going to save the persistant data here for all devices that don't have their own harddrives.

Time for the first boot!

Awesome, we can now boot any device and get a shell! Also you should be able to ssh into this machine without needing a password (if you set up the SSH key in the beginning)

Let's make a default config

You could work with this setup but there are a few things that'll make your life a lot easier. One of them is to make a save script that saves the currently installed applications so you don't have to start with a blank image on every reboot.

On the pxe booted laptop first let's add the config folder to the fstab so if we save changes.

This should have created some tar-gz files in /config
These files are the overlay files that will be applied at boot to the file system. They include installed programs and everything in your /etc/ folder.
Since we set the gpxe-script up to already include the mac address in the request, you should now be able to save and reboot and have all programs installed when you reboot.

What to do next

If the device you booted up has a harddrive or USB storage, you can add that to your /etc/fstab and have local storage. For most programs it would work to just mount /var to a local or NFS device to save program data.

You can even network boot a whole desktop manager if you install it using this tutorial but don't forget to save (using the save command) every time you changed something in a /etc or installed a program.