Hosting Minecraft on Hyper-V in Windows 8.1 Pro

Just got a new computer which I hoped would be powerful enough to run both a Minecraft Server and the Minecraft game. And, turns out it is!

Managing servers and stuff tend to be easier in unix though, so I figured I’d try to run it in a virtual machine. First thought of VirtualBox, but then I stumbled upon the fact that Windows 8.1 Pro comes with a Hyper-V Platform built-in. Decided to check it out, and it works fantastic.

At least after I swapped out the virtual hard drive with the SSD from my old computer. Not sure if I set it up wrong, or if Minecraft just really don’t like being inside a virtual hard drive on a regular HDD…

Anyways, here’s what I’ve done for future reference in case I need to set it up again, or if anyone else would like to check it out. Depending on your comfort with command lines, unix, etc, you might need to use some google-fu. Or leave a comment, and I’ll try to help 🙂

Here’s what I use and try to cover here:

Add Hyper-V

  1. Go to Control Panel\Programs\Programs and Features.
  2. Click on Turn Windows features on or off, select the Hyper-V node and everything below it, hit OK and reboot (which I think it’ll ask you to do).

    Windows Features window

Setup Hyper-V

  1. Find the Hyper-V Manager.
    Searching for hyper-v

  2. And open it up for this fun stuff.
    Hyper-V Manager window

  3. Open Hyper-V Settings and change the default folders for Virtual Machines and Virtual Hard Disks (if you want them somewhere else).
  4. Open Virtual Switch Manager and create a new virtual switch of type external and make sure Allow management operating system to share this network adapter is checked. This will briefly cut your network connection, but it comes right back up. Also note that Windows uses slightly longer to connect to your network when booting up because this virtual thing has to boot up too.
    Virtual Switch Manager window

Setup the Virtual Machine

  1. Create a new Virtual Machine, choose Generation 1, at least 5 GB of non-dynamic startup memory, the Virtual Switch you created earlier and Attach a virtual hard disk later..
    (Tried to use 512 MB startup memory and the dynamic memory option, but got weird sporadic kernel hickups and after running the Minecraft Server for a while, it crashed because of lack of memory. Might have been doing it wrong 😛 )

  2. Open up the Settings of the VM.
  3. Make sure that BIOS has CD at the top of the Startup order.
  4. Set Number of virtual processors to 2, or whatever you want.
  5. Add a Hard Drive to IDE Controller 0 and select the Physical hard disk you want to use, which in my case was an unused SSD. Make sure to make the disk offline through Disk Management first, or it won’t show up in the dropdown list.
  6. Download the Ubuntu Server and set it as the Image file of the IDE Controller 1, which should already be a DVD Drive.
  7. Make sure Automatic Start Action is set to Automatically start if it was running when the service stopped, and Automatic Stop Action is set to Save the virtual machine state. This means you can safely restart your computer and your VM with your Minecraft server should come right back up where it was left off.
  8. Hit Ok, connect to the VM and start it up!
    Settings for VM

Install Ubuntu and stuff

  1. Install Ubuntu Server. Just follow the instructions and Google if you need help.
  2. Install Java and Screen.
    $ sudo apt-get install openjdk-7-jre-headless screen

Setup port forwarding

  1. Shut down the VM.
    $ sudo shutdown -h now
  2. Open the Settings for the VM again and go to Advanced Features under Network Adapter.
  3. Switch the MAC Address to Static and hit OK.
  4. Go to your router (or whatever functions as your DHCP server) and make sure the VM has a reserved IP (which is what we needed the static MAC address for)
  5. Forward whatever port you’re going to use for the Minecraft server to the VM, think default is 25565, and apply/reboot router as needed.
  6. If you haven’t already, you might also want to set up some sort of DDNS so your friends don’t need to deal with an unstable IP address when connecting to you from the outside.

