Raspberry Pi Minecraft Server Script With Startup Service 1.13

Minecraft Update Aquatic
Minecraft Update Aquatic

Based on the comments and feedback from my older guides I have added many requested features and fixes. It has changed so much since 1.12’s World of Color that my old guide is now obsolete and it’s time for the 1.13 Aquatic era update!

This script and guide are written to help you get a great performing Raspberry Pi Minecraft server up and running in only a few minutes.

I play on my server with 3-4 players on Survival mode without any difficulty on default settings (vanilla view distance of 10 and normal entity spawns/ranges). Above that number of players you will want to look into hardware with more memory but if you just want to play with a few friends it will be an excellent experience!

Features

  • Sets up fully operational Minecraft server in a couple of minutes
  • Installs OpenJDK 9 for ARM (supports G1, a much better garbage collector than Java 8 for ARM has)
  • Sets up Minecraft as a system service with option to autostart at boot
  • Automatic backups to minecraft/backups when server restarts
  • Updates automatically to the latest Minecraft server version when server is started
  • Optional daily restart of Pi using cron
  • Easy control of server with start.sh, stop.sh and restart.sh scripts
  • Optional configuration of video memory to 16MB (default 64MB) and overclocking MicroSD reader to 100Hz (default 50Hz) for maximum performance

Requirements

  • Raspberry Pi model with 1024MB of RAM. Basically a Raspberry Pi 2B or higher. (No Zero unfortunately, 512MB is not enough RAM to do this, I’ve tried!)
  • Raspbian Stretch Lite (No GUI, it eats up too much precious RAM!)
  • Solid state drive highly recommended but not required.
    You can get a SSD setup on a Pi for < $30. See my article here for details
  • If using MicroSD you want to be using a mid to high range card otherwise you will really be hurting on IO when the server is reading/writing chunks of terrain. Your card’s name should have lots of Pros/Ultras/Extremes in the title! Click here for MicroSD card benchmarks/recommendations.

Recommended Gear

Raspberry Pi 3B+ with 2.5A Power Supply

Sabrent USB 3.0 to SSD / 2.5-Inch SATA Adapter -AND- Kingston A400 SSD 120GB SATA 3 2.5” Solid State Drive

Or for a compact setup: SanDisk Extreme Pro USB Solid State Flash Drive

Installation

Install Raspbian Lite on your Pi first and then SSH into your Raspberry Pi and type/paste the following commands:

wget -O SetupMinecraft.sh https://raw.githubusercontent.com/TheRemote/RaspberryPiMinecraft/master/SetupMinecraft.sh
chmod +x SetupMinecraft.sh
./SetupMinecraft.sh

The script will setup the Minecraft sever and ask you some questions on how to configure it. I’ll explain here what they mean.

“Set clock speed to 100 MHz? Requires reboot. (y/n)?” – This will overclock your MicroSD card reader for you to 100 MHz giving you much faster read/writes on your server. Poor I/O is the #1 performance bottleneck so if you are going MicroSD we need to do all we can to mitigate that!

There are some cards (usually cheap ones) that can’t handle this overclock and will fail to boot afterward. If this happens don’t panic. You can simply reimage the MicroSD card or put it in your computer and go to /boot/config.txt and remove the line dtparam=sd_overclock=100 and save and it will boot right back up unharmed.

Most cards can handle the overclock fairly easily. If your card couldn’t do the overclock just run the script and say no when it asks to overclock. If you are using a SSD instead of MicroSD this setting will do nothing no matter what you pick.

“Change GPU shared memory to 16MB? Requires reboot. (y/n)?” – This is recommended for everyone. Since we are running a headless lite distribution we don’t need any more than the bare minimum of 16MB. That extra memory makes a gigantic difference when we are only working with 1GB total.

“Start Minecraft server at startup automatically (y/n)?” – This will set the Minecraft service to start automatically when your Pi boots. This is great because whenever you want to play you can just plug it in and go without having to SSH in.

“Automatically reboot Pi and update server at 4am daily (y/n)?” – This will add a cron job to the server that reboots the Pi every day at 4am. This is great because every time the server restarts it updates to the latest Minecraft server version as well. The Minecraft Paper server binary is updated every couple of days with bug and performance fixes.

