Setup a Minecraft Server on your FreeNAS

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:

mkdir /mnt/Main/MinecraftServer
mkdir /mnt/Main/MinecraftServer/jail_root
mkdir /mnt/Main/MinecraftServer/FreeBSD

Now, we will change into the FreeBSD directory and download FreeBSD:

 cd /mnt/Main/MinecraftServer/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:

cd /mnt/Main/MinecraftServer/jail_root/etc
cp /etc/resolv.conf .
cp /etc/localtime .

mount -uw /

cd /conf/base/etc
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”.

AMD64 Java JRE
i386 Java JRE

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:

mkdir /mnt/Main/MinecraftServer/jail_root/usr/local/virtual_java/

mv /mnt/Main/diablo-jre-freebsd7.amd64.1.6.0.07.02.tbz /mnt/Main/MinecraftServer/jail_root/usr/local/virtual_java/

cd /mnt/Main/MinecraftServer

Now, change the apparent root to the jail_root directory, then update FreeBSD:

chroot jail_root freebsd-update fetch install

Run the jail:

chroot /mnt/Main/MinecraftServer/jail_root
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:

cd /usr/local/virtual_java
pkg_add -v /usr/local/virtual_java/diablo-jre-freebsd7.amd64.1.6.0.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:

su root
java

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:

mkdir /mnt/Main/server/
cd /mnt/Main/server/

In the /server folder, create craftbukkit.sh:

vi 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:

#!/bin/sh
BINDIR=$(dirname “$(readlink -fn “$0″)”)
cd “$BINDIR”
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:

./craftbukkit.sh

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:

chroot /mnt/Main/MinecraftServer/jail_root
set prompt=”Minecraft &> ”
cd /mnt/Main/server
./craftbukkit.sh

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!

Tagged , ,

