Ubuntu VM

Guide for running my Linux game server VM's on my Windows 2019 HyperV Server

Guide for running my Linux game server VM's on my Windows 2019 HyperV Server

I am using my factorio server VM as an example in this guide to remind future me how to do things...

Source Reference

The setup is pretty standard with one major exception.

Beyond that, it's really no different from deploying any other VM.

Base Configuration

Ubunut Install quick notes:

Post Install Steps

sudo su
wget https://packages.microsoft.com/config/ubuntu/16.10/packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb
apt-get update
apt-get upgrade
apt-get autoremove && apt-get autoclean
apt-get install linux-virtual linux-tools-virtual linux-cloud-tools-virtual linux-image-extra-virtual 
apt-get install openssh-server htop iftop
#Update SSHD with our settings.  recommend changing the port number, enabling PubKeyAuth and removing PasswordAuth
sed -i -e 's/#Port 22/Port 222/g' -e 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/g' -e 's/#PasswordAuthentication no/PasswordAuthentication no/g' /etc/ssh/sshd_config 
service ssh start
ifconfig -a

Get the IP Address and Test SSH Connection with the account used to do the installation, use either console to continue

adduser steam
cd /home/steam
mkdir .ssh
cd .ssh
nano authorized_keys

Paste the SSH Key into the file, this can be the same key from the default account (git syncronized)

chmod 600 authorized_keys
chown steam:steam authorized_keys
chmod 700 /home/steam/.ssh
chown steam:steam /home/steam/.ssh
usermod -aG sudo steam

Test Steam SSH Now

Network Configuration Steps:

nano /etc/hostname
    ## update hostname as desired
nano /etc/hosts
    ##Add host names as required
    # <name>
    # <.>

We need to create the file in the next line and set it's network setting to diabled

nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
    network: {config: disabled}
# Clear out the existing netplan's
mv /etc/netplan/* /root
#Create a new netplan with the values we need for the network configuration
nano /etc/netplan/01-network-card.yaml
    #use the the number recorded earlier, remove the #, update the below and paste into the netplan
# network:
#  version: 2
#  renderer: networkd
#  ethernets:
#   eth0:
#    dhcp: false
#    addresses: [x.x.x.x/24]
#    gateway4: x.x.x.x
#    nameservers:
#     search: [search.domain]
#     addresses: [x.x.x.x,x.x.x.x]
netplan generate
netplan --debug apply
    #verify no issues
netplan apply
    #can use "ifconfig -a" or "ip a" to verify configuration
    #verify dns "systemd-resolve --status"

Steam Config

not needed for Factorio, but useful for other games

Login as the steam user

sudo apt-get isntall lib32gcc1
curl -sqL "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar zxvf -
    #login anonymously and verify installation files

Factorio Config

    ##Install Factorio using WinSCP, or curl, and review the mgmt script
cd /home/steam
    ##download the file, extract to install (gz = patch, xz = stable)
sudo tar -xzf factorio_headless_x64_0.16.51.tar.gz
# sudo tar -xJf factorio_headless_x64_0.16.51.tar.xz
sudo chown steam:steam factorio -R
    ##Copy the mgmt script, configure as required
nano /home/steam/factoriocmd.sh
    ##Install the SystemD file, configure the startup command
sudo nano /etc/systemd/system/factorio.service
sudo systemdctl daemon-reload
sudo systemdctl enable factorio.service

Network Config

Port Forward: 34197

Do Factorio Server Things

# GIST for factoriocmd.sh

# Don't forget the service

sudo /home/steam/factoriocmd.sh