How to Make A Minecraft Server With The Raspberry Pi Zero

When I first heard of the Raspberry Pi Zero, the smallest single-board computer in the Pi family, one of the first things I thought to use it for was a Minecraft server. Yes the specs are low, but perhaps with enough fine-tuning I could turn it into something usable, I thought.

Some initial research online didn’t give me much hope. All I could find were nay-sayers criticizing the relatively tiny amount of RAM (512MB) and the measly 1 GHz chip on the device. They certainly are tight restrictions, but with enough work the tiny Raspberry Pi Zero can do some amazing things – Including running a Minecraft server.

Well, with some caveats anyway.

The plan

Because of the device limitations I had to right away decide between two paths: A, use an older and lighter version of Minecraft or B, use a game mode of Minecraft that is inherently easier to run. I didn’t think the former would be very interesting so I opted to create a server focused on the game mode known as Skyblock.

A new Skyblock island

In Skyblock the player spawns on a little island with some basic supplies and is tasked with producing more resources and expanding their island. It lends itself to this task very well as there are hardly any blocks or entities to render, making it quite easy to run on low-end hardware. And though it probably hurt the performance some amount, I decided to use a plugin for this, ASkyBlock, instead of a custom world file. This allows for multiple players to easily create their own islands and interact.

Setting up the Raspberry Pi

Here are the parts I used:

  • Raspberry Pi Zero
  • Micro-SD card
  • 5V, 1000ma USB adapter
  • Micro-USB cable
  • Cheap micro-USB to ethernet adapter (the quality isn’t too important as our server will be quite small and won’t use much bandwidth)
  • Ethernet cable

Install Raspbian onto the SD card. Connect power and internet to the Pi, plug in the SD card and turn it on.

Next, enable SSH. This is the easiest way to interact with the Raspberry Pi. When that is done log in to the Pi using PuTTY on your PC.

Creating the server

I won’t go into too much detail on setting up a regular Minecraft (PaperMC) server, but these are generally the steps I took.

On your Windows machine, download and run BuildTools. You’ll need Git to do this.

Now download and run Spigot. I chose version 1.12.2 as it is in my opinion the perfect blend of being featured but not too new and difficult to run.

Finally, download and run PaperMC. You’ll run this instead of the Spigot jar file. Paper is a highly-performant Minecraft server that will really allow us to get the most out of our little Pi.

You can now create a .bat file to start the server with on your Windows machine. Boot up the server, accept the EULA, start it again, and it should load everything with no issues. You should be able to access the server in-game with the IP “localhost”.

You’ll spawn into a regular Minecraft world, but remember – We wanted to create a Skyblock game. So, I went into the server files and deleted the “world” folder, and replaced it with a map that was completely empty (a superflat world with just a layer of air). I built a little square for players to spawn on as well. Now we’re ready to set up ASkyBlock.

Configuring plugins

I used a variety of plugins to make the server:

Only ASkyBlock was really necessary, but the others did make my life a little easier.

The usage for ASkyBlock is pretty simple – When you spawn in to the server, type /island to create a new island for yourself. You also have the option to create two islands near each other for you and a friend to play on.

Now that we have the server set up, we need to make sure that it can also run on our comparatively anemic hardware. So, on to…

Optimizing!

performance monitoring with htop

The first things we should look at are the configuration files for the server. This won’t be running on regular hardware, so we need to dial some settings back a bit.

I used this really good article on Spigot server optimization to help me through this. I followed all of the steps that had either a Medium or High performance impact listed. One of the most impactful changes I made was to view-distance in Server.Properties, which I changed to a measly 3. This would be quite annoying in a regular Minecraft game, but shouldn’t bother anyone in Skyblock. I also set the maximum players to 5.

I also used the JVM startup flags linked in the article. I allotted exactly 400MB to the server task with the argument -Xmx400M. And here’s a good time to make the startup script (start.sh) that will be used in Raspbian!

You could add plugins made for optimizing performance like ClearLagg but I didn’t find the need.

Another thing we can do to squeeze a little more performance out of our Pi Zero is to overclock the CPU. It’s as simple as adding a few lines to a configuration file and restarting. Do this at your own risk! While it’s probably perfectly safe to overclock the Pi Zero as there’s so little current running through the thing, accept the fact that it may cause irreparable damage to the device. Do some research if you don’t feel comfortable.

I used this tutorial to overclock the Pi. I ran a benchmark before and after applying the changes and here’s what I got:

The command:

sysbench --test=cpu --cpu-max-prime=2000 run

Results (without overclock):

Test execution summary:
    total time:                          54.4052s
    total number of events:              10000
    total time taken by event execution: 54.3295
    per-request statistics:
         min:                                  2.47ms
         avg:                                  5.43ms
         max:                                 45.62ms
         approx.  95 percentile:              12.90ms

Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   54.3295/0.00

Results (with overclock):

Test execution summary:
    total time:                          48.6731s
    total number of events:              10000
    total time taken by event execution: 48.5755
    per-request statistics:
         min:                                  2.24ms
         avg:                                  4.86ms
         max:                                 22.65ms
         approx.  95 percentile:              12.61ms

Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   48.5755/0.00

I ran each test a few times, and consistently got roughly a ~10% increase in performance. I’d say that’s pretty decent for so little work.

Starting the server

Now that our Pi is prepped and our server configured, we are ready to run the Minecraft server for real.

Copy the entire server folder over to your Raspberry Pi. This is made easy with SSH which we set up earlier. We can use a program like WinSCP to log in to the Pi and transfer the files through the local network.

Now access the folder on your Pi with a PuTTY session. Locate the start.sh file you made earlier and run sudo bash start.sh to start the server. With some luck, the server should boot right up (though it might take a few minutes).

Your friends can join you by connecting to your IP. To get that to work though you’ll need configure your router to port forward Minecraft’s port, 25565, to the Raspberry Pi. If you own a domain name (like wordpress.com) you can connect it to your home’s IP so that people can use the domain instead of your IP.

Occasionally on startup the server will panic, thinking it has too little RAM. The error looks like this:

Exception in thread "main" java.lang.OutOfMemoryError
        at java.io.FileInputStream.readBytes(Native Method)
        at java.io.FileInputStream.read(FileInputStream.java:233)
        at com.destroystokyo.paperclip.Paperclip.getBytes(Paperclip.java:170)
        at com.destroystokyo.paperclip.Paperclip.checkJar(Paperclip.java:181)
        at com.destroystokyo.paperclip.Paperclip.run(Paperclip.java:67)
        at com.destroystokyo.paperclip.Main.main(Main.java:14)

You should be able to just run the command again to hopefully get past it.

Conclusion

Honestly, it’s not too bad. You won’t be able to have tens of players at a time but the server can definitely handle at least a few people. With just myself on the server it runs near flawlessly. The server sat at around 70% CPU usage most of the time. If you are hitting the CPU cap too often and need a greater boost you can go back to the configuration files and tighten the settings up even more.

Since resources are so tight I do recommend preparing for server crashes. You can do this by setting up a script that detects if the server is running and if not, restarts it. What’s even better is having this script start when the Pi is rebooted.

It’s frankly amazing that all of this can be done with a chip about the size of my thumb and a couple of attachments. And I think with this setup we haven’t made too many compromises that would inhibit a player’s enjoyment.

If you have one of these devices laying around, consider giving this project a try.

In a future project I will be doing something similar with an old phone, so stay tuned for that.

Thanks for reading!