How to run loa in a vm

From Legends of Aria Admin and Modding Wiki
Jump to: navigation, search


How to run LoA in a VM (Virtual Machine)


As my first article on this Wiki, I want to share a few good practices about Virtual Machines.

Introduction

First topic will be about why we would want to run LoA, which is very demanding in resource, in a VM. Well, one objective is : keeping your project cheap. We'll try to keep it stable too, hopefully. Money is a big constraint to LoA community admins who would want to start running a server. One of the required specification, at my knowledge and through empiric experience, is having at least 128Gb RAM (of course, this depends on the number of maps you're running, and the number of dedicated server you use to run your cluster). Even running with Windows Server 2019 or 2016, with 64Gb RAM, has often lead my past servers to be unstable after several days of uptime, and especially while the playerbase was growing.

Moreover, running this on a server having an SSD is mandatory. An NVMe is also a good benefit and worth the bucks spent. I even tried an NVMe 3D XPoint, which was definitely faster, but way too expensive currently.

As concerning the CPU, I have sticked to Intel : i9 or Xeon, strangely CPU wasn't the main factor in stability. Having latest AMD Ryzen 9 or above wasn't really determining, and if choosing to pay for a Windows Server license, was inscreasing monthly fees. Although, try to have a minimum of 8 cores. we'll come back to this later.

I'll leave it up to you to define the hardware part that suits you best. The point of the article is mainly about software and what to use once you have your hardware chosen. Although, I thought I would share my own experience with the different attempts I made on that side, as it may be helpful in choosing a good dedicated server without spending too much on monthly fees. If running LoA in a Virtual Machine on a Linux machine is helpful in reducing monthly costs, I had to dedicate a few lines about how to choose the cheapest, but still working dedicated server for Legends of Aria.

I ended up (without naming brands) with a dedicated server at 64 EUR a month : 128Gb RAM, 2x 1Tb SSD NVMe and an Intel® Core™ i9-9900K Octa-Core. As a professional, I don't pay VAT, but you should be able to find a similar offer for such a "beast" nowadays.


So let's go straight to the object of this page : Running LoA in a Virtual Machine.

In a global perspective to reduce fees and encourage more of our fellow community admins to try/test/start their own server, I have come to the conclusion that running an LoA server is now possible on a Linux/VirtualBox configuration. You can do that on only one machine, as long as you take at least 128Gb RAM. You can also split your cluster on 2 servers with each 64Gb. As I mentioned it earlier, I base my numbers on 128Gb as I am using exactly the same maps as the official servers. If you're skilled enough to create your own maps or tweak with adding more maps, or using less than what is proposed by standard LoA, well I don't think you need to read this article. ;)

We'll take the assumption that you will not use your dedicated server for other projects, and we'll eagerly take all the resource from our HOST machine (Linux) to feed our GUEST machine (Windows 10 Vritual Machine). With some tweaking, it's possible to keep the Linux part for other projects, or even better it's possible to create other virtual machines, but it's not the point of this article.

Again, why choosing Windows 10 for running LoA as a server ? Fees again : a lot of people now have access to a digital Windows 10 Home licence, which allows them to install Windows 10 on 10 different machines. Wonderful ! That works on virtual machines too !

If by any chance you don't have a Win10 digital licence, you can purchase one in your Windows Store, directly from your compputer. Be sure to link it to your Microsoft Account (you just need to be connected to your Microsoft account while purchasing the licence). It's 150 bucks ! but it's a one time purchase, by opposition to the monthly fees for a Windows Server (which may go from 20 bucks to 70 bucks a month, depending on the number of cores you have).

Personally, as I have a Windows 365 E3 subscription, which offers a Windows 10 Enterprise licence, and the complete Office 365 suite.

Watch out though if you go for Windows 10 Home, as you will have to handle Windows Updates manually. If you don't, Windows 10 may restart any time during the day (or night), leaving your server down. You may configure autorestart and autologin, or simply a good practice is to check daily about new Windows Updates. They do that monthly now. And if you get updates pulled, plan a full server restart (only the Windows 10 part is needed, but you will have to coordinate that with your players).


1. Choose and install your Linux