That is it for the setup script. The server will finish configuring and start!

First Run

The first time you run the server it will take a little longer to start since it is generating all the server data. If you try to log in before it fully starts you will get a connection timeout error. Watch for the line: “Timings Reset”. This is the last line that prints when the server is ready to rock and roll. At this point you will be able to connect successfully.

The very first time you log into the server it will be slow for about 1-2 minutes. This is because since nobody has logged in before the server has to scramble to generate all the chunks within your view distance (10 by default) and send them to you/store them. During this time you may not be able to see very far and if you try to destroy blocks there will be noticeable lag from when they break to when they actually disappear.

Don’t panic! This will go away within a couple of minutes as the Pi catches up with all the first time login stuff it needs to do. Performance stabilizes and it will feel very much like the offline experience after that.

If you are hosting for a few friends I’d recommend logging in for the first time right after you set up the server instead of having several people nail a blank server at first startup. This gets it out of the way and when everyone is ready to log in the starting area chunks will be fully fleshed out and the Pi just has to read them. It’s an order of magnitude faster for the Pi to read chunks than to generate and store chunks.

In my experience after the initial login exploring new parts of the server doesn’t cause any lag even though new chunks are being generated. The reason for this is that when you’re walking it’s really only having to generate a new chunk as you get close to the border instead of a huge square area of chunks in all directions and all at the same time like during the first login.

Start, Stop and Restart Server

The server can be started, stopped and restarted two different ways. You can use the provided scripts in the Minecraft folder or you can use systemctl. Here are the commands:

cd ~/minecraft
./start.sh
./stop.sh
./restart.sh

-OR-

sudo systemctl start minecraft
sudo systemctl stop minecraft
sudo systemctl restart minecraft

Automatic Backups

The server backs up each time it starts. This helps you recover easily if something goes wrong. This system works best if you configured the server to restart daily since it means you will have a backup every day.

To access these backups type:

cd ~/minecraft/backups
ls

When a backup is made the filename will be the date and time the backup was taken. If you need to restore a backup it’s very easy. Substitute the timestamp in my example to the backup you want to roll back to. Type:

cd ~/minecraft
./stop.sh
rm -rf world world_nether world_the_end
tar -xf backups/2019.02.15.22.06.30.tar.gz
./start.sh

Your world has now been restored! It’s a good idea to download these backups off the Pi periodically just in case the Pi’s storage fails.

Updating the Scripts

The scripts can always be updated by downloading the latest SetupMinecraft.sh and running the installer again. It will update all of the scripts in the Minecraft directory and reinstall the startup service for you. This will not overwrite your world or any other data so it is safe to run!

Port Forwarding

If everyone on your server is on the same LAN or WiFi network as you then you don’t need to do this. If you want people to connect from outside your local network then you need to set up port forwarding on your router.

The process for this is different for every router so the best thing to do is just look at your router and find the model # and put that in google with port forwarding for easy instructions on how to do it for your specific router.

You want to forward port 25565. The type of connection is TCP if your router asks. Once you do this people will be able to connect to your Minecraft server through your public IP address. This is different than your local IP which is usually a 192.x.x.x or 10.x.x.x. If you don’t know what that is just go to google and type “what’s my ip” and Google will kindly tell you!

Wired vs. Wireless

Going with an ethernet (wired) connection is going to be faster and more reliable. There’s so much wireless traffic and other interference in the air that running your server on WiFi is not recommended.

Even if it is working great 99% of the time it can ruin your experience very quickly if the WiFi drops for a couple of seconds and you get blown up by a creeper!

All that being said, the server works fine on wireless. The script will work fine as is with a wireless connection.

Conclusion

OpenJDK 9’s new garbage collector has made running a server on the Raspberry Pi feel great! We can run at the default view distance of 10 with default entity settings.

If you have any feedback or suggestions let me know in the comment section. A lot of the new developments in this script were directly from comments to the older articles.

Have fun!