41 thoughts on “Setup a Minecraft Server on your FreeNAS

  1. Joed says:

    I got some questions for you. I decide to make my old pc into a freenas box. I want to install java like this a run a minecraft server. The server i have running right now is using bukkit. I have all the plug-ins i want installed and all of that. Is there a way to keep all my files i have now and have it run of freenas box? or is it just a vanilla minecraft server?

    • Tapalla says:

      Joed,

      Yes, you can certainly run Bukkit as your server with your existing plugins & worlds. I’m actually running a Bukkit server that used to be on my Windows 7 PC which I moved to my FreeNAS box. Just copy your existing Bukkit files to the same directory as the “craftbukkit.sh” file on your FreeNAS (from this tutorial, that folder would be the “/mnt/Main/server” folder inside the jail).

      • joed says:

        Ok, thanks. Idk I debating whether to install ubuntu and install some apps to do the exact same things as free nas. Freenas just seem so hard to use. I looked at the website, and watch the videos, and I’m just unsure what to do. Well, freeNAS has all the features I want, ubuntu is, I think, easier to setup. And has more than just a server to it. But does take up and use more of the computers resouces. Let me tell you what I want to do and maybe you can help. I read this article on lifehacker.com, and they talked about either doing a home server with ubuntu or freenas. Home server being able to have bitorrent downloads, streaming media, and for me running a minecraft server. Which I also run off of windows 7.

      • Tapalla says:

        I went with FreeNAS because it is the best, free option out there for keeping my data integrity. I wanted a solution that would keep my media & files intact even after a hard drive failure. It was only soon after that I wanted to do more with my box, such as using it to host my Minecraft server. If you don’t care so much about losing your files to “bit rot” or hard drive failures, Ubuntu Server is definitely the way to go. As you said, Ubuntu it is much easier to setup for other capabilities such as BitTorrent downloads, media streaming, hosting a Minecraft server, etc. These *can* be done on FreeNAS, however at this stage of its development, you’ll spend more time trying to get it to work on FreeNAS than you would with Ubuntu. My data & media are first priority, so I stuck with FreeNAS. If that wasn’t the case, I would have switched to a different server OS, such as Ubuntu.

  2. Halorl says:

    Thanks for the guide. I followed it with no problems, until this part:

    cd /usr/local/virtual_java
    pkg_add -v /usr/local/virtual_java/diablo-jre-freebsd7.amd64.1.6.0.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

    On this part I cannot stay inside the chroot and execute these commands. When I try it says that no such file or directory exists. When I do it outside of the chroot, however, the commands execute fine.

  3. AlejoM says:

    I`m working on Freenas 8.3-RC1 and I already have a jail running which has Transmission and miniDLNA. does it work for my version of freenas? Can I run the default jail with this new configuration? can both jails run in parallel? thanks

  4. David says:

    Thank you for your very detailed write-up. However, as the prior poster noted I have had a lot of issues with utilizing the jail based on your instructions. Once i’ve CHROOT’d to the jail, I can’t see /mnt/MAIN/ to create the server folder, let alone to run the craftbukkit.sh script.

    Can you help? Thanks again!

  5. Clark Miller says:

    First of all, thanks so much for this guide! I am having some trouble though when I get to “cat base.?? | tar –unlink -xpzf – -C /mnt/Main/MinecraftServer/jail_root/”. I get a “cat:stdout: Broken pipe” error. Still very new to FreeNAS and FreeBSD. I am using FreeNAS 8.3.0.

  6. Craig says:

    Thanks for the guide but im getting an error at the cat base section.

    after excuting the cat base.?? section im getting “cat: stdout: Broken Pipe:

    ive checked that ive not mistyped anything, any ideas what im doing wrong

    thx

  7. Jørgen Bele says:

    Output: “cat base.?? | tar .unlink -xpzf . -C /mnt/Disk1/MinecraftServer/jail_root/”:

    Usage:
    List: tar -tf
    Extract: tar -xf
    Create: tar -cf [filenames…]
    Help: tar –help

    what to do???

    • Jens says:

      i ran the following to get it to work properly:
      cat base.?? | tar –unlink -xpzf – -C /mnt/Main/MinecraftServer/jail_root/
      notice the double – by unlink.

      Hope it helps.

  8. Minecraft says:

    I just could not go away your website before suggesting that I extremely loved the usual information
    a person provide for your guests? Is going to be back ceaselessly in order to investigate cross-check new posts

  9. anime says:

    Thank you for some other excellent post. The place else may just anyone get that type of information in such a perfect method of writing? I’ve a presentation next week, and I am on the search for such info.

  10. 86644 says:

    Hey there, my name is Thanh and I’m a fellow blogger out of Voorburg, Netherlands. I’m glad to see
    the work you’re doing on this site. Coming upon wordpress.com was refreshing and helpful in terms of writing and work. Keep up the good work guys: I’ve put you guys on my blogroll. I believe it will boost the appeal of my web site.

  11. inskpro says:

    Hello guys,
    thanks for the guide.
    But I have a problem on the cat base command.
    Here is a copy of my shell, i don’t know what I’m doing wrong.

    I type in:

    cat base.?? | tar –unlink -xpzf – -C
    /mnt/Asylum/MinecraftServer/jail_root/

    And get this error:

    Usage:
    List: tar -tf
    Extract: tar -xf
    Create: tar -cf [filenames…]
    Help: tar –help
    cat: stdout: Broken pipe

    I’ve checked the command again and again, i cannot see any fault in it.

    Would be great if anyone can help me.

    • RatherNotSay says:

      I had this problem as well. Others have already included their fix and the one I happened upon but it might not be clear because of a font problem as much as anything.

      cat base.?? | tar –unlink -xpzf – -C /mnt//MinecraftServer/jail_root/

      If you can’t see it because of the font you are using its:

      cat base.?? | tar unlink xpzf C /mnt//MinecraftServer/jail_root/

      A single hypen in front of unlink gets interpreted as -u which is like -r which is like -c which is create an archive and in conflict with the -x for extract from archive.

      The usage error is coming back because your command line is telling tar to create and extract the archive at the same time.

      • RatherNotSay says:

        My greater than and less than symbols got clipped from the post and the content inbetween.

        Here is another attempt at the correct command line:

        cat base.?? | tar hyphenhyphenunlink hyphenxpzf hyphenC /mnt/yourvolume/MinecraftServer/jail_root/

  12. Quizno says:

    cat base.?? | tar –unlink -xpzf – -C /mnt/Main/MinecraftServer/jail_root/
    ^That works for me.

    The broken links can be found here: http://www.freebsdfoundation.org/java/java16
    They’re outdated, but they’re the ones referenced in this guide.

    I got to the last part of this, and I’m stuck. Here were my roadblocks.

    When I ran:
    > chroot jail_root freebsd-update fetch install
    the shell stopped at “(END)” I wasn’t able to type anything, and everything said “done,” so I ctrl+z “suspended” and was able to keep going.

    The lines:
    > 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
    I had to execute outside of the jail, as they would not execute otherwise.

    While in the jail I also couldn’t excecute
    > mkdir /mnt/Main/server/
    > cd /mnt/Main/server/
    so I put them in the jail’s /mnt/ folder, under a folder I made called /mnt/mcserver
    (full path is “\mnt\MAIN\MinecraftServer\jail_root\mnt\mcserver”)

    > chmod -x ./craftbukkit.sh
    wouldn’t give me permission, so I ran
    > chmod 777 ./craftbukkit.sh
    instead.

    So now I’m at the last part, running ./craftbukkit.sh, and I’m getting the error:
    “Unable to access jarfile craftbukkit.jar”

    I’m running
    FreeNAS-8.3.1-RELEASE-p2-x86 (r12686+b770da6)
    which was released LONG after this post was made, but there’s NO OTHER TUTORIAL OUT THERE ON HOW TO DO THIS. Hope I helped some people, hope someone will help me!

    • dtm4lifebaby says:

      I just figured out how to successfully do this. By following your instructions, and doing some trial and error, i was able to get the server going. Did you figure it out, or would you like some help?

  13. dtm4lifebaby says:

    Well actually, I am at a point when I ssh into my server, run ./craftbukkit.sh, it will work, but when I disconnect from my ssh session, the minecraft server stops running. So now i need to figure out how to keep a constant connection going with the jail.

    • Quizno says:

      I decided to use Ubuntu 12.04 LTS instead of FreeNAS, gave me a bit more flexibility. The server works fine now, not sure if I’ll mess with it on FreeNAS in the future. Still want to know where I went wrong though!

      • dtm4lifebaby says:

        I used this for the craftbukkit.sh:

        #!/bin/sh
        BINDIR=$(dirname “$(readlink -fn “$0″)”)
        cd “$BINDIR”
        java -Xmx1024M -jar craftbukkit.jar -o true

        I got it from here: http://wiki.bukkit.org/Setting_up_a_server#Linux

        When you download the craftbukkit server jar and put it in the jail, all you need to to is rename the file to craftbukkit.jar. After I did that, I chroot the jail, located the craftbukkit.sh, and ran it, and it was able to run. I still cant figure out how to make it constantly run though. Right now, when I want to play on my server, I open up a terminal window, SSH to my server, chroot the jail and run it, and when I’m done, I shut it all down. I want the jail to run 24/7 without me having to start it up via ssh.

    • Tapalla says:

      For those who are having problems keeping their Minecraft server open even after closing their SSH connection…

      FreeNAS comes with “Tmux” installed. It is similar to the more widely used GNU Screen. You can use Tmux to create a 2nd, “persistent” terminal session which continues running in the background.

      Launch your Bukkit server in a Tmux session and it will stay alive even after you disconnect from the SSH connection.

      Read more about Tmux here: http://doc.freenas.org/index.php/Tmux

      • dtm4lifebaby says:

        YES! That did it! Thank you very much!

      • wow, thanks for that. Tmux is pretty awesome oO

        just setting up a minecraft server for some friends and suddenly i learned something awesome. thanks!

      • Daniel says:

        So..now I am trouble with 1.7 update. I am getting the “authentication servers are down” error and I believe it is because I need a JRE 7 .tbz update.

      • dtm4lifebaby says:

        Unfortunately since the release if MC 1.7, the diablo 1.7JRE does not exist causing issues to login. According to the web, they stopped making the diablo .tbz updates so now I am unable to launch the server successfully through the freebsd jail.

  14. Cody says:

    Whenever I ran: 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

    It installed multiple versions of FreeBSD that ended up being over 20g in size. Is this supposed to happen?

  15. Reta says:

    Ahaa, its good discussion about this piece of writing here at this weblog, I have read all that, so now me also commenting here.

  16. jk says:

    Has anyone attempted this using FreeNAS v9 64-bit?

  17. xargon666 says:

    I’m giving it a go on FreeNAS v9 64-bit

    I encountered an error running this also: 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

    I instead ran a directly targeted wget which downloaded the .txz for FreeBSD, then tried to run cat base.?? | tar –unlink -xpzf – -C /mnt/Main/MinecraftServer/jail_root/

    I see there are other comments here relating to faults with this above, will have to give it a try. As far as I can tell, so far so good. Just a matter of wrapping your head around it.

    • xargon666 says:

      Right, apolgies for text dump! So here is where I’m at so far:

      First I made the jail through thr WEBgui

      then made the extra directorys as indicated in the guide, and proceeded to download FreeBSD with the following command:

      wget -rnd ftp://ftp1.us.freebsd.org/pub/FreeBSD/releases/amd64/amd64/10.0-RELEASE

      This downloads a series of files, fairly sure that’s what I want, fingers crossed!
      Then I ran the following commands with no issue:

      cd /mnt/MainArray/jails/Cybertron/FreeBSD/

      cat base.txz | tar –unlink -xpzf – -C /mnt/MainArray/jails/Cybertron/jail_root/

      cd /mnt/MainArray/jails/Cybertron/jail_root/etc

      cp /etc/resolv.conf .

      cp /etc/localtime .

      mount -uw /

      cd /conf/base/etc

      cp -a /conf /mnt/MainArray/jails/Cybertron/jail_root/

      mount -t devfs devfs /mnt/MainArray/jails/Cybertron/jail_root/dev

      mkdir /mnt/MainArray/jails/Cybertron/jail_root/usr/local/virtual_java/

      mv /mnt/MainArray/Downloads/diablo-jre-freebsd7.amd64.1.6.0.07.02.tbz /mnt/MainArray/jails/Cybertron/jail_root/usr/local/virtual_java/

      cd /mnt/MainArray/jails/Cybertron/

      chroot jail_root freebsd-update fetch install

      chroot /mnt/MainArray/jails/Cybertron/jail_root
      set prompt=”Cybertron &> ”

      Everything is fine up until I try the chroot commands, where I get the following:

      [root@fileserver /mnt/MainArray/jails/Cybertron]# chroot jail_root freebsd-updat
      e fetch install
      Looking up update.FreeBSD.org mirrors… 5 mirrors found.
      Fetching public key from update5.freebsd.org… failed.
      Fetching public key from update6.freebsd.org… failed.
      Fetching public key from update2.freebsd.org… failed.
      Fetching public key from update3.freebsd.org… failed.
      Fetching public key from update4.freebsd.org… failed.
      No mirrors remaining, giving up.

      [root@fileserver /mnt/MainArray/jails/Cybertron]# chroot /mnt/MainArray/jails/Cybertron/jail_root
      chroot: /usr/local/bin/bash: No such file or directory

      I am not clear on exactly what I am doing here. The inner workings of FreeBSD are a mystery to me. I’m guessing that I have not installed something correctly somewhere along the way. I’m not 100% clear on what chroot does even 0_o

      Also when I try the pkg_add parts of the guide, it says that “pkg_add” is not installed. I gather I need to install this command(?) inside the chroot? I have managed to download pkg.txz but I am unsure on how to install it. Well, any help would be great, i’d love to see a working guide for the latest(?) FreeNAS!

  18. Chisomo Banzi says:

    Thanks for this tutorial. But the wget command where you get FreeBSD always comes up with an error. I made sure i had no typos but still. It says,

    wget: unable to resolve host address ‘_amd64_base’

    Please help because this is one of the only tutuorials out there, trust me i know. Thanks again.

  19. watch belle says:

    It’s awesome designed for me to have a site, which is helpful in favor of my knowledge.

    thanks admin

  20. kixty9 says:

    Reblogged this on Minecraft 18.

  21. Myra says:

    You share interesting things here. I think that your blog can go viral
    easily, but you must give it initial boost and i know how to do it, just search in google for –
    mundillo traffic increase go viral

  22. A reaction to a particularly stressful life event (a bereavement, divorce, or loss of
    job), and. Skincare is a major one that must not be overlooked.
    ” we become stressed out and before we know it, the day is over and we haven’t accomplished half of what we thought we needed to do.

Leave a reply to kixty9 Cancel reply