I usually go with Debian. Ubuntu seems nice also to me, but I'll write this guide as a Debian user, being what I have in front of my eyes. Both Debian and Ubuntu are really close and share most commands. Other distributions like RedHat, Suze, ... are good too ! As long as you feel okay with them. Installing Linux is pretty simple and straightforward on most hosts. I've tried Hetzner and OVH. With both, you can install Linux in a few clicks. Just be sure to configure both your NVMe's in Raid 1 : mirroring. Some may choose Raid 0, but believe me I would never configure a server without a Raid 1 after I experienced a disk crash in January 2020 in one of my servers. It's just a plug & play to avoid dataloss (and coordination with the tech guys in the data center ...).


2. Setup an X

Well, in most cases, you will get a minimal version of Debian (or Ubuntu, or ...). It means : all you get is a terminal, just text, just commands, just like in the 80's in DOS :) We'll go the way to add an 'X', or a Desktop Environment : Gnome 3. It's way easier to deal with Windows 10 eventually. Once that one is installed, we'll also need a remote desktop app so we can display our 'windows in Linux'. For that purpose, we'll choose NoMachine. And we will also need Putty. Putty is used to connect to your Linux server in SSH. Basically, when things go wrong with the rest, connect there and type 'reboot'.


2.1 Download Putty and connect to your server

