Server 101: A Digital Foundation
February 27, 2021
Excerpt: A simple set up that allows us to access our files and stream media from our PC, our phone, and wherever else we might want them. No one owns them but us. If anything goes wrong, it can be replaced easily. And most importantly, we’ll have control over our digital self in a way that it deserves.
We regularly create ‘psychic predators’, choosing to concentrate on the uncontrollability of events or concentrating on events we can’t control. A far better way of approaching this is to exercise our ‘psychic muscles’.
Table of Contents
This article follows on from our project on taking better care of our digital selves. As such, I will basically assume you’ve followed the previous steps to get here. But if not, the core premise is that you are now reasonably regularly backing up your files to an external harddrive or two, and you also have your files both on your computer and in the cloud. But, there are a number of problems with that solution, the most urgent of which are that we’d really like our backups to be automated, and we want to move off our reliance on the cloud.
Very shortly, we’re going to have a simple set up that allows us to access our files and stream media from our PC, our phone, and wherever else we might want them.
The obvious choice for such a thing is to set up another computer in the other room, and somehow get access to that from wherever we happen to be. This is the most basic definition of a server. A computer that serves information, in this case files.
No one will own our server (or our files) but us. If anything goes wrong, it can be replaced easily. And most importantly, we’ll have control over our digital self in a way that it deserves.
This is going to be a two part article, because while this will get us there and lay the foundation, there are several additional steps worth taking that will make the ‘access anywhere piece’ much, much easier. But, first things first: let’s lay the foundation.
When I was trying to work out where to start with a server, the first really useful idea I came across was this PiKeeper project.
The user, DarkHand had concerns that mirror ours:
large amounts of data…little cost…data redundancy
Helpfully, it’s exactly what we’re after as a backup solution with no frills. A cheap computer, with a couple of hard drives. Nothing fancy. DarkHand also offers something I didn’t even think of—portability. With this option, the actual computer we use as our server doesn’t matter at all. DarkHand sets things up so that not only are the files backed up, the harddrives can be removed and plugged into something else on a whim. This is not something you can do with most of the more complicated solutions, and it also means the external harddrives we already have are perfect for the job.
I won’t bother rehashing the project because DarkHand’s article is extremely comprehensive. I’ll simply point you to the thread. But I will detail the points that sold me on it before moving on to what we’ll need to do to get started:
- Frankly, if we’re taking our digital personhood seriously, we are going to have to learn how to use the family of operating systems called Linux at some point, for reasons I’ll detail in a moment. This project does that, but it also has a real focus on making everything work with Windows. As a transitional move, it’s fabulous. Linux, as I said, is a family of operating systems, like MacOS or Windows. But unlike MacOS or Windows, they’re usually completely free and usually really tiny, so we can run as many computers as we want on almost anything we want. Old slow computers? Yes. A USB stick? Yes. It’s also going to make life so much easier for us with particular reference to the likelihood of fucking things up. If we break a Linux machine, it’s extraordinarily easy to fix in comparison to other operating systems. This is because people who use Linux are fanatically helpful, and also because the various Linux operating systems are usually open source. Open source means the code is available online, and so absolutely anyone can solve our problems. We don’t need to go to the Genius Bar or email Windows support. Anyone with some time on their hands will have probably solved our problem for us already, and a quick search will bring up the answer to our problem. This PiKeeper project is a great entry point into using Linux.
- The PiKeeper project runs on a Raspberry Pi. These are super cheap, fully functional computers that run a Linux operating system. A Pi is cheaper than the harddrives we bought for our backups, in fact. The drawback is that they’re built on an architecture that’s a little unusual for computing. Most computers you think of as computers are X86. The Pi is ARM which for reference is used in a lot of phones. So occasionally we might run across computer programs that won’t install easily. But because Raspberry Pis are so popular, I’ve so far had no problem finding solutions online for this. I did this project first with a Raspberry Pi because I didn’t have a spare computer lying around, so anything you follow me into doing you’ll have a solution to.
- However, the great thing about Linux (and this project) is that the computer you use doesn’t matter at all. If you have an old laptop or something lying around, you can use that just as easily. Unlike a Raspberry Pi, these might not come with Linux installed, which means you run into another issue: how to install Linux. We will solve this. Again, we want to do this because it will make everything way easier. Eventually I did move on to an X86 computer, because the Pi has a couple of risks and annoyances I didn’t like (and I’ll detail) but mostly because I upgraded my laptop and I could use the old one. But since I wanted to start cheap, I started with a Pi.
Here’s what we need to do:
- Obtain a computer. We’re using Linux, so it can be super old and slow and it won’t matter. If you’re wondering what computer to buy, I’ll make a couple of recommendations here. If you have enough money, buy a Raspberry Pi that’s either the one DarkHand mentions in his PiKeeper project or newer. That way, you know you have a brand new, fully functioning computer that can do what we need it to do. If you can’t or don’t want to do that, you should be fine with any computer that at least matches the specs of the one DarkHand is using. If you want to have a bit of room for growth, you probably want about 4GB of RAM—that will be the rate-limiting factor for the things we want to do (we don’t really need to worry about CPU). The age of the computer isn’t going to matter much. I later moved on to a five-year-old laptop. You’d be amazed at how a computer that’s slow and crashes all the time with Windows suddenly works like new with Linux.
- We then need to get the operating system installed and working. I’ll detail two routes here: first set up steps specifically for a Raspberry Pi, and then we’ll move on to the more general steps for all computers.
- We’re then ready to tackle the PiKeeper project.
- We’ll stop there for this article, because at this point we already have a fully functional server and we should stop and congratulate ourselves. However, this is the first part of a two-part process, because there are additional steps we should take to make accessing and managing our server much, much easier. I’ll talk a little more about that at the end. I suggest you read both articles before getting started though, particularly the part in the next article about the VPN, because that will solve quite a number of issues you’ll encounter handily, with particular reference to getting the IP address of the server so you can connect to it from other computers.
Depending on how comfortable you are, feel free to skip to the point or points most relevant to you.
Using a Raspberry Pi for this project
First thing to do is to make sure you buy all the stuff for the Pi. If you just buy the computer, you’ll literally just be buying a board with electronics on it. Best thing to do is go to a computer store and ask or search online for this. I went into the local Raspberry Pi store. You need:
- the computer, which is just a tiny little board;
- you also need a power cable; and
- an operating system. I’m going to assume you bought a Pi from the Pi store, which means it has the Rasbian operating system pre-installed. If you need to install one on your Pi, you need to do that before we start. I’ll give a brief overview of that shortly.
That’s the bare minimum, but only buying those things will make the initial set up quite difficult. I’ll explain, since I was cheap enough to do just this. But you’d be better off if you also got:
- a case so it doesn’t get all dusty. I eventually did this because having just the exposed board freaked me out.
- you want to make sure you have internet access. The Pi4 has wireless and an ethernet port. If your Pi is an older model and doesn’t have wifi, you might want to get a USB wifi dongle. All models should have an ethernet port, so you can just buy an ethernet cable and plug it directly into the modem.
- You will make your life substantially easier if you source a keyboard, a mouse, a monitor, and the cables to attach those things. But, as long as you have some means of connecting the Pi to the internet (e.g. ethernet cable, native wifi or wifi dongle), you can manage without. In this latter case, you may eventually run across a problem that is easier to solve with a monitor. I was lucky in this regard, because I could pop into the Raspberry Pi store and use their equipment to troubleshoot a specific issue I had. If you can do the same thing with a friend or family member’s stuff, you should be ok to not get them—particularly because you can plug your harddrives directly into your computer if need be with the PiKeeper project. But like I said, things can get a lot more troublesome if you don’t have these on hand.
Everything you need is available on the Raspberry Pi store.
Putting an operating system (OS) on the Pi
I just bought the Pi from the Pi store, so it came preinstalled with the Rasbian operating system (a Linux OS for Raspberry Pi). I recommend this. But if maybe you have a second-hand Pi, or if you fuck up along the way (like I did) and the Pi isn’t working anymore, it’s handy to know how to get a fresh OS onto the Pi.
As such, if your plan is to go buy a brand-new Pi, with whatever accoutrements you want, you can skip this for now and go on either headless access if you’ve decided to make life hard for yourself by not securing access monitor/keyboard/mouse, or if you do have access to those things you can skip all the way to the general steps to setting a server up, perhaps briefly reading about how you might grow out of the Pi one day on the way.
Remember that the Linux OSes are mostly free, certainly the popular ones are, so getting your hands on one is as easy as going to the website and downloading it it.
The Pi uses a SD card as its storage medium. These are real cheap which is nice, but if you want to play with these you need an SD slot on your computer or an SD reader that can plug into a USB port. So get one of those first.
Now, once you can read SD cards on your computer, you can flash the SD card with Rasbian (or whatever OS). You can (and really should) just search ‘flashing an OS to an SD card’ to get some detail on this, but I’ll explain what this means briefly. You’re essentially overwriting the SD card with an ‘image’ of the operating system. Kind of like painting over a painting—you’re replacing whatever was on the SD card with the files that come with the OS and nothing else. Then you can just plug the SD card into the Pi and start again. It’s very easy, but the instructions will vary depending on what computer you’re using to flash the SD (e.g. Mac or PC), so I’ll leave you to search around a bit. I particularly suggest you use Raspian, since it’s designed for people who are new to this and are using a Pi, but feel free to get something else.
So, go do that.
Headless access (no monitor/keyboard)
If you’re foolishly cheap like me, you now need to set up your Pi for ‘headless’ access—that’s access without a monitor or ‘head’. This means that you won’t, at least initially, have access to a graphical user interface—you’ll be relying on the command line to operate your server. If that freaks you out, this might not be a good place to start and I wouldn’t necessarily recommend it. That said, in following along these tutorials, you’ll eventually have to learn to be comfortable in the command line and there really is no good starting place for that, so you may as well start at the start. That, at least, was my thinking. But seriously, this is not easy. You might want to wait until you can get access to a monitor and keyboard and skip to the set up steps.
What we’re going to do, is set up the Pi for access via SSH from the computer we’re trying to backup. SSH is a method of computer-to-computer communication, and it requires network access. As such, we need to set up our Pi to access the internet immediately upon startup. You can do this by plugging the Pi into the modem with an ethernet cable. Once plugged in, the Pi will sort the internet out when it boots. If you don’t have an ethernet cable and you’re trying to do this, you’re an idiot. I was also an idiot, so let me explain how this works in both cases.
What we need to do is set up networking before we boot up the Pi. We do this by editing the boot files on the SD card that is the Pi’s storage medium. As such, we need an SD card slot on our computer, or an SD card reader that we can plug into a USB port for this. Once we can do that, there are are couple steps to this:
- Enable SSH access. You can go here for instructions, or search ‘enable SSH on a headless Raspberry Pi’. But at the time of writing, this was as simple as placing a blank file called
ssh
(no extension) on the boot partitition of the SD card. - If you aren’t using ethernet, you need to set up wireless networking. Skip this step and go to the next one. If you are using ethernet, this is as simple as plugging the ethernet cable into the Pi and the modem.
- If you’re not using ethernet, you need to set up wireless networking. If you are using ethernet, make sure you’ve done the previous step and skip this step. You can go here for instructions, or search something like ‘wireless headless access to raspberry pi’. This will involve creating the wireless configuration file, called
wpa_supplicant.conf
and copying it onto the boot partition of the SD card. This is easier than it sounds, to start with I did it with my phone’s hotspot 1. - Access the Pi via SSH. Again, I’ll send you off with a link for instructions, or search something like ‘ssh headless access raspberry pi’. But in sum, you need to figure out the IP address of the Pi, then use an SSH client to SSH into the Pi using that IP address. I warn you, this IP address is going to be a problem, because without intervention it will change every now and then, so you’ll also want to assign the Pi a static IP address (so it doesn’t change). Search for how to do that. Alternatively, you can create a VPN network between your computer and the Pi using something like Tinc and access your Pi using the VPN IP address. We do this in the next article.Frankly, I never assigned a static IP address, and just went straight for the VPN. It was way easier in both the short and long term (even back when I didn’t really understand what a static IP address was or how to set up a VPN).
You might ‘grow out’ of the Pi
Eventually, you might want to start doing things with your server that aren’t part of this project. For example, streaming movies or music. The Pi, being a weird architecture, means that this could be more difficult because a particular program we want to use might not be built for Pi. As I said, this didn’t happen to me for a long, long time—the only thing I couldn’t install on the Pi was a mailserver, and that’s only because I wanted a very specific implementation. I’d suggest that by the time you’re ready to do weird stuff like that, you’ll be more than ready to upgrade. If you’re just going to be doing your backups and such, you might never feel the urge.
Another example of ‘growing out’ of the Pi, for me, came in trying to tackle this issue of silent corruption. Data can get corrupted for a lot of reasons, and if you’re like me, you’re not inclined to audit all your files personally all the time which makes you want to automate this process as much as possible. One source of silent corruption can come from memory errors. An excellent way to avoid memory-related corruption is to install some hardware called error-correcting checksum RAM. It’ll be a while before you come to care about this, if you’re starting where I started, but you can’t do this with Pi.
The long and the short of it is the Pi is perfect for just starting out, but keep in mind that at some point in the future, you might want to upgrade.
Choosing and installing an operating system
Now you need to pick a Linux operating system and install it. It would be pretty silly for me to write this up, because there are a thousand tutorials online. I’ll just make some general notes here.
- Many Linux distributions will allow you to try them out before you install them. This is called using a “live-usb” or “live-cd”. I recommend doing this, just to get a feel. I also recommend you do this and do one of the many Linux command line tutorials online while you’re at it, like this one from Ubuntu. In particular, learn how to mess with files, how to launch programs, and what a ‘super-user’ is. The good thing about these live-usbs is that they are temporary—you use them like you would if they were installed, but when you reboot, they go back to how they were before you messed with them. Have a little play now, with no risk of messing things up, because you’ll have to learn this stuff eventually.
- Since this is a server, and we aren’t going to be using this for day-to-day stuff, you don’t actually need an operating system with a graphical user interface. You can do everything from the command line. This opens you up to using operating systems designed for servers, like Ubuntu Server. Like I said you’ll eventually need to become familiar with the command line. Forcing yourself to start there by choosing a server OS like Ubuntu Server is an excellent way to learn. Immersion is the best way to learn any language.
- At a minimum, pick an OS with a lot of support. Linux has about a million different variants. The actual OS probably doesn’t matter so much as long as it’s a popular OS. The differences between the OSes aren’t going to be interesting to you until you’re already comfortable enough to swap OSes like dirty underwear. So Ubuntu Desktop or Ubuntu Server are both very popular. Debian (and Raspian if you’re on a Pi). Linux Mint. All of these have lots of support and when you go to search problems, there will be a lot of solutions.
- Many OSes release updates and new versions frequently. I’d recommend installing a version that has long term support (LTS). Since Linux distributions are usually free and open-source, they can’t fund support for every version for all time and versions without LTS are abandoned after a couple of years. You’ll therefore be forced to upgrade more often than if you choose an LTS release.
- Make sure you read a few different tutorials for installing the OS you’ve selected because some are more informative than others in regards to what the various set up options mean.
- Don’t stress too much. If you mess it up, you can just start again! That’s the beauty of what we’re doing here. It might take a while as you learn new things, but the whole point of doing this is so we can just swap out stuff that’s broken, messed up, lost or stolen.
- On a related note, when you are installing an operating system on a computer, you might spend time worrying about things like wiping the harddrive or creating partitions and such—thinking that perhaps you’d brick the computer by doing so, don’t worry. The BIOS of a computer is the thing that helps you install a new operating system, and the installation of the operating system is the thing that allows you to wipe your harddrive and such. The BIOS is stored in a chip on the motherboard, not on the harddrive, and even if you mess up the installation, you’ll still be able to get to the BIOS and therefore have another go at installing the operating system. You’d have to be doing some really weird stuff to mess up the BIOS. That said, read a few tutorials for installing your chosen operating system so you know what you’re doing. Read about how a BIOS works even. The last thing I need is people emailing me saying “I blindly followed the steps on some random website like you told me and now my computer is broken”.
General steps for setting up our server
So, we are going to loosely follow PiKeeper. As I said, I’m basically going to hand you off to that project because it’s great. But I’ll explain some of the key benefits, make a couple of general points and then we’ll actually go on and extend things slightly.
- I actually never bothered to get DarkHand’s samba solution working for file access. I jumped straight into the steps described in the follow up article to this one because I was having trouble with getting the IP address of my server. If you take the samba option, you will need to work out how to get your files synced to the cloud as your offsite backup. One solution would be to do what I eventually did and check out rclone, which allows you to sync from your server to most cloud services. I’ll write that up at some point. Alternatively, you might try using syncthing to sync a folder from your server to your computer and have the cloud sync the syncthing folder, although double syncing a folder sounds kind of dangerous to me.
- I also never bothered with the UPS or got the mailserver working, although I actually really think I should. Don’t be me and do those things.
- PiKeeper allows our external harddrives to be compatible with both Windows and Linux. I found that eventually I didn’t care about this anymore, but there was one occasion early on that my server crashed, and it was very nice to be able to plug my harddrive into a nearby PC so I could get at a file I needed without having to fix anything.
- PiKeeper will teach us a lot about harddrives, harddrive maintenance and files which, since we’re mainly doing this to back our files up, seems appropriate.
- It will also demonstrate just how incredible Linux is for the kinds of things Linux is commonly used for (like backup management, or other server tasks). For example, it introduces us to rsync and cron jobs, which are bloody fabulous things. Both of these programs are completely standard in the Linux world, but they quickly open up a realm of possibilities to you that you never thought possible using Windows—a clear example of how liberating Linux can be. cron is a tool that runs programs automatically, whenever you want (e.g. backing up your files every day). rsync is a program that can do a bunch of different kinds of file copying, one of which is to sync one folder with another folder by only copying new or changed data. With these two programs and a single line of code, you can have a daily backup completely automated. And because rsync can be told to just copy changes over, the backup takes seconds rather than minutes or hours to copy all the files across every time.
Also, there’s a little bit of a shift that we need to make conceptually which is the truly huge leap we’re making here, and the source of our digital freedom. The PiKeeper project has us put our files on an external harddrive connected to our server, and we merely access them from our computer. That means the source of truth for our files is no longer our computer, but rather the files connected to the server. While we might use our computer to manipulate our files, its role is no longer the one thing that does all of the things. Instead we have this kind of separation of concerns:
- one external harddrive contains our files;
- one external harddrive contains a backup of our files;
- the server itself allows access to our files;
- our computer is what we use to play with our files;
- together with the computer, the files in the cloud are also a kind of backup.
Now, we have this beautiful modularity. If our computer breaks or gets stolen, it’s annoying and probably expensive but we still have our files and the server. All we need to do is get a new computer connected to the server, and we’re back in business. If the harddrive fails with our files on it, we can turn to our backups to replace them. If our house burns down, we’ll need to get a new server and harrdrives, but with a little help from the cloud (or less conveniently, a harddrive at a friend’s house), it’s much less of a big deal than when our computer was the one thing that did all of the things. Our digital lives are far, far safer and we can rest a little easier.
However, there are a couple of ways we need to improve upon this, and there are two specific problems worth discussing. Let’s cover the problems first.
DarkHand has us install smartmontools
which is a fabulous disk utility that checks if your harddrives are failing. Unfortunately, if you’re using external harddrives like we are, and they’re plugged in via USB, smartmontools might be a little difficult to get working or might not work at all. The reason is complicated enough that I couldn’t be bothered working it out in detail. Something about how commands are communicated between the language that the harddrive speaks and translation via the USB port to the computer driver that manages such things. You can go off and read about it here, or search ‘smartmontools UAS SAT passthrough’. But essentially, some harddrive vendors don’t have drivers that work properly, Seagate being the worst offender. If your harddrives are one of these and the workarounds don’t help, you’ll need to rely on rules of thumb to know when to replace them and hope they don’t break down sooner. I will write about harddrives at some point for some pointers on replacements but in the meanwhile, go learn the difference between ssd and hdd harddrives, and then make sure to get one from a vendor that doesn’t have this problem.
The second problem is that ntfs3g, as set up in the PiKeeper project, will make all the files on your harddrive belong to the super-user no matter what. Even if you change the ownership of the files with chown. If you don’t know why that would be annoying, I suggest you go read up on the super-user, but briefly, it means that any program interacting with those files might have difficulties making changes to them unless the program has super-user privileges (and letting them have super-user privileges is not a great habit to get into). There are apparently ways to fix this problem, but I never managed to work out how.
The improvements are fairly simple:
- I’d like an offsite backup that is better than the cloud solution we have. I’m not going to address this now, because it’s not super important, but I will write this up at some point.
- We want to be able to access our server from anywhere. The current set up is a little awkward for that. The main issue is that if we aren’t home, it’s going to be pretty hard to get access to our files, primarily because your internet service provider will almost certainly change the IP address of your server, and that will cause you enormous pain. But also, the method of accessing our files using samba, while tried and true, isn’t a fabulous solution for our digital architecture. As such, the next item is to sort out access from anywhere. So you can go ahead and follow along that article.
I will make clear once again that I never actually bothered to get DarkHand’s samba solution working. I jumped straight into the solutions in the next article, so if you’re looking at how to integrate PiKeeper with our cloud solution from earlier, we haven’t done that yet! We’ve just laid the foundation. Either check out the next article, or you could just do what I eventually did and use rclone which allows you to sync files from your server to most cloud storage services. Alternatively, you might try using syncthing to sync a folder from your server to your computer and have the cloud sync the syncthing folder, although double syncing a folder sounds kind of dangerous to me.
But, if you want to stop, for now, we’re done! You’ve successfully moved into the Linux world, and in doing so, you’ve laid the foundation for your digital freedom. No one source of failure is going to tank your digital self, and you can build upon this foundation in incredible ways. As a teaser, I’d invite you to go checkout this huge list of completely free things you can do with a server.
I should point out that this isn’t always easy. The reason I used my hotspot, and eventually had to go into the Pi store to use a monitor was because I wanted to connect my Pi to an enterprise-level wifi network—eduroam. There was some issue with the version of the operating system I was using at the time and WPA2 enterprise wifi, which meant that I had to do make some substantial changes. Specifically, Raspian Buster was broken at some point for WPA2 enterprise—wpa_supplicant 2.8 was bugged with the broadcom-wl driver bundled with Buster. Here’s a link for that particular issue if you’re trying to use enterprise wifi and you can’t seem to connect (I ended up swapping the driver order). But if you’re just on a home network, it should be fine. ↩
Ideologies worth choosing at btrmt.