Comments 16

  • Hello! Thank you so much for making this guide! This helped so much! I was wondering though, do you know of a way to add plugins to the server and choose a map? I know there are other ways that include those options, but they didn’t work for me, and this was a lot simpler! Thank you so much for your help, have a nice day!

    • Hey Puppy,

      Glad you enjoyed the guide!

      The good news is that this server supports plugins. The server supports Spigot/Bukkit plugins. There’s tens of thousands of them! https://dev.bukkit.org/bukkit-plugins and https://www.spigotmc.org/resources/categories/bukkit.4/ are two good repositories of plugins. Installing these is pretty much as simple as downloading the plugin and extracting it to your ~/minecraft/plugins directory.

      As far as choosing maps there’s a few different ways to do it. The most popular way is by specifying a seed. If you browse Google for Minecraft 1.13 seeds you can get a bunch of them. To you use a seed you will go to the minecraft directory and edit server.properties by typing nano server.properties. In that file you will see a line that looks like seed=x. If you put the seed in here before you start your server it will generate that world from the seed! You can also use programs such as MCEdit to edit the world in a map editor and use that for your server.

      Let me know if you run into any trouble or have any more questions!

      -James

  • What a fantastic script, thank you.
    After the 1st reboot that followed on from things like overclocking the SD card, a server was up and running with the server output appearing on the screen and accepting commands as expected. The option to overclock the SD card, automatically run the server at startup and doing the reboot at 4am were all accepted.
    But after closing the Raspberry Pi 3B+ down after the next switch on I can’t see the server running and can’t find it to play. The IP address of 192.168.0.149 was checked, and I saw that about 15 seconds after the command prompt appeared, the cursor moved to the far left (instead of being after the $ sign), and “screen -r minecraft” failed to find a screen to resume.
    Running ./start.sh did start the server.
    I admit to installing the GUI then using raspi-config to boot to command only before doing the server installation. Is this the cause of the server not runing at bootup?

    • Hey Greenbandit,

      I downloaded Raspbian full to do some testing and found some problems in the script when ran on Raspbian full vs. the Lite version. This has to do with how the networking services start in full vs. lite.
      I have updated the scripts with several fixes thanks to your feedback. This will improve reliability on both versions. If you download the latest SetupMinecraft all the fixes are in there!

      -James

      • James,
        That has sorted it on my system. This is awesome.
        I can now install Raspbian (Full), then use raspi­config to get the Raspberry Pi to boot to command before running your setup script thus giving me the ability to go back to the desktop between minecraft sessions to edit files or whatever if I ever want to (because I am not that good at using the command line for the clever stuff). And the minecraft server now runs as intended after a reboot.
        Here’s an idea. My router is set to have a limited DHCP address range to leave room for fixed IPs on my LAN, so since I am aiming towards leaving the Pi on 24/7 for my boys I manually edited /etc/dhcp.conf to give eth0 & wlan0 a fixed IP address. Would it be worthwhile adding such an option to the setup script to ensure that the IP address doesn’t ever change? Since I didn’t setup my wifi during the initial Raspbian setup, the (commented out) wlan0 section in /etc/dhcp.conf was not created, but it did work when manually added.

  • Hi, when going through the setup, it always ends with “Setup is complete. Starting Minecraft server…” pauses for a few seconds, and then says
    “There is no screen to be resumed matching minecraft.” Any ideas?

  • “Setup is complete. Starting Minecraft server…
    There is no screen to be resumed matching minecraft.”
    Help! I have tried executing start.sh a couple times, but the server never seems to start. Any help is appreciated.

    • Hey Wyatt,

      Let’s find out! There’s two log files and one of them should tell us what is going wrong. Go ahead and do a
      cd ~/minecraft/logs and then do:
      nano latest.log

      The other log can be viewed by typing sudo journalctl -u minecraft. I don’t suspect you’ll see anything unusual in this one since it sounds like it is making it to the end of the start.sh script.

      Let’s see what it says in your latest.log file. Can you also post which Pi you are using?

      Thanks,
      -James

  • James,
    I remain grateful for your setup script.
    A RPi minecraft server received a lot of use last weekend from 4 LAN players and it has worked great. In contrast to a previous setup based on a vanilla server, this didn’t show signs of lag even with the view distance at the default 10 whereas the vanilla server needed the view distance at 6 to make it playable on the world we were using.
    But I’m puzzled why backups are not working. I can see the “mkdir backups” line in the setup script, but there was no backups directory until I manually created one. After a 4am reboot though, there is no backup visible to user=pi in /minecraft/backups. Is this my finger trouble? Out of interest, which part of the scripts is it that makes the backup?

    • Hey again Greenbanditz! I’m glad it’s working great on vanilla settings! That was my experience as well as before Java 9 came out I had to turn down the view distance and some other settings to get good performance.

      The backup is made in start.sh with this line:

      # Create backup
      echo “Backing up server (to minecraft/backups folder)”
      tar -pzvcf backups/$(date +%Y.%m.%d.%H.%M.%S).tar.gz world world_nether world_the_end

      Can you check your start.sh and make sure that it has this line? If you had updated from a previous version it may not have pulled it down from the github repository.

      If your start.sh is missing that line download the latest SetupMinecraft.sh which now will update all of the scripts in the Minecraft directory. This will get everything up to date!

      There is one other possibility. Did you change the world name of your world? It assumes that your folders are world, world_nether and world_the_end. If you have changed it I may need to add a line that reads from server.properties what the world name is so that if people are changing it then backups are still taken.

      -James

  • Hey James, this is great and I’m loving that I can host a server on my Pi instead of keeping my beefy PC running. Now my friend and I have a game we can play together, and he can log on whenever he likes.

    I’m using with the Lite version as recommended, but found that my server does not start automatically at startup anymore. I couldn’t find a file in the ~/minecraft directory where these settings would be – any advice? Should I just try reinstalling?

    • Hey Kieran,

      I have fixed this in the latest version. It broke due to a broken ca-certificates-java package in Raspbian. I’ve just added the capability for SetupMinecraft to update your scripts to the latest version without reinstalling.

      Simply do:
      cd ~
      rm SetupMinecraft.sh
      wget -O SetupMinecraft.sh https://raw.githubusercontent.com/TheRemote/RaspberryPiMinecraft/master/SetupMinecraft.sh
      chmod +x SetupMinecraft.sh
      ./SetupMinecraft.sh

      This will update all of the start/stop scripts to the latest version. It will also reinstall the startup service. If it is still having trouble we will dig a little deeper by checking ~/minecraft/logs/latest.log.

      Let me know how it goes!
      -James

      • You’re a legend, James! The server didn’t end up rebooting at 4AM, but that’s fine for me now because I don’t have to manually restart it myself at 4AM. I’ll keep it running and see what happens overnight to see if it restarts this time.

        • That’s awesome to hear Kieren, keep us posted!

          Make sure your Pi isn’t still set to the wrong time zone (I think the default time zone is the UK)

  • Hello James,
    I also suffer from the “There is no screen to be resumed matching minecraft”-problem. The server was running fine for some weeks and then stopped to work at all (after some stupid server “maintenance” . Never touch a running system…).
    I tried a new install on a blank SD-card and a fresh download of raspbian lite but there seems to be a problem with the installation of java. Again “… no screen …” but without a working java there will be no server running and therefore no screen to resume…
    I hope the java-issue will be fixed soon.
    You did a great job! Thank You! Without Your work I wouldn’t ever have set up a minecraft server on a RaspberryPi.

    • Hey Achim,

      I found the problem. It turns out there is a problem with the Raspbian ca-certificates-java package right now and it’s not installing correctly. Specifically it gives: Error: missing `client’ JVM at `/usr/lib/jvm/java-9-openjdk-armhf/lib/client/libjvm.so’.

      I have just committed a workaround to SetupMinecraft.sh. Do a:

      rm SetupMinecraft.sh
      wget -O SetupMinecraft.sh https://raw.githubusercontent.com/TheRemote/RaspberryPiMinecraft/master/SetupMinecraft.sh
      chmod +x SetupMinecraft.sh
      ./SetupMinecraft.sh

      and Java will now install correctly! The workaround specifically was a soft link from the client to the server JVM folder. The SetupMinecraft script now does this for you but the manual fix is:
      sudo ln -s /usr/lib/jvm/java-9-openjdk-armhf/lib/server /usr/lib/jvm/java-9-openjdk-armhf/lib/client
      sudo apt-get install openjdk-9-jre-headless -y

      Thanks for reporting the issue!

Leave a Reply

Your email address will not be published.