You can find Putty here : https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html When you launch Putty, you can enter your server's IP. Keep that one secret at all costs (basic protection rule^^). By default, you will use port 22, no need to enter anything unless you change SSH port later (another basic protection rule^^). A terminal will be open now, and you should read : 'Login as: '. Type 'root'. Hit enter and type your password (the one you received in your emails when the installation at Hetzner, OVH or other providers was finished). Don't be scared, when you type, nothing will appear (you'll love all the basic protection rules in Linux ^^), it's just so nobody in your back reads your root password. Notice we can't count the number of characters in your password either. Smart^^


2.2 Install GNOME

So you finally made it into Linux. Welcome to the real world ! :p Well, we probably want to install GNOME as we have some Microsoft needs later. Here are a few commands that are mandatory to remember. For more advanced configuration of Linux, I'll let you read other guides and tutorials.

- apt update : checks if there are updates available

- apt upgrade : install updates that were found

- apt install <package> : install a new package

- reboot : reboot your server

- su : gets into root mode (superuser)

- sudo <command> : runs a command as a superuser (without being logged as a root user)

- su -i : gets into root mode (by elevating your level)

- dpkg -i <debfile.deb> : installs a deb package (that you have probably just downloaded)

- wget <url> : download a file from the Internet

- df : check how much space is Free on your Disk

- nano <file> : edit a file in text mode

- mkdir <folder> : create a folder

- ls : list items in a folder

- cd : change directory


That should set a few cards in your hands. We probably won't need more commands as we'll end up in GNOME very soon. Although the linux this guide is written as if connected with your root user, it's recommanded to create a new user, add that user to sudo group, and then disabling access to root user. If you follow that safe way, don't forget to add 'sudo' before every command I write. Once you have enterered your sudo password (that you choose when you create the sudo user), you won't have to write it again unless you AFK or logout.


Before you install GNOME, be sure you are running on contrib non-free sources. Type in your terminal: 'nano /etc/apt/sources.list' You should find a line similar to this one: 'deb http://deb.debian.org/debian/ buster main non-free contrib' I think in Ubuntu it's : deb http://de.archive.ubuntu.com/ubuntu hirsute main restricted universe multiverse


If not, you can add the keyword 'non-free' and 'contrib' at the end of each similar lines. Hit ALT - X then Y and ENTER. Saved.


Then we'll check our packages and updates them if needed. Type 'apt update' and hit enter. Then 'upt upgrade' and validate.


Those two command are usually run one after the other, 'update' first, then 'upgrade'.


And then we can install GNOME : 'apt install gnome' That'll probably take more than 1Gb, so be sure to have a stable connection because we don't want to get disconnected while running Putty. If ever disconnected, just start again from 1. :p


2.3 Install NoMachine

Don't reboot yet ! We'll make sure you can connect from other computers to our new debian server with Gnome. Go inside a temp folder : 'mkdir /opt/tmp' and 'cd /opt/tmp' Then you can download NoMachine from their website: 'wget https://download.nomachine.com/download/7.4/Linux/nomachine_7.4.1_1_amd64.deb' (you can check here for newer versions : https://www.nomachine.com/download/linux&id=1 ) From the temp folder /opt/tmp, run this command : 'dpkg -i nomachine_7.4.1_1_amd64.deb'


That's about it for this part ! We can reboot our server using the command : 'reboot'. You'll get an error in Putty, because the connection is lost.


3. Connect to your Linux Server with NoMachine

Now you need NoMachine on your computer too, so you can connect to your server in a desktop environment. If you use Windows on your local machine, then check this page and install NoMachine for Windows : https://www.nomachine.com/download/download&id=8 A bit similar to Putty, you'll have to create a new connection here with your login and password. This time, we'll use port 4000 (NX). You may have to open a firewall on your dedicated server if you activated it, or if you had it from previous servers. This is done form the Customer Pannel on your host's website (OVH, Hetzner, ...).


Well, now you should be at a login screen !

Typically, we won't be able to login. That's another protection : root users can't login through NoMachine by default. Two choices : you go back into Putty and you create a user then add him to the sudo group (there are guides for that and it's really the way to go when you want to securize your server), or you go back into Putty and you tweak NoMachine so we can go through as root (for the sake of this guide lol). In any cases, we go back into Putty. Back at the black screen, do this : 'nano /usr/NX/etc/server.cfg' and look for this line with CTRL + W 'EnableAdministratorLogin 1'. You can activate it by uncommenting it (remove the dash).


Alright, let's try again NoMachine and connect to our server. Now if everything went fine, we're in our new Linux Debian with Gnome dedicated server.


4. Install VirtualBox from Oracle

Once we have this setup, usually, we should run a Linux project. We don't have that chance on LoA yet, but we can choose to either go with MONO Project, or a Virtual Machine. For this guide, I'll stick to a VM.


Once in your Debian, you will open a terminal (ah, you thought I would avoid you with that one :p). And run these commands :

apt update

apt upgrade

(always run these ones before installing new packages)


cd /opt/tmp

wget https://download.virtualbox.org/virtualbox/6.1.22/virtualbox-6.1_6.1.22-144080~Debian~buster_amd64.deb

wget https://download.virtualbox.org/virtualbox/6.1.22/Oracle_VM_VirtualBox_Extension_Pack-6.1.22.vbox-extpack


(by default, virtualbox isn't part of Debian Buster, so we have to add this to the list of repositories)


dpkg - i virtualbox-6.1_6.1.22-144080~Debian~buster_amd64.deb (finally update again our packages and install virtualbox)


You can now exit the terminal and find VirtualBox. Try to enter 'VM' in the search box ;) When it's launched, install the extension pack.


5. Create your Virtual Machine with Windows 10

5.1. 5. Create your Virtual Machine with Windows 10 ... + a few good practices on how to configure your VM

Well, from now it's pretty straightforward, so I will give less details on how to do things.


I previously covered how to acquire (legally, I insist !) a Windows 10 licence. It's either included in your Microsoft account as a digital licence (up to 10 machines), either you can buy one for 150 bucks, or you can get a Windows 365 E3 (or above) subscription which gives you access to full Office, Sharepoint, Visual Studio Pro (that one used to be included, at least, not sure it's still the case), a lot of other Microsoft apps and a Win10 Enterprise Licence. In any case, we'll just install a Windows 10 Home edition for this article, you will be able to fix the licence issue in the next 30 days after installation (you can imagine the advantage of having a VM, but I will hush on that point). Just a note about Win10 Enterprise, which will require a Win10 Pro licence so it can be upgraded to Win10 Enterprise. The upgrade is done during the installation of a professional version of Windows 10.


Now, you'll get yourself a copy of Windows 10. We use to type in Google : 'download Windows 10 ISO'. Well, type this in Goodle and you'll be suprised to end up on an official website from Microsoft. They allow anyone to CREATE an ISO file from their own computer. Good to know :) It's free, and after less than 30 minutes, you'll have an ISO file. Here's the page for downloading the media creation tool : https://www.microsoft.com/en-us/software-download/windows10 Go there, and click on the button 'Download Tool'. It's 100% legal.


