How to Install CraftBukkit Minecraft Server on Raspberry Pi

First we need to Install Java.

sudo apt-get install openjdk-7-jre

Next lets create a CraftBukkit directory to store all the files.

mkdir ~/mc-bukkit
cd ~/mc-bukkit

And lets download CraftBukkit.

wget "http://dl.bukkit.org/downloads/craftbukkit/get/02389_1.6.4-R2.0/craftbukkit.jar" -O "craftbukkit.jar"

Now lets create a script that we can use to start the Server.

sudo vi /etc/init.d/mcstart.sh

Copy and paste the following text.

#! /bin/sh
# /etc/init.d/mcserver

### BEGIN INIT INFO
# Minecraft CraftBukkit Start script
### END INIT INFO

case "$1" in
  start)
    echo "Starting mcserver"
    MCDIR=$("/home/pi/craftbukkit")
    cd "$MCDIR"
    java -Xmx512M -jar craftbukkit.jar -o true &
;;
  stop)
    echo "Stopping mcserver"
    kill `pgrep mcserver`
    ;;
  *)
    echo "Usage: /etc/init.d/mcserver {start|stop}"
    exit 1
    ;;
esac
exit 0

Now lets make the file executable.

chmod +x mcstart.sh

And launch

sudo /etc/init.d/mcstart.sh

The first lunch will take a long time so be patient.

If you want to start CraftBukkit when your Pi boots up then run the following command.

sudo /etc/init.d/mcstart.sh start

Turn Your Raspberry Pi into a Wireless Hotspot

Goal:

The goal of this guide is to turn a Raspberry Pi into a wireless home/mobile router.

Equipment:

  1. Raspberry Pi with raspbian
  2. Wireless USB device.  The guide uses a Edimax Nano USB Wifi (EW-7811Un) adapter
  3. Ethernet cat5 cable to connect to the Internet

Lets get started.

Install the following packages.

sudo apt-get install hostapd dnsmasq iptables

Open up “/etc/network/interfaces” and add the following lines.  If there is a line for wlan0 you can comment it out with a “#”.

iface wlan0 inet static
address 192.168.42.17
netmask 255.255.255.0

Configure Hostapd

Edit the following file “/etc/default/hostapd” so it looks like this.

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Now edit the hostapd config file “/etc/hostapd/hostapd.conf” and configure the wireless access point.

interface=wlan0
driver=rtl871xdrv
bridge=br0
ssid=MC
channel=1
wmm_enabled=0
wpa=1
wpa_passphrase=min3cr@ft
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
auth_algs=1
macaddr_acl=0 

 Configure the DHCP Server

For the DHCP server we just need to add the following lines to “/etc/dnsmasq.conf”

interface=wlan0
dhcp-range=192.168.42.20,192.168.42.152,255.255.255.0,12h
dhcp-option=3,192.168.42.17

Configure Iptables

Now we need to set it up so the pi can forward traffic from wlan0 to eth0.

Edit “/etc/sysctl.conf” and uncomment the following line

net.ipv4.ip_forward=1

then execute

sysctl -p

Next create an iptables “config” file.

sudo touch /etc/network/if-up.d/router.sh
sudo chmod +x /etc/network/if-up.d/router.sh
sudo su -c "echo '/etc/network/if-up.d/router.sh' >> /etc/rc.local"

Add the following line to the file.

sudo iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
sudo iptables --append FORWARD --in-interface wlan0 -j ACCEPT

If you are using the same wireless adapter that is used in this guide then you will need to execute the following commands to replace the hostapd binary.  You can find more info here.

wget http://www.daveconroy.com/wp3/wp-content/uploads/2013/07/hostapd.zip
unzip hostapd.zip
sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.bak
sudo mv hostapd /usr/sbin/hostapd.edimax
sudo ln -sf /usr/sbin/hostapd.edimax /usr/sbin/hostapd
sudo chown root.root /usr/sbin/hostapd
sudo chmod 755 /usr/sbin/hostapd

That should do it. Plug in the Ethernet cable and reboot  your pi and you should be good to go.

Create an Image of a SD Card

The following command works on both OS X and Linux.  It creates an image from the SD card called raspi.img which you can later use to clone to another SD Card or just keep as a backup.  It is exceptionally useful for backing up a Raspberry Pi.

Replace “mmcblk0” with your SD cards name.  Take a look at this post if you need help finding the name.

sudo dd if=/dev/mmcblk0 of=~/raspi.img

Installing Raspbian on Raspberry Pi from the Linux Command Line

First download the Rasbian zip from here.

Unzip the zipped file.

unzip 2014-01-07-wheezy-raspbian.img

You need to find your sdcard name.  If you don’t now how to, take a look at this post.

Next format your card as Fat32.

Now write the image to the sdcard with the following command.  Replace the mmcblk0 part of “of=/dev/mmcblk0” with your drive name.

sudo dd if=~/2014-01-07-wheezy-raspbian.img of=/dev/mmcblk0 bs=4M

It will not display any information until it is finished, so be patience.

Once it is complete, eject it and plug it into your Raspberry Pi and boot it up.