Difference between revisions of "User:CounterPillow/Quartz64 Minecraft Server Guide"

From PINE64
Jump to navigation Jump to search
Line 322: Line 322:
** '''Example:''' <code>man ls</code> shows the manual page for the <code>ls</code> command.
** '''Example:''' <code>man ls</code> shows the manual page for the <code>ls</code> command.
** Use this whenever you're not sure about a command's invocation. It'll be more accurate to your situation than what an internet search will tell you, and a lot less annoying to use.
** Use this whenever you're not sure about a command's invocation. It'll be more accurate to your situation than what an internet search will tell you, and a lot less annoying to use.
* <code>wget</code>: Download a file from the internet
** '''Example:''' <code>wget https://plebian.org/img/plebian-logo-white.svg</code> downloads Plebian's logo from its website.


{{hint|'''Useful Reminder:''' You can tab-complete a lot of things! For example, if you don't want to type out a whole directory name, hit tab once to complete it as far as possible, and hit tab twice to show the remaining options with how far you've completed it so far. Try typing <code>ls /u</code> and hitting tab, and you should have it complete to <code>ls /usr/</code>.}}
{{hint|'''Useful Reminder:''' You can tab-complete a lot of things! For example, if you don't want to type out a whole directory name, hit tab once to complete it as far as possible, and hit tab twice to show the remaining options with how far you've completed it so far. Try typing <code>ls /u</code> and hitting tab, and you should have it complete to <code>ls /usr/</code>.}}
=== Editing Text Files ===
For the rest of the guide, we'll be spending significant amounts of time editing text files. That's why it's good to familiarise yourself with a terminal text editor. The simplest to use of these is <code>nano</code>.
nano <var>foo</var>.txt
opens up nano, writing to the file <var>foo</var>.txt. We can save to the file with Ctrl+o, and quit nano with Ctrl+x.
A more advanced option is <code>vim</code>. You can run a lengthy interactive guide to using vim with the command <code>vimtutor</code>. Learning vim is a whole can of worms in of itself, so it's best to stick to nano if you're unsure.


== Troubleshooting ==
== Troubleshooting ==

Revision as of 05:40, 10 September 2023

Warning: This article is a work-in-progress and incomplete, if you came here from a search engine, turn back.

This guide details how to build and set up a small Minecraft (Java Edition) server on a Quartz64 Model B single board computer. The guide is intended to cover the basics in detail so that inexperienced users can follow it.

Note: If you have a 12+ year old child interested in computers and have some experience yourself, this could be a great guide to work through with them.

Introduction

Motivation

You may ask yourself why one would want to host a Minecraft server themselves instead of renting one. That is a valid question, and one big consideration is running cost. Buying the hardware and running the software yourself from your own internet access means that you're only paying a one-time cost (ignoring the minuscule power draw), whereas renting a server would usually incur a monthly fee. Since it's your server, you also have complete control over the software you run. Lastly, it's a great and fun way to learn about Linux system administration.

As for disadvantages, the server will only be as available as your home internet connection and electricity supply, and you yourself are responsible for keeping your system safe and up-to-date. The server is also not very high performance. It's best for a small group of friends, and not suitable for a public server that is likely to come under DDoS attacks.

In the below table, you can see a comparison between paying Microsoft for a realms server and self-hosting it according to this guide.

Minecraft Realms Self-Hosted
Setup Cost USD 0 USD ~130
Monthly Cost USD 7.99 USD 0
Modifications No Yes
Players 10 Uncapped
Availability Always Depends on you
Security Provided by Microsoft Your responsibility
Performance High Low
Full Shell Access No Yes
Teaches You Linux No Yes

Ignoring all points other than cost and assuming a USD 0.30/kWh rate for power with an average power draw of 3W for the board, the Quartz64 Model B as it is set up in this guide will have paid for itself in less than 18 months.

Game Plan

Let's get a high-level overview of what will be set up in this guide.

The goal is to have the base operating system (Debian Bookworm, using the Plebian images) installed on the microSD card. The Minecraft server itself will read and write its data from an NVMe M.2 SSD. The Minecraft server we'll use is PaperMC. We'll run it as a locked down systemd service. To make the server available to others on the internet, we'll use ddclient with DuckDNS to get ourselves a domain name for our (likely) dynamic IP, and forward the ports on the router.

Shopping List

Total cost: Around USD 130 excluding shipping.

From Pine Store