So on your local computer, run the tool and choose as a media : ISO. It'll start from the settings on your computer.


You'll get a huge file ! Around 6Gb. And you will have to upload this to your Debian Server. So if you don't have fiber, come back later as usually, upload speeds are slow on most sides of our globe.


That will let me time to cover how to deal with the backups and downloads/uploads. There are several ways, but FTP stays the best imho. It SHOULD be included in your minimal debian, but as my debian is several years old, I'll give you the package to install. Go back to NoMachine, get to your Desktop, open a terminal, and run this : 'apt install vsftpd'. That's it (don't forget the twins apt update and apt upgrade before install vsftpd).


As an FTP Client, I use Filezilla. It's totally free. Kinda like Putty, you'll have to enter your IP, your login and password. Then you can reach the files on your Debian server from your local computer. So now you can start uploading the Windows10.iso file to your server. Try to find an easy folder for that. /opt/tmp seems like a nice one.


For backups, there are also multiples ways to do that. Easiest one : copy/paste your 'LoA Server' folder to a 'Backups' folder inside your VM, use 7zip to compress it into one file. It should be around 300Mb, including your mod, your logs and your saves. Later, we'll create a mapped folder so you can copy or move that file from inside the VM, to your debian server. Last step will be to download that backup file from your debian server to your local computer and put that in a safe location (again, rules for safe backups are multiple ... try to keep three copies in three places, you'll be fine in most cases ^^).


Let's say you have your ISO file on your debian server now !


Good ! But we won't use it now. ;)


Check this page, again from official Microsoft dev websites : https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/


And download directly a Virtual Machine with Windows 10 Enterprise in development environment. Choose VirtualBox. That's a huge file ! 20Gb. So download that one from your server directly. You can surf from there with Firefox.


30 seconds later, yeah, you have your 20Gb downloaded. ^^ That file is an OVA file. It's not typically what you are used to if you ever tried building VM's. Open Virtual Appliance. To get that one inside Virtual Box. Click on 'File --> Import Appliance'. It's also pretty straightforward. Just install it and check it for the number of days you can use it : 90 days I think, maybe less depending on when you downloaded the 20Gb file :)


I think the key to having a stable VM under Linux is using that OVA file. It's configured in an optimal way, both by using the tricks we'll see in next point, but also how they installed Windows 10 Dev inside the VM.


Right ! Do you like this ? Well, even if 90 days is 3 months, it's not eternity. We sould think about your licence.


Then do this : First, log out from your Windows 10 session inside the Virtual Machine. At login screen, press SHIFT + Restart. Choose 'Troubleshoot --> Advanced Settings --> Startup Settings', and hit restart. You may try a few things there, but I think the best way is to wipe everything : when you get to choose safe mode or other options, just click in the sticky bar from VirtualBox and insert as a device our ISO file. If well coordinated, you should be able to 'Press any key to boot from CD or DVD ...'. I looked for that ANY key for years ! but eventually, just pressing something on your keyboard works and you'll get to the installation of your Windows 10 Home (or Pro).


I'll leave you there for configuring and installing Windows 10.


Last note on that part : why do we install Windows 10 Enterprise dev to wipe it afterwards ? Well, installing Windows 10 Home inside the preconfigured Virtual Machine will keep most of the settings for that VM. Also, the hard drive C:\ even if wiped, is using the best settings for the SATA controller. It also lets you 3 months to do tests and see if you can have a stable server that way. It's also perfect for Test Centers, which eventually get removed when the updates are in production.


5.2. ... + a few good practices on how to configure your VM

Okay well, these are not from me, mostly, as I'm pretty new to the world of VM's. Although, from all my reading and testings, I can confirm some of those tricks are improving speed and stability.


- Create a VM with a fixed hard disk

When you create a VM, it is rather recommended to create a fixed hard drive and not dynamically allocated.