Setup your Minecraft Server

  1. Either download the vanilla server, or create one through the ATLauncher and copy it to the VM through SFTP or something. I used the Yogscast Complete Pack and extracted it to /opt/minecraft/yogpack-<i>version</i>.
    Create Server in ATLauncher

  2. Adjust server.properties, ops.txt and white-list.txt as needed.
  3. Create launch.sh with, in the case of current Yogpack version, something like the following command. This will start the server in screen using the current directory name as screen name and giving it 5 GB of memory.
    screen -dmS ${PWD##*/} java -Xmx5G -XX:MaxPermSize=512M -jar cauldron-1.6.4-1.965.21.174-server.jar nogui
  4. Make launch.sh executable and start it up.
    $ chmod u+x launch.sh
    $ ./launch.sh
  5. See my Notes on Minecraft hosting post on how to connect to the screen and make sure it starts up all good. Also try to connect to it with your Minecraft client.

Setup minebackup.sh

  1. Install Git and Rsync.
    $ sudo apt-get install git rsync
  2. Get minebackup.sh, put it somewhere and make it executable.
    $ mkdir -p /opt/backup && cd /opt/backup
    $ git clone https://github.com/frdmn/minebackup.sh minebackup
    $ chmod +x minebackup.sh
    $ sudo ln -s /opt/backup/minebackup/minebackup.sh /usr/bin/minebackup
  3. Create ~/.minebackup.conf with something like the following.
    SCREENNAME="server"
    SERVERNAME="Minecraft Server"
    SERVERDIR="/opt/minecraft/yogpack-2.9.3.1"
    BACKUPDIR="/opt/backup/yogpack"
    FULLBACKUP="/opt/backup/yogpack.tar.tz"
    BACKUP_QUOTA_MiB=10000
    RDIFF_EXCLUDES=(server.log plugins/dynmap/web/tiles/)
  • Check that it works by triggering a backup manually and adjust config as needed if it doesn’t.
    $ minebackup backup
  • If it did, set up a cronjob to do it automatically by running crontab -e. The following will create an incremental backup every 15 minutes and a complete one every Monday at 5 in the morning.
    */15 * * * * /usr/bin/minebackup backup
    0 5 * * 1 /usr/bin/minebackup backup full

    And you’re done!

    Think that should be it anyways? There should now be a Minecraft server running on Hyper-V ready for fun. And it should be backing itself up in case of… not fun. And if you close the Virtual Machine Connection and the Hyper-V Manager, it should still be running in the background. Just reconnect later if you need to do something.

    Definitely room for improvement though:

    • The server doesn’t start up by itself with Ubuntu boots up, but since the VM “lives” through computer reboots that doesn’t really happen unless I make it. In which case I might as well start the Minecraft server too.
    • The backup covers anything going wrong with the server, griefing, et cetera, but the backup should really be going to a different hard drive, a cloud thing or whatever in case the whole VM and it’s drive explodes. Might be possible to change the minebackup.sh script to target an external somewhere and I might look into that at some point. I’ll blog if I do. And if you already have a good solution for this, please do leave a comment!
    • There’s no security, grief protection or anything on the Minecraft server in my case. So you might want to think about that. In my case I only give the address to people I know well and the white-list is a handy thing. With a backup every 15 minutes it should be fine either way 🙂

    Questions? Suggestions for improvements? Anything? Don’t be a stranger; leave a comment 🙂

    • Robert

      Nice tutorial! Have you taken a look at Turnkey Linux MIneOS? YOu can download the the iso and create a Hyper-v server with that disk pretty effortlessly. Might be worth a look!

      • Looked at it now. Getting the OS in was indeed pretty effortlessly. Getting an actual minecraft server up and running however seemed a bit more fiddly at first… especially the requirement for getting a server back through a URL. REALLY need an upload feature…

    • Sgt_Kick_Ur_Ass

      So the issue that you had with using a regular HDD vs an SSD. Was it that the server ran high tick time when someone connected? I am running on a hp dl380 g6 server with hyper v and running virtual machines. this is on 4 300gb 10k rpm SAS drives in raid 5. everything is set up perfectly and the server idles perfectly but when someone connects it runs the tick rate really high. I do run 8 different game servers on hyper v. but I have tested a base vanilla server without anything else running and it still runs high tick rate. I’m stumped. All my minecraft servers do this. I also have hyper v on my current desktop.

      • Been a while, but think just everything was super painfully slow. I didn’t try hosting anything else though, so might be something weird going on with minecraft, or maybe Java applications? Don’t really know 😕

        • Sgt_Kick_Ur_Ass

          When you mean painfully slow, I assume it was breaking a block and it not registering for like 3 seconds. That’s my issue. I’m pretty sure if you looked at the server then, that the tick time was probably higher. I’m trying to get them running good and if it comes down to the drives I will buy four new ssd’s or one to store the vm drives on. But I want to figure out if that’s the problem first. Not sure if it’s cpu lag between the vm and the host or hard disk or network. I’ve kinda ruled out network and a little bit rolled out cpu but not totally sure on the cpu. I assume since we are both using Hyper-V that it may also be hdd for me too even if they are 10k drives. I am on a SAS raid controller that’s directly connected to the motherboard but I don’t know if the sata controller is gonna be any better?