I was able to setup a Minecraft server on my FreeNAS box after several hours of Google’ing around. I am running FreeNAS-8.0.4 (this tutorial works for FreeNAS-8.2 as well) on a USB drive. FreeNAS reserves basically the entire drive for the operating system’s use—because of this, any changes you make to the server are lost after powering down or rebooting. Thus in order to install Java—which is needed to run your Minecraft server—we must setup a “jail” running FreeBSD onto your actual volume. A jail is basically an isolated chroot. Our FreeBSD jail is initiated at system bootup then runs in the background parallel with FreeNAS. Files in this jail are saved on your NAS to a folder from within the chroot jail.
This document will explain how to manually setup such a jail on your box. After setting up the jail, we will setup the Minecraft CraftBukkit server.
Let’s begin. First things first, access your FreeNAS terminal whether via SSH or locally.
Make sure to change all the commands below from Main, the name of my volume, to the name of yours.
We will name our jail MinecraftServer. Start off by creating the jail’s directories:
Now, we will change into the FreeBSD directory and download FreeBSD:
wget -rnd ftp://ftp1.us.freebsd.org/pub/FreeBSD/releases/`uname -m`/`uname -r | cut -d- -f1-2`/base/ `uname -r | cut -d- -f1-2`_`uname -m`_base
Note: If you see an error like “Resolving 8.2-release_i386_base (8.2-release_i386_base)… failed: hostname nor servname’ provided, or not known“, just disregard it.
Execute the following command
cat base.?? | tar –unlink -xpzf – -C /mnt/Main/MinecraftServer/jail_root/
Next, we need to copy over some of the FreeNAS configurations to the jail:
cp /etc/resolv.conf .
cp /etc/localtime .
mount -uw /
cp -a /conf /mnt/Main/MinecraftServer/jail_root
mount -t devfs devfs /mnt/Main/MinecraftServer/jail_root/dev
We need to download the Java JRE for FreeBSD. Depending on which version of FreeNAS you have installed download one of the files below from your PC browser, then save it onto your NAS. If you don’t remember which FreeNAS platform you have installed, go to the FreeNAS web interface then click on System > System Information. It should be listed under “Platform”.
After you saved the JRE into your FreeNAS, execute the commands below. These will move the .tbz file from /mnt/Main into the jail’s /mnt/Main/MinecraftServer/jail_root/usr/local/ directory:
mv /mnt/Main/diablo-jre-freebsd7.amd126.96.36.199.07.02.tbz /mnt/Main/MinecraftServer/jail_root/usr/local/virtual_java/
Now, change the apparent root to the jail_root directory, then update FreeBSD:
chroot jail_root freebsd-update fetch install
Run the jail:
set prompt=”MinecraftServer &> “
Download the packages needed to install and run Java JRE:
pkg_add -rv xtrans
pkg_add -rv xproto
pkg_add -rv xextproto
pkg_add -rv javavmwrapper
Install the Java JRE:
pkg_add -v /usr/local/virtual_java/diablo-jre-freebsd7.amd188.8.131.52.07.02.tbz
echo libz.so.4 libz.so.5 > /mnt/Main/MinecraftServer/jail_root/etc/libmap.conf
echo libz.so.4 libz.so.5 > /mnt/Main/MinecraftServer/jail_root/conf/base/etc/libmap.conf
echo libz.so.4 libz.so.5 > /etc/libmap.conf
Make sure you are root user then test to see if the java command runs:
If you see the Java help manual after typing java, the JRE should be installed at this point. Now we have what we need to run the Minecraft server.
Let’s setup the Minecraft server now. You should still be in the jail (if the terminal says “MinecraftServer &>”). While in the jail, create the Minecraft server folder in your volume:
In the /server folder, create craftbukkit.sh:
Copy the text below onto the clipboard, press “i” in the terminal to enter insert mode, then right-click to paste it in:
BINDIR=$(dirname “$(readlink -fn “$0″)”)
java -Xmx1024M -Xms1024M -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=2 -XX:+AggressiveOpts -jar craftbukkit.jar nogui
Type “:wq” to save and quit the text editor. Now, we need to Change permissions for craftbukkit.sh to make it executable:
chmod -x ./craftbukkit.sh
Start the server by running the script:
Make sure your router is forwarding port 25565 (TCP) to your FreeNAS server.
Congratulations, your Minecraft server is now running on your FreeNAS box! Whenever you want to launch your server, remember to enter the jail first before executing the craftbukkit.sh script by running the following commands:
set prompt=”Minecraft &> ”
Most of the jail setup I have done here was learned from: Install JDownloader In A FreeBSD Jail
If you have any questions or comments, please feel free to ping me in the Comments below!