This is because when using space on a dynamically allocated virtual hard drive, VirtualBox must support and adjust the 'storage space of the virtual machine, which leads to a decrease in performance.


- Install VirtualBox Guest Additions

VirtualBox Guest Additions is a add-on that we install on the virtual machine. It offers a better integration between the VM and the host. Finally it can also improve the performance and speed of the VM.


- Allocate more memory to the VM

You can add more RAM to the VM. The more memory it has, the faster it will be. Of course the amount depends on the amount of memory available on the host and therefore on its hardware configuration.


As we took 128Gb and we have no other projects running on our dedicated server, we can allocate 96Gb to the VM without any issues. A rule is to keep 16Gb for the host, so we could go a bit higher up to 110Gb. But in any cases, don't go in the red (the bar in VirtualBox for setting RAM values) as it may lead to the host becoming unstable. I think something between 96Gb and 105Gb is more than enough for LoA (even lower than that).


- Add Cores to Virtualized Processor

A processor has multiple cores (each core is like a separate processor) and has also hyperthreading, which makes each core work as if it were two cores. This allows calculations to be run in parallel.


Virtual box reccomends the maximum number of cores you use should be n-1 of your physical cores. Hyper-Threading does not count.


For Legends of Aria, in our current configuration, we need to go 'in the red' for the number of cores. Take the number of physical cores you have, in my case: 8 cores. Multiply by 2: 16. And remove 1. The key for a stable LoA community server running on a Virtual Machine is this, put the maximum of cores you can put on the VM, minus 1. I have tried this many many time. 4 cores it failed. 7 cores it failed. 8 cores it failed. 16 cores it worked ! 15 cores ... it worked also, so I kept it to 15. By this, I mean, when you press the button to launch your cluster from the web launcher (I haven't tried it yet with the new Python Launcher you can start locally), you can see all the maps becoming green, status for those maps changing from "Starting up" to "Accepting Users", until when all of them but 1 or 2 reaches "Accepting Users", the cluster crashes and drops to all maps turning red again. After studying that behavior multiple times inside the VM, if you don't go above your physical cores, e.g. 15 or 16 cores, the CPU runs at 100% for too long and the cluster controller looses contact with the web launcher. It may be not an issue with the local Python Launcher. It's certainly not an issue with a Windows Server 2019, as I've tested both on the same machine. But with this trick, we can reach a stable situation with a Virtual Machine : go above the number physical cores.

Here's a quote from stackoverflow.com I found that confirms that this practice can be done nowadays: " The Virtual Machine (the guest OS) at the end is a single process for the host and when you modify the number of CPU's in the Virtual Machine settings what they will do is change the number of threads that the process will have to emulate the other CPU's. (at least in VirtualBox) "

Acceleration, choose 'Hyper-V' for Windows guests. Mandatory.


- Activate paravirtualisation VT-x / AMD-V

Oracle VM VirtualBox provides paravirtualization interfaces to improve time accuracy and performance of guest operating systems.


- And a few Windows tricks that don't really depend on VM's

Add two SDD's : 1 for Data and 1 for SWAP. On your D: DATA, you'll install LoA server files On your E: SWAP, you'll establish your swap files. To do this : 'control pannel --> system --> advanced system settings --> (performances) settings --> (tab) advanced --> modify (phew!!). There, untick 'automatically managment from swap files for ...'. Choose your E: SWAP SSD and put the radio button to 'Size managed by the system'. Then click on 'Define'. It will ask you to restart Windows. Do so. That SWAP trick is important too as it reduces disks access, or at least spread it on 2 different drives : C: WINDOWS and E: SWAP. It's not an obligation, but running LoA on a separate SSD found my preference.


And this is it !


It works, and I'm pretty sure that wasn't possible a few years ago, and that it is now possible and may be slightly unstable still, but in the coming years, with CPU's becoming faster and more powerful, SSD's faster like the latest NVMe 3DX Point, and RAM ... becoming cheaper (64 bucks a month for a 128Gb server, just that was not possible when I started hosting an LoA server in 2019).

Feedback and improvement to this page are welcome ! I'll probably clean all the typos tomorrow.

Now, I want to see more LoA Community Servers ! ;)