Note: When choosing "Courier Shipping" on Pine Store, you may unfortunately be charged additional import duties once the package arrives. How high these are depends on your jurisdiction, the order value and the courier Pine Store chooses.

From Elsewhere

  • A good 32GB microSD card for the operating system — USD ~15
    • SanDisk Max Endurance is a decent brand, Samsung EVO is fine too.
    • Even if the brand looks correct, buy from a reputable marketplace and seller: fakes are common! Double-check who's selling it to you on e.g. Amazon.
    • Avoid no-name cards, like the ones from Pine Store, or cards that aren't intended for longevity but maximum speed.
  • A TLC flash 500GB or higher capacity NVMe M.2 drive — USD ~35
    • Look at the SSD spreadsheet and pick a cheap one with TLC, and either DRAM or HMB
    • PCIe 3/4 doesn't matter, it'll run at one lane of PCIe 2 anyway
    • Decent usually cheap options: Kioxia Exceria, Patriot P300, Lexar NM620, WD Blue SN570
    • Avoid: Kingston NV1/NV2 (no cache, meaningfully slow here), anything with QLC flash (could be meaningfully slow here), anything SATA/AHCI (won't work), anything Aliexpress (fraud).
    • Shop around for deals and used drives! Just look up the manufacturer and model in the spreadsheet to verify that it's both TLC and has either DRAM or HMB cache. Bandwidth will be severely limited by the Quartz64's one lane of PCIe 2 here so paying a lot is not worth it.

Things You Hopefully Already Have

  • A microSD card reader (your laptop may have one built-in already), USB3 microSD card readers are cheap and useful.
  • An ethernet Cat5e or Cat6 or Cat6a cable (though technically you could run it on Wi-Fi)

Getting Started

Unbox your Quartz64 Model B. Carefully attach the U.2 wireless antenna (the little grey wire with the sticker on the end) to the antenna connector that can be found near the Wi-Fi chipset (the shiny metal square). If you do not need Wi-Fi, you can skip attaching the antenna. Now is a good time to stick on the tiny aluminium heatsink; remove the protective film on its bottom and stick it onto the black chip in the centre labelled "Rockchip".

Take the baseplate from your Acrylic Open Enclosure, the small screws, and the brass nuts. Insert the screws from below the base plate (top side is the one with the acrylic standoffs) through the standoffs. Place your Quartz64 Model B board on the standoffs such that the screw threads poke through its mounting holes, oriented such that the board ends up in the middle of the base plate; the standoffs are not centred on purpose, so orientation matters. Now, secure the board by fastening the four brass nuts onto the exposed screw threads.

Next, get the large screws and metal posts, as well as the top acrylic plate. Insert the large screws through the bigger outside holes of the base plate, and fasten the metal posts on the other side. Lay the top plate on the four metal posts, and fasten it down with the remaining four large screws.

Connect the board with an ethernet cable to your network, but do not hook up power yet.

Stick your microSD card into your SD card reader, then follow Plebian's official flashing instructions.

Once it's flashed successfully, stick the microSD with the black bottom facing upwards into the underside of the board, below the metallic Wi-Fi chipset. This can be fiddly to get in with the board mounted to the acrylic base plate. If you're unsure of where exactly the microSD connector on the Quartz64 Model B is, peer through the transparent bottom of the acrylic base plate.

Next, unbox the M.2 NVMe SSD, flip it around and stick it in right below where you mounted the SD card; it will awkwardly protrude from the side of the case, and the spring loading mechanism of the connector will push it against the acrylic bottom plate. As sketchy as this is, it should work, so long as you don't violently bump the protruding SSD.

First Contact

After you hook up the power supply to the barrel connector (important: not the audio jack, that would be bad), your board's LEDs should light up. After a couple dozen seconds, one of the LEDs should begin rhythmically blinking in a "heartbeat" like fashion. If the heartbeat pattern does not appear even after a minute or so, try hitting the little white switch closest to the antenna mount to reset the board. If it still doesn't appear after another minute, go to #Connecting UART.

Once you see the heartbeat pattern, you may now connect to the board over the network, using SSH.

Using SSH on Windows

Recent versions of Windows 10 and 11 have SSH as well as mDNS support built-in. Click on the start menu, search for the Command Prompt and open it.

Into the command prompt, type:

ssh pleb@plebian-quartz64b.local

if everything went well, it should prompt you with a host key question. Type "yes" to accept and remember the host key for future use. If the Command Prompt says ssh is not a recognised command, look at #Installing OpenSSH On Windows.

ssh will now ask you for a password for the user "pleb". Type in "pleb" as the password. You will then be prompted to change your password; change it to something secure, then log back in (with the same ssh command again, hit the up arrow to get the previous command from your history) with your new password.

Congratulations, you are now logged into your Quartz64 Model B.

Using SSH on Linux or BSD

Make sure the OpenSSH client is installed; how depends on your distribution. If your system is set up with an mDNS resolver such as Avahi or systemd-resolved with mDNS resolution enabled, you can open a terminal and type:

ssh pleb@plebian-quartz64b.local

if everything went well, it should prompt you with a host key question. Type "yes" to accept and remember the host key for future use.

ssh will now ask you for a password for the user "pleb". Type in "pleb" as the password. You will then be prompted to change your password; change it to something secure, then log back in (with the same ssh command again, hit the up arrow to get the previous command from your history) with your new password.

Congratulations, you are now logged into your Quartz64 Model B.

Using SSH on macOS

Open a terminal by clicking on the Launchpad icon in the Dock, typing Terminal in the search field and then clicking on Terminal.

Into the newly opened terminal, type:

ssh pleb@plebian-quartz64b.local

if everything went well, it should prompt you with a host key question. Type "yes" to accept and remember the host key for future use.

ssh will now ask you for a password for the user "pleb". Type in "pleb" as the password. You will then be prompted to change your password; change it to something secure, then log back in (with the same ssh command again, hit the up arrow to get the previous command from your history) with your new password.

Congratulations, you are now logged into your Quartz64 Model B.

First Steps

TODO: Validate this.

Changing The Hostname

First up, you may want to change the hostname the board uses. We can do this quite easily; in your ssh session with the board, type

sudo hostnamectl hostname yourhost

to change the hostname to yourhost. You will be prompted for your password.

Explanation: What we just did was run the hostnamectl command as the superuser with sudo. The superuser, or sometimes called the root user, is the ultimate administrator account on Unix-like systems such as Linux: it has access to everything, and should therefore be used with appropriate caution. By prefixing a command with sudo like this, we ask for it to be run as the superuser. The user "pleb" is allowed to use sudo in this way because it is in the necessary supplementary group.

After changing our hostname, a reboot is usually a good idea; type

sudo reboot

to reboot the board. To connect to it after doing this, you'll have to use the new hostname with the .local top-level domain, for example

ssh pleb@mcserver.local

if you set your hostname to "mcserver". You will be prompted to accept the host key again, only this time, it should tell you that it already knows the host by a different name.

Changing The Username

Being called a pleb isn't very nice, so we'll change this as well. In your ssh session, type:

sudo usermod -l yourname -md /home/yourname pleb

to update your username and home folder to yourname. Don't try to use spaces in your name and don't start your new username with a number. For example, if we wanted to rename the user pleb to greg, we would type:

sudo usermod -l greg -md /home/greg pleb
Explanation: The command usermod here is run with several arguments, each separated by space. The first argument, -l, signals that the next argument will be the new user name. What follows next in our example is "greg", which is the new username we chose.

Next is the argument -md. This is actually two arguments in one, and could be written instead as -m -d in usermod's case, though this depends on the command. -m tells the command to move our old home to our new home, and -d tells it that the next argument is the path of the new home directory. In this case, we chose "/home/greg/". This is the usual expected location for a home directory for a user called "greg", though it's not a strict requirement.

Finally, the last argument is a positional argument, which usermod expects to be the current username you wish to operate on.

Then, we should also rename the user group:

sudo groupmod -n yourname pleb
Explanation: Each user also has a "login group" they belong to, usually named the same as their username (though not necessarily so). To keep it consistent with your new username, we're renaming it with the groupmod command.

Finally, log out (by either typing logout or hitting Ctrl+d, and start a new ssh session with:

ssh yourname@yourhost.local

Your prompt should now show you your new name, and the command id -gn (no sudo!) should show you that your group has been renamed as well.

Getting Our Feet Wet

If you are already familiar with basic Linux/Unix usage from the command line, you can skip this section. However, to ensure nobody is left behind, this will be a quick crash course into how to do very basic things.

Where Are We?

There is a concept of a "current working directory". Any command we run assumes relative paths are relative to this working directory. We can show the current working directory with:

pwd

This should currently show your home directory.

Creating Directories

Using the mkdir command, we can create a new directory.

mkdir foo

would create a new directory called foo in our current working directory. That's because the argument we gave it is interpreted as a path relative to the current working directory, as it does not begin with a forward slash (/).

Changing The Current Working Directory

With the cd command, we can change our current working directory:

cd foo

we should now be in the directory foo; we can verify this by running pwd again:

pwd

This should output /home/yourname/foo.

If we want to ascend the directory hierarchy by one level, we can change to the path ".." to do so; ".." has a special meaning to be the parent directory:

cd ..

If you are ever in a hurry, you can run cd without any arguments to return to your home directory.

Further Explanation: Another special directory name is .: this refers to the current directory. For example, cd . would do nothing.

cd foo/./bar would be equivalent to cd foo/bar, and cd foo/../bar would be equivalent to cd bar (into foo, up one level, into bar).

Another path component with special meaning is ~. Our shell expands this to our user's home folder. cd ~ would be equivalent to cd with no arguments.

We can also give cd an absolute path. Absolute paths start with a forward slash, and the highest level directory is simply /, the root level directory. We can change your working directory to / with cd /, but be aware that we're not allowed to write any files or make any directories here.

Listing Directories

If we want to find out what's in our current directory, we can use the ls command:

ls

We can also give it a path as an argument to list the contents of that path instead:

ls /usr

This would list the contents of the system usr directory.

To get a more detailed list, including who owns the files and what their access rights are, we can use the -l argument to ls:

ls -l

By default, ls does not list files or directories starting with a dot (.). We can give it the -a argument to list those as well, including the special . (the folder itself being listed) and .. (its parent folder) directories:

ls -al
Further Explanation: Note that we once again were able to combine the two single-letter short options into one argument. ls -al is equivalent to ls -a -l or ls -l -a.

Creating (Empty) Files

To create empty files, we can use the touch command:

touch foo

would create a new empty file named foo in our current working directory.

Further Explanation: What touch actually does is update a file's last-modified time, and create the file if it doesn't already exist. Running touch on an already existing time would only update its last-modified time, and not alter the file contents in any way.

Deleting Things

To delete an empty directory, we can use the rmdir command:

rmdir foo

would remove the foo directory, but only if it's empty.

To remove a file, we can use the rm command:

touch foo
ls
rm foo
ls

This would create a file called foo, list the current working directory to show you that it's there, then remove the file, and then list the current working directory again.

rm can also remove things recursively, in this case it's able to remove directories. Be aware though that there is no undo, if you rm something near and dear to you, you better have had backups. In the following example, we'll create a directory, then create a file in it, then delete the directory recursively by passing rm the -r argument:

mkdir foo
touch foo/bar
ls foo
rm -r foo
ls

More Useful Commands

A short list of handy commands to know:

  • cp: Copy a file (or, when recursive, a whole directory)
    • Example: cp foo bar copies file "foo" to "bar".
    • Example: cp -R foo bar recursively copies the directory "foo" and its contents to "bar".
  • mv: Move/Rename a file or directory
    • Example: mv foo bar moves a file or directory "foo" to its new name "bar".
  • man: Show manual page for a command.
    • Example: man ls shows the manual page for the ls command.
    • Use this whenever you're not sure about a command's invocation. It'll be more accurate to your situation than what an internet search will tell you, and a lot less annoying to use.
  • wget: Download a file from the internet
Useful Reminder: You can tab-complete a lot of things! For example, if you don't want to type out a whole directory name, hit tab once to complete it as far as possible, and hit tab twice to show the remaining options with how far you've completed it so far. Try typing ls /u and hitting tab, and you should have it complete to ls /usr/.

Editing Text Files

For the rest of the guide, we'll be spending significant amounts of time editing text files. That's why it's good to familiarise yourself with a terminal text editor. The simplest to use of these is nano.

nano foo.txt

opens up nano, writing to the file foo.txt. We can save to the file with Ctrl+o, and quit nano with Ctrl+x.

A more advanced option is vim. You can run a lengthy interactive guide to using vim with the command vimtutor. Learning vim is a whole can of worms in of itself, so it's best to stick to nano if you're unsure.

Troubleshooting

This section contains various subsections for helping you troubleshoot problems you may have while following this guide.

Connecting UART

TODO: Write this.

Installing OpenSSH On Windows

On Windows 11, open the start menu, go to Settings > Apps > Optional features. If "OpenSSH Client" doesn't show up in your installed features, click on "View features" in "Add an optional feature" and search for "OpenSSH Client" and check it, then hit "Next" and "Install".