Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 68 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save husjon/c5225997eb9798d38db9f2fca98891ef to your computer and use it in GitHub Desktop.
Save husjon/c5225997eb9798d38db9f2fca98891ef to your computer and use it in GitHub Desktop.
Script and Instructions to setup a Valheim Dedicated Server using Oracle Cloud Infrastructure

Table of Content

⚠️ Disclaimer ⚠️

This install script has now been updated with a configuration for box64 which has been tested to work for a few weeks and by different people using this guide.
If you have made any changes to the ~/.box64rc configuration file for the [valheim_server.x86_64] section, please remove it and run the setup script.
If you should experience any issues, please leave a comment.

This script / procedure for setting up a Valheim server on ARM is currently broken as of 7th of November 2023. (https://www.valheimgame.com/news/patch-0-217-28/)

This unfortunately also includes the rollback procedure. Check comments for any updates regarding this issue.

Credit

The original guide is from Reddit user That_Conversation_91 on r/Valheim.
Original post can be found here

Instructions

Note: For this guide a free account is required on the Oracle Cloud Infrastructure allowing us to spin up a server which is decently specced.

In this guide, we'll:

  • Set up a Virtual Machine using the Oracle Cloud Infrastructure, including firewall rules
  • Prepare and use SSH to connect to the Virtual Machine
  • Update the Operating System and install the Valheim Dedicated Server software
  • Finally we'll use Systemd to allow the server to run automatically.

If you have the knowledge of setting up a server on an alternative cloud provider or your own hardware you may skip ahead to Installing the Valheim Dedicated Server

Pre-requisite

Windows

To connect to the server in the section Connecting to the VM Instance we need to do some preparation.

  1. First of all we need an SSH client, namely Putty
  2. Head on over to https://www.putty.org/ and click on the Download PuTTY link
  3. Scroll down to Alternative binary files
    1. click on putty.exe (64-bit x86)
    2. next scroll down and you'll find puttygen click on puttygen.exe (64-bit x86)
  4. Open up puttygen
    1. Press Generate
    2. Copy the whole SSH key starting at ssh-rsa, we'll need this in the next section when Creating the VM Instance
    3. Press Save public key and save it to f.ex your Desktop
    4. Press Save private key and save it to f.ex your Desktop
      It will ask about password protecting the key, this isn't necessary for this setup.

Mac / Linux

Verify that we have a set of SSH key pairs

  1. Open a terminal
  2. Run the command ls -l ~/.ssh/.
    If you see the files id_rsa and id_rsa.pub, you can continue on with OCI (Oracle Cloud Infrastructure)
  3. If you did not see these files, you can run the command ssh-keygen -N '' -f ~/.ssh/id_rsa Now you can re-run the command from step 2 and you should see both files.

OCI (Oracle Cloud Infrastructure)

  1. Head on over to https://cloud.oracle.com/ to sign up for a free account.
    After logging in you will be shown a Get Started page.
    All subsequent section starts from Getting Started.

Creating the VM instance

  1. From the Getting Started dashboard, scroll down a bit and click the Create a VM instance
  2. On the right hand side of Image and shape click Edit
    1. Click Change image and choose a Canonical Ubuntu Minimal aarch64 and confirm with the Select image button.
      Note: make sure you select aarch64 which is aimed at ARM server
    2. Click Change shape and set the following:
      • Instance type: Virtual machine
      • Shape series: Ampere
      • Shape: VM.Standard.A1.Flex
      • OCPUs: 4
      • Memory: 24GB
  3. On the right hand side of Networking click Edit
    1. Select Create new virtual cloud network and leave the values as is.
  4. On the right hand side of Add SSH keys click Edit
    • If you're f.ex on Linux or Mac you can find your SSH keys under ~/.ssh/id_rsa.pub In this case you can select Upload public key files (.pub) then navigate to ~/.ssh/id_rsa.pub
    • For Windows, the SSH public key we copied in Pre-requisite for Windows can be pasted in by under Paste public keys
  5. Click Create.
    Note: If you get a warning about Out of Capacity, scroll up to the Placement section and try another Domain (AD 1, AD 2 or AD 3), and try again.
    This will take a couple of minutes while the instance is being provisioned / set up.
    While we wait for it we'll go back to the dashboard and set up the networking.
    Click on the ORACLE Cloud header or click here to go back to the Getting started page.

Configuring the Network and firewall rules

  1. At the top of the Getting started page, click on Dashboard
  2. Under Resource explorer, click Virtual Cloud Networks, then click the network (f.ex vcn-20221120-1500)
  3. On the left hand side, click on Security Lists, then the Default Security List for NETWORKNAME
  4. We will be creating a rule so that we can connect to the server from Valheim.
    1. Under Ingress Rules, click Add Ingress Rules:
      • Source Type: CIDR
      • Source CIDR: 0.0.0.0/0
      • IP Protocol: UDP
      • Source Port Range: All
      • Destination Port Range 2456-2459
  5. Click on the ORACLE Cloud header or click here to go back to the Getting started page.
  6. Navigate back to the Dashboard, under the Resource explorer click on Instances then the instance (f.ex instance-20221120-1503)
  7. On the right hand side you'll see Instance access, click Copy to the right of Public IP address, we need this in the next step.

Connecting to the VM Instance

The IP Address we copied in the previous step will be referenced here as IP_ADDRESS

Windows

  1. Start putty which we downloaded in Pre-requisite for Windows
  2. We'll configure the following parameters:
    • Host Name (or IP address): IP_ADDRESS
    • Port: 22
    • Saved Sessions: Valheim Server
    • Close window on exit: Never
    • Click Save
  3. Next in the navigation tree to the left go to Connection > SSH > Auth > Credentials
    1. Under Private key file for authentication click Browse... and navigate to the Private key we saved using puttygen
  4. Go back up in the navigation tree to Session and click Save
  5. Then click Open
  6. You should within a couple of seconds see a prompt along the lines of ubuntu@instance-20221120-1503:~$
  7. You're now good to go to Installing the Valheim Dedicated Server

Mac / Linux

  1. On Mac and Linux we already have an SSH client installed.
  2. Open up a terminal then execute ssh ubuntu@IP_ADDRESS
  3. You should within a couple of seconds see a prompt along the lines of ubuntu@instance-20221120-1503:~$
  4. You're now good to go to Installing the Valheim Dedicated Server

Installing the Valheim Dedicated Server

  1. Run the following command:

    wget https://gist.githubusercontent.com/husjon/c5225997eb9798d38db9f2fca98891ef/raw/setup_valheim_server.sh
    

    This will download the installation script onto your server allowing it to set up everything which is needed.

  2. Then run the following command:

    bash ./setup_valheim_server.sh

    The first time this is run, the setup script will update the operating system and then reboot. If you get notification about kernel upgrades, or restarting services you may just press Enter, allowing the default values be. After it's done you will be disconnected, wait about 15-20 seconds then reconnect to the server.

  3. Run the same command again

    bash ./setup_valheim_server.sh

    Note: If you're playing on Console or Xbox Game Pass / Microsoft Game Pass, please enable Crossplay.
    Also, read the Crossplay section.

    The installation will take a couple of minutes to complete as the script installs all the necessary packages and set up the server with initial values.
    Once it finishes it let you know that we need to make a small edit to one file then start the server.

Configuring the Valheim Server

  1. Open up the server_credentials file with nano ~/server_credentials (or text editor of choice)
  2. Adjust the SERVER_NAME, WORLD_NAME PASSWORD, PUBLIC as you see fit.
    Note: The setup script populated the password field automatically with a random decently strong password.
  3. When done, Press Ctrl+X, then y and finally Enter.
    Note: Mac users might need to use the Cmd button instead of Ctrl

Starting the Valheim Server

To start the server, run the command valheim_server start
This will take a couple of minutes as the world is being generated.

From within the game, it might not show in the Select Server list, instead click the Add server button and type in the address IP_ADDRESS:2456 (Using the IP address fromConfiguring the Network and firewall rules)

More information can be found in the attached Readme.md file and can be viewed with cat ~/Readme.md

Updating the Valheim Server

Whenever the Valheim client updates, the server also needs to be updated.
To do this, log onto the VM then run the command valheim_server update
This will stop the running server and update the server files.
Once done, you must start the server using valheim_server update

Crossplay (Console / Game Pass)

Note: Crossplay on ARM architecture is currently experimental (thanks to @bitdo1).

During setup you will be asked if crossplay should be enabled or disabled.

If you'd like to enable / disable this after the first setup, you can change it by rerunning the setup script. You will need to restart the server for this to take effect using valheim_server restart

After crossplay has been enabled, the join procedure is the same as normal using IP:port, however you can now also join by using a 6 digit code which can be found in the logs after the server has started (using the valheim_server logs-live command).
Example log message:
Session "My Valheim server" with join code 295265 and IP 12.34.56.78:2456 is active with 0 player(s)

Note: Do keep in mind that the join code will change every time the server is restarted!

Modding

BepInEx currently do not support ARM, hence modding currently seem to not be possible.
If this changes in the future, this section will be updated to reflect that.
An issue has been raised with BepInEx and can be found here BepInEx/BepInEx#336

PS: If you're willing to try to install mods on your ARM instance and are able to so successfully, please do let me know.

As for a guide to install mods, here is one.
https://www.youtube.com/watch?v=h2t9cSFidt0

Installer Self-update

The setup_valheim_server.sh now has a self-update feature which allow it to update itself and apply any bugfixes that should be necessary whenever the script is run.

After updating, it will show what have changed, update itself, then ask the user to restart the setup script.
It is not retroactively applied, hence the script will need to be downloaded again f.ex with:

wget https://gist.github.com/husjon/c5225997eb9798d38db9f2fca98891ef/raw/setup_valheim_server.sh -O ~/setup_valheim_server.sh

This will overwrite the existing script.

This feature was added Thu, 15 Dec 2022 19:56:51 +0100.

Adding Pre-existing worlds

If you already have a world you've played on (f.ex hosted on your own computer) and you'd like to continue using it with this server,
the following steps can be used.

  1. Locate your save folder, navigate to this folder:
    The files we are interested in are the .db and .fwl files.
    • Windows: %userprofile%/AppData/LocalLow/IronGate/Valheim/Worlds
    • Linux: $HOME/.config/unity3d/IronGate/Valheim/worlds
  2. Stop the Valheim Server with valheim_server stop
  3. With an SFTP client (f.ex FileZilla), upload the .db and .fwl file to the folder: /home/${USER}/valheim_data
  4. Edit the ~/server_credentials and update the WORLD_NAME parameter to the name of your World files.
    F.ex if you world file was My_Valheim_World.db and My_Valheim_World.fwl, set it to WORLD_NAME="My_Valheim_World"
  5. Start the Valheim Server with valheim_server start
  6. Within a few moments the server should be back up and running with the world you uploaded.

Troubleshooting

In case you should experience any issues and would need some assistance, the install logs and server logs are helpful to troubleshoot the issue.

To help with this the following steps should be followed:

  1. Create a log output of the running server using the following command:
    journalctl --no-pager --since=-1d --user -u valheim_server > ~/valheim_server.systemd.log
    This will take a snapshot of the logs from the Valheim Server from the last 24 hours.
    In case the Valheim server was never started, this can be omitted.
  2. Download the install_valheim_server.log and valheim_server.systemd.log file located under /home/ubuntu using f.ex FileZilla.
    Note: Use port 22 for SFTP/SSH.
  3. Go to https://gist.github.com/, click Add File for each file, then Create Public / Secret Gist
    This creates a gist (similar to this guide) which we can go through to troubleshoot.
  4. Copy the URL to the gist and create a comment down below describing the issue and adding the link to the gist.

I might be delayed due to work / timezones etc, but hoping to get you going as quickly as possible.

Changing versions

This could be useful in case the public version breaks something. Make sure you create a backup of the server before switching versions.

Switcing to the Previous Stable Version

  1. Run SteamCMD to change to the default_old branch
cd ~/steamcmd

./steamcmd.sh \
    +@sSteamCmdForcePlatformType linux \
    +force_install_dir "/home/$USER/valheim_server" \
    +login anonymous \
    +app_update 896660 -beta default_old validate \
    +quit
  1. In Steam, right-click the game, open Properties, go to Betas and select default_old from the dropdown and wait for the game to update (this might take a few minutes).
  2. Start the game and connect to your server as normal.

Switching to the Public Beta Branch

  1. Run SteamCMD to change to the public-test branch
cd ~/steamcmd

./steamcmd.sh \
    +@sSteamCmdForcePlatformType linux \
    +force_install_dir "/home/$USER/valheim_server" \
    +login anonymous \
    +app_update 896660 -beta public-test -betapassword yesimadebackups validate \
    +quit
  1. In Steam, right-click the game, open Properties, go to Betas and select public-test from the dropdown and wait for the game to update (this might take a few minutes).
    If public-test is not in the list, type in yesimadebackups in the Input field below and press Check Code.
  2. Start the game and connect to your server as normal.

Reverting back to the public version

  1. Run SteamCMD to change to the public branch
cd ~/steamcmd

./steamcmd.sh \
    +@sSteamCmdForcePlatformType linux \
    +force_install_dir "/home/$USER/valheim_server" \
    +login anonymous \
    +app_update 896660 -beta public validate \
    +quit
  1. In Steam, right-click the game, open Properties, go to Betas and select None from the dropdown and wait for the game to update (this might take a few minutes).
  2. Start the game and connect to your server as normal.

Oracle and Reclamation of Idle Compute Instances

Oracle have a policy on their Always Free instances whichs allows them to reclaim instances that are idle or using less than a certain percentile (See: Always_Free_Resources).

For the most part using the server should not trigger this.

If the server should be flagged for reclaimation, you'll receive an email saying that it has been flagged for being idle for the last 7 days.
Next it will say that if it continues for another 7 days, the server will be stopped.
This gives us ample time to either back up the data or continue playing.

The only thing needed to do is to log onto your Oracle Cloid Infrastructure, go to your Instances and click the Restart button, this will pause the reclaimation.

TODOs

  • Add ability to update the Valheim server prior to starting the server.
    Tue, 24 Jan 2023 23:01:18 +0100
    Now part of the valheim_server helper command.

  • Add information about adding pre-existing worlds
    Tue, 24 Jan 2023 22:47:19 +0100

  • Add support for users other than ubuntu
    Tue, 24 Jan 2023 22:33:56 +0100
    Made it so that the install script no longer is tied to the ubuntu user.

#!/bin/bash
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
ORANGE=$(tput setaf 3)
BOLD=$(tput bold)
CLEAR=$(tput sgr0)
function warn { echo -en "\n\n${BOLD}${ORANGE}[-] $* ${CLEAR}\n"; }
function success { echo -en "${BOLD}${GREEN}[+] $* ${CLEAR}\n"; }
function info { echo -en "\n\n${BOLD}[ ] $* ${CLEAR}\n"; }
function error { echo -en "${BOLD}${RED}[!] $* ${CLEAR}\n"; }
function notify { echo -en "\n\n${BOLD}${ORANGE}[!] $* ${CLEAR}\n"; }
function perform_self_update {
SETUP_SCRIPT_URL="https://gist.github.com/husjon/c5225997eb9798d38db9f2fca98891ef/raw/setup_valheim_server.sh"
ETAG_CACHE="${HOME}/.cache/setup_valheim_server.etag"
SETUP_SCRIPT_PATH="$(realpath "$0")"
TEMP_SCRIPT_PATH="$(mktemp)"
info "Checking for setup script updates"
curl --silent --etag-save "${ETAG_CACHE}" --etag-compare "${ETAG_CACHE}" -L "${SETUP_SCRIPT_URL}" -o "${TEMP_SCRIPT_PATH}"
if [[ -s "${TEMP_SCRIPT_PATH}" ]]; then
if ! cmp --silent $SETUP_SCRIPT_PATH $TEMP_SCRIPT_PATH; then
echo "Setup script available, updating..."
notify "Changes (< = removed | > = added):"
diff --color --minimal "${SETUP_SCRIPT_PATH}" "${TEMP_SCRIPT_PATH}"
echo
sleep 1
mv "${TEMP_SCRIPT_PATH}" "${SETUP_SCRIPT_PATH}"
success "Updated setup script."
notify "Please re-run the setup script..."
echo
exit 0
fi
fi
success "No update available"
echo
rm -f "${TEMP_SCRIPT_PATH}"
}
function main {
# Stop on error
set -e
cd
while :; do
echo "This script will install the Valheim Dedicated server "
echo -n "Are you sure? [yes/no] "
read -r answer
case $answer in
YES|Yes|yes|y)
break;;
NO|No|no|n)
echo Aborting; exit;;
esac
done
echo
while :; do
echo "Should this server use crossplay?"
echo "Note: this is currenly highly experimental"
echo -n "[yes/no] (default: no) "
read -r answer
case $answer in
YES|Yes|yes|y)
CROSSPLAY_SUPPORT=true
break;;
NO|No|no|n|*)
CROSSPLAY_SUPPORT=false
break;;
esac
done
# Update and upgrade the system
mkdir -p ~/.cache
if [[ ! -f ~/.cache/valheim_server_setup ]]; then
info "First time setup"
info "Adding Architecture"
sudo apt -y update
sudo dpkg --add-architecture armhf
info "Updating and upgrading the OS"
sudo apt -y update
sudo apt -y upgrade && touch ~/.cache/valheim_server_setup
success "Updating and upgrading the OS - Done"
sudo reboot
warn "Rebooting..."
fi
# Prepare box86 and box64
info "Installing required packages"
sudo apt -y install \
build-essential \
cmake \
gcc-arm-linux-gnueabihf \
git \
libc6:armhf \
libncurses5:armhf \
libstdc++6:armhf \
libpulse0 && \
success "Installing required packages - Done"
if uname -p | grep "aarch64" > /dev/null; then
notify "Found system to be 64bit Arm"
# Fetch and build Box 86 and 64
for ARCH in {86,64}; do
cd
if [[ ! -d "$HOME/box${ARCH}" ]]; then
info "Fetching Box${ARCH}"
git clone "https://github.com/ptitSeb/box${ARCH}" && \
mkdir -p "box${ARCH}/build"
success "Fetching Box${ARCH} - Done"
fi
info "Building Box${ARCH}"
cd "$HOME/box${ARCH}/build"
git fetch
if [[ $ARCH == 64 ]] && [[ -n $BOX64_VERSION ]]; then
TAG="${BOX64_VERSION}"
elif [[ $ARCH == 86 ]] && [[ -n $BOX86_VERSION ]]; then
TAG="${BOX86_VERSION}"
else
TAG="$(git tag | tail -n 1)"
fi
git checkout "${TAG}"
cmake .. -DRPI4ARM64=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo
make -j"$(nproc)" && success "Building Box${ARCH} - Done"
info "Installing Box${ARCH}"
sudo make install && success "Installing Box${ARCH} - Done"
done
sudo systemctl restart systemd-binfmt.service
if ! grep -F '[valheim_server.x86_64] #box64 v0.2.6' ~/.box64rc; then
info "Adding box64 configuration"
cat <<-EOF | tee -a ~/.box64rc
[valheim_server.x86_64]
BOX64_DYNAREC_BLEEDING_EDGE=0
BOX64_DYNAREC_STRONGMEM=3
EOF
fi
fi
# Fetch and initialize steamcmd
if [[ ! -f ~/steamcmd/steamcmd.sh ]]; then
info "Fetching steamcmd"
mkdir -p ~/steamcmd && \
cd ~/steamcmd && \
curl -sqL "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar zxvf -
./steamcmd.sh +quit && success "Fetching steamcmd - Done"
fi
# Add steamcmd steamclient.so symlink
info "Adding steamclient.so symlink"
mkdir -p ~/.steam/sdk64 && ln -frs ~/steamcmd/linux64/steamclient.so ~/.steam/sdk64/
# Install the Valheim Dedicated Server from Steam
if [[ ! -f ~/valheim_server/start_server.sh ]]; then
info "Installing Valheim Dedicated Server"
cd ~/steamcmd
./steamcmd.sh \
+@sSteamCmdForcePlatformType linux \
+force_install_dir "/home/$USER/valheim_server" \
+login anonymous \
+app_update 896660 validate \
+quit && \
success "Installing Valheim Dedicated Server - Done"
fi
# Add x86_64 version of libpulse-mainloop-glib.so.0
if [[ $CROSSPLAY_SUPPORT == true ]]; then
if [[ ! -f ~/valheim_server/linux64/libpulse-mainloop-glib.so.0 ]]; then
info "Installing libpulse-mainloop-glib.so.0:x86_64"
pushd "$(mktemp -d)"
wget http://mirrors.kernel.org/ubuntu/pool/main/p/pulseaudio/libpulse-mainloop-glib0_15.99.1+dfsg1-1ubuntu1_amd64.deb
dpkg -x libpulse-mainloop-glib0_15.99.1+dfsg1-1ubuntu1_amd64.deb ./ && \
cp usr/lib/x86_64-linux-gnu/libpulse-mainloop-glib.so.0 "/home/$USER/valheim_server/linux64/"
success "Installing libpulse-mainloop-glib.so.0:x86_64 - Done"
popd
fi
else
rm -f "/home/$USER/valheim_server/linux64/libpulse-mainloop-glib.so.0"
fi
# Initialize the Server Credentials file
if [[ ! -f ~/server_credentials ]]; then
info "Generating server_credentials file"
PASSWORD="$(tr -dc "a-zA-Z0-9" < /dev/urandom | fold -w "32" | head -n 1)"
cat <<-EOF > ~/server_credentials && success "Done"
SERVER_NAME="My server"
WORLD_NAME="My World"
# NOTE: Minimum password length is 5 characters & Password cant be in the server name.
PASSWORD="${PASSWORD}"
# If the server should be listed publically. (1=yes, 0=no)
PUBLIC=0
PORT=2456
EOF
success "Generating server_credentials file - Done"
fi
# Update firewall
info "Updating firewall rules"
RULES=(
"INPUT -p udp -m state --state NEW -m udp --dport 2456 -j ACCEPT"
"INPUT -p udp -m state --state NEW -m udp --dport 2457 -j ACCEPT"
"INPUT -p udp -m state --state NEW -m udp --dport 2458 -j ACCEPT"
)
FIREWALL_RULES_ADDED=false
for RULE in "${RULES[@]}"; do
sudo iptables -C ${RULE} 2> /dev/null || \
sudo iptables -I ${RULE} && FIREWALL_RULES_ADDED=true
done
if $FIREWALL_RULES_ADDED; then
sudo cp /etc/iptables/rules.v4{,.bak}
TMP_FILE=$(mktemp)
sudo iptables-save > "${TMP_FILE}"
sudo mv "${TMP_FILE}" /etc/iptables/rules.v4
fi
success "Done"
# Add Valheim helper
info "Creating Valheim Server helper"
mkdir -p /usr/sbin
cat <<-EOF | sudo tee /usr/sbin/valheim_server > /dev/null
#!/bin/bash
# Stop on error
set -e
function show_usage {
echo "Usage: \$(basename \$0) COMMAND"
echo
echo "Commands:"
echo " update Stops and Updates the Valheim server"
echo " start Start the Valheim server"
echo " stop Stops the Valheim server"
echo " restart Restart the Valheim server"
echo " logs Shows the logs of the Valheim server"
echo " logs-live Shows the live logs of the Valheim server"
echo " help Shows this help message"
echo
}
function start_server {
if ! systemctl --user --quiet is-active valheim_server; then
echo "Starting Server..."
systemctl --user start valheim_server
sleep 2 # sleeping to allow service to start up before validating.
systemctl --user --quiet is-active valheim_server && \
echo "Server Started"
else
echo "Server already running"
fi
}
function stop_server {
if systemctl --user --quiet is-active valheim_server; then
echo "Stopping Server, please wait..."
systemctl --user stop valheim_server
echo "Server Stopped"
else
echo "Server already stopped"
fi
}
function restart_server {
stop_server && start_server
}
case \$1 in
update)
stop_server
/home/\${USER}/steamcmd/steamcmd.sh \\
+@sSteamCmdForcePlatformType linux \\
+force_install_dir "/home/\${USER}/valheim_server" \\
+login anonymous \\
+app_update 896660 validate \\
+quit
echo
echo "Server updated."
echo "Start the server with \"valheim_server start\""
;;
start|stop|restart)
\${1}_server;;
logs)
journalctl --user -u valheim_server;;
logs-live)
journalctl --user -f -u valheim_server;;
help|--help|-h|*)
show_usage;;
esac
EOF
sudo chmod +x /usr/sbin/valheim_server
# Set up the Systemd Service
info "Setting up Systemd Service"
mkdir -p ~/.config/systemd/user/
[[ $CROSSPLAY_SUPPORT == true ]] && CROSSPLAY="-crossplay"
# Add servicefile
cat <<-EOF > ~/.config/systemd/user/valheim_server.service
[Unit]
Description=Valheim Dedicated Server
[Service]
KillSignal=SIGINT
TimeoutStopSec=30
Restart=always
RestartSec=5
WorkingDirectory=/home/${USER}/valheim_server
EnvironmentFile=/home/${USER}/server_credentials
Environment=SteamAppId=892970
Environment=LD_LIBRARY_PATH="./linux64:\$LD_LIBRARY_PATH"
ExecStart=/home/${USER}/valheim_server/valheim_server.x86_64 \\
-nographics \\
-batchmode \\
-port "\${PORT}" \\
-public "\${PUBLIC}" \\
-name "\${SERVER_NAME}" \\
-world "\${WORLD_NAME}" \\
-password "\${PASSWORD}" \\
${CROSSPLAY} \\
-savedir "/home/${USER}/valheim_data"
[Install]
WantedBy=default.target
EOF
# Enable Lingering Systemd user sessions
loginctl enable-linger
# Reload Systemd
systemctl --user daemon-reload
# Enable Valheim Systemd service allowing it to start automatically on boot
systemctl --user enable valheim_server.service && success "Setting up Systemd Service - Done"
info "Creating Readme"
cat <<-EOF > ~/Readme.md && success "Creating Readme - Done"
# Valheim Server Helper Commands
## Help
valheim_server help
## Start server
valheim_server start
## Stop server
valheim_server stop
## Updating the server
valheim_server upgrade
# Enable / Disable crossplay
This can be accomplished by re-running the setup script.
It will ask you of you want crossplay enabled or disabled.
EOF
# Start the Valheim Systemd service
success "Setup finished"
echo "A file named 'server_credentials' have been placed in the home directory"
echo "Edit as you see fit with f.ex 'nano ~/server_credentials'"
echo "Within nano, when done editing, press 'Ctrl+X', then 'y', finally 'Enter'"
echo
echo "Finally, to start the server, the following command can be used:"
echo " valheim_server start"
echo
echo "A readme with additional commands have also been placed in the home directory"
}
perform_self_update
# Pinned versions for Box 64 / 86
BOX64_VERSION="v0.2.6"
# BOX86_VERSION="v0.3.0"
main | tee install_valheim_server.log
@husjon
Copy link
Author

husjon commented Feb 29, 2024

Hi @dre3002 thanks for giving this a go.
As for the box64rc configuration, you can just use nano to open the file and add the configuration parameters. (the /etc/box64.box64rc file can also be edited but needs root/sudo access, user file is preferred in this instance).

For now I think you can just stay on v0.2.6 as that is the stable version which is released.

@Blueyescat
Copy link

Hello.

You can use FEX instead of box86/64 for BepInEx, and everything else. It does require Ubuntu 22 or newer.

I just installed FEX (using its install script, with RootFS) on ARM64. I managed to run steamcmd.sh, download Valheim beta server (didn't even know patch 0.217.28 didn't work with box64!), add BepInExPack, and run start_server_bepinex.sh, directly without FEXBash. All worked without any issues. It still says "libdoorstop can't be preloaded", but doesn't seem to matter.

I didn't test extensively, but BepInEx with ServerCharacters and ServerBlankPassword mods seemed to load and work as expected. I don't know about performance. Also, I believe on Ubuntu 20 it would work for BepInEx but not SteamCMD (modify the FEX install script).

In this case, I guess the problem is in box64. Has this issue really been going on for 3 years? 🤷

@dre3002
Copy link

dre3002 commented Feb 29, 2024

@husjon

I tried to use nano but when I type it in it says "-bash: nano: command no found". I used filezilla to see and I can't find the ".box64rc" file that needs to be edited. And I do not know how to properly make this file or where it goes, which is the main issues I am facing.

@husjon
Copy link
Author

husjon commented Feb 29, 2024

@Blueyescat first time hearing of FEX, so not sure how it would even compare unfortunately, but good to know that it works.

@husjon
Copy link
Author

husjon commented Feb 29, 2024

@dre3002 then you might need to install apt, f.ex using sudo apt install nano.
Alternatively you can create the file on your own computer and upload it to the server to the home directory of the user you use, just make sure you rename it to .box64rc

@dre3002
Copy link

dre3002 commented Feb 29, 2024

@husjon

Perfect thank you! Again I apologize if this is really basic stuff. I am still learning and struggling, but I got it working! I am finally able to connect to the server, so now I will just leave it running. Can't stress test much yet but i'll leave my character connected for the time being and see how that goes.

Later on I will try actually playing the game and having more people connect. Will update in a few days if nothing goes wrong, or immediately if it crashes.

Thanks!

@Blueyescat
Copy link

@Blueyescat first time hearing of FEX, so not sure how it would even compare unfortunately, but good to know that it works.

Yeah, Box is much faster according to these benchmarks: https://box86.org/2022/03/box86-box64-vs-qemu-vs-fex-vs-rosetta2/

But perhaps it will be okay with Valheim or OCI Ampere, or help Box in some way...

@husjon
Copy link
Author

husjon commented Feb 29, 2024

A nice read even though the article is 2 years old, I suspect there have been improvements from all parts since then.

For now as for this guide, I will stay with Box as supporting multiple can become quite the hassle really quickly, I will however definitely keep FEX in mind as it's nice to have different options available.

@husjon
Copy link
Author

husjon commented Feb 29, 2024

@dre3002 happy to help and glad you got it going, looking forward to hearing the results.

@husjon
Copy link
Author

husjon commented Mar 13, 2024

Just a heads up, the install script has now been updated to apply the fix mentioned in #gistcomment-4916615 .
Since quite a few people have tested it and there positive results, I've decided to make the changes public and easier to apply.

I've currently pinned the box64 version to v0.2.6 which have had the best result, the upcoming v0.2.7 will require some minor tweaks but will be applied when it is updated.

Note: If you have made any changes to the ~/.box64rc configuration file for the [valheim_server.x86_64] section other than what was mentioned in the above gist comment, please remove it and re-run the setup script, this will re-apply the correct settings.

Finally, a huge thanks to everyone helping with testing.

@dre3002
Copy link

dre3002 commented Mar 19, 2024

Hey sorry I took so long. Just wanted to provide a little update.

I was intrigued by @Blueyescat suggestion of using FEX as it seems to support modding. I ended up setting a server up with FEX because of this and have been playing for the last 2 weeks with a friend. There have been some issues but I am unsure if they were caused by the game itself or because of FEX or because of my friends high ping (he gets 100ms vs my 3ms) or some combination of everything. For the most part though I am able to get about 3-4 days of continuous run time before the server crashes or something goes wrong. A quick restart fixed most issues.

Gameplay wise it has been pretty good. We are using the "Better Networking" mod which seemed to have significantly helped with some lag issues.

As for BOX64, I did leave the server running for about a week but was not actively playing on it due to messing with FEX. Of the time I left it running I did occasionally connect and everything seemed to work fine. No issues with crashing. I will also add that generating a world is significantly faster on BOX64 vs FEX. But most other tasks are done in a similar timeframe. I do wish Bepinex worked with BOX64 though as performance would likely be so much better.

@marciz34
Copy link

If I wanted to create a new world. would I just stop the server and then edit the config file with a new name?

Also am I alone in being charged $2/month from Oracle to use this server?

@husjon
Copy link
Author

husjon commented Mar 26, 2024

Hi @marciz34, yeah stopping the server and WORLD_NAME in ~/server_credentials, then restarting the server is all that is needed.

As for being charged, make sure that you're using the correct shape VM.Standard.A1.Flex and not exceeding the oCPU and memory limits. (See Always_Free_Resources for more information)
Keep in mind this is a maximum of multiple instances, you can have many instances but at most 4 cpus and 24gb memory assigned in total following the shape type mentioned above.

Hope this helps.

@user4302
Copy link

user4302 commented Mar 31, 2024

im having some trouble

so i first ran valheim_server update
then using the latest version on valhheim on steam the most i was able to do was enter the password,

and then i got the following on the server logs
Peer 6548764327654327 has incompatible version, mine:0.217.31 (network version 18) remote 0.217.38 (network version 20)

so i selected the last stable version on steam for valheim, which is 0.217.31
and now i dont get any server logs when i try to connect to the server

and the game just says failed to connect

update:

restarting the server seems to fix whatever issues i had, and i can now connect to the game successfully.
(played just for a minute or 2)

big thank you to everyone involved in helping with getting this to work again

@user4302
Copy link

user4302 commented Apr 2, 2024

ok its not working

so i did a few tests,

2 days ago i was able to login and move around, it was fine
i only tested for around 1 minute

today someone else tried logging in, and it said failed to connect
and the server logs did not show any logs of anyone trying to connect

so i restarted the valheim server and he was able to connect but when he went through a portal he was disconnected

restarting the server did not work again after this
so i restarted the OCI
i was able to login, but had an icon on the top left blinking, looked like a cable connected to a box
i think my network was just unstable (im assuming)

after this the other person was again unable to login, he got the failed to connect popup, and no updates on the valheim logs-live
its the same if i restart the valheim server and try to connect to it as well

i am attaching my logs for when i restart the server, there are quite a lot of errors and warnings, but it just say game server connected at the end of it all

https://pastebin.com/0CszLKKW

@husjon
Copy link
Author

husjon commented Apr 2, 2024

Hi @user4302 I can't see any references to box in the logs.
With the updated done with the install script it should enable a few environment variables for box64.
Can you see file in the home directory named ~/.box64rc?

If not, could you try to manually update the install script (#installer-self-update for more information), then re-run the installer to apply the patch.

@nafnarem
Copy link

nafnarem commented Apr 3, 2024

Hi @husjon Thanks so much for the guide! I got it working. :) Can i ask though if you can teach me how to add a discord webhook/notification system on it? Thanks again!

@user4302
Copy link

user4302 commented Apr 4, 2024

Hi @user4302 I can't see any references to box in the logs. With the updated done with the install script it should enable a few environment variables for box64. Can you see file in the home directory named ~/.box64rc?

If not, could you try to manually update the install script (#installer-self-update for more information), then re-run the installer to apply the patch.

heyy, thanks for the fast reply,

so i ran ls -la inside home/Ubuntu (/home only has Ubuntu and ops folders) and do not see any files or folders called .box64rc (https://imgur.com/a/5WgnvWr)
to manually update the install script im assuming i just need to run that command,
and after that i run valheim_server update again, ill try that

Update

After the self update, Running valheim_server update didnt fix the issue, should I run bash ./setup_valheim_server.sh?

Also will this overwrite my existing saves?
(I do have backups)

@netserver238
Copy link

Hi @user4302 I can't see any references to box in the logs. With the updated done with the install script it should enable a few environment variables for box64. Can you see file in the home directory named ~/.box64rc?
If not, could you try to manually update the install script (#installer-self-update for more information), then re-run the installer to apply the patch.

heyy, thanks for the fast reply,

so i ran ls -la inside home/Ubuntu (/home only has Ubuntu and ops folders) and do not see any files or folders called .box64rc (https://imgur.com/a/5WgnvWr) to manually update the install script im assuming i just need to run that command, and after that i run valheim_server update again, ill try that

try /etc/box64.box64rc

@user4302
Copy link

user4302 commented Apr 4, 2024

Hi @user4302 I can't see any references to box in the logs. With the updated done with the install script it should enable a few environment variables for box64. Can you see file in the home directory named ~/.box64rc?
If not, could you try to manually update the install script (#installer-self-update for more information), then re-run the installer to apply the patch.

heyy, thanks for the fast reply,
so i ran ls -la inside home/Ubuntu (/home only has Ubuntu and ops folders) and do not see any files or folders called .box64rc (https://imgur.com/a/5WgnvWr) to manually update the install script im assuming i just need to run that command, and after that i run valheim_server update again, ill try that

try /etc/box64.box64rc

Hi, yeah there is such a file there. box64 as well as box86

@husjon
Copy link
Author

husjon commented Apr 4, 2024

@user4302

Update

After the self update, Running valheim_server update didnt fix the issue, should I run bash ./setup_valheim_server.sh?

Also will this overwrite my existing saves? (I do have backups)

Yeah, re-running the installer (./setup_valheim_server.sh) after the manual update will apply the fix and add the file under ~/.box64rc

The configuration under /etc/box64 isn't necessary, but if you add it, the one in the home directory will take precedence.

As for overwriting, no it should only re-use the existing saves, but backups are always recommended :)

@user4302
Copy link

user4302 commented Apr 5, 2024

@user4302

Update

After the self update, Running valheim_server update didnt fix the issue, should I run bash ./setup_valheim_server.sh?
Also will this overwrite my existing saves? (I do have backups)

Yeah, re-running the installer (./setup_valheim_server.sh) after the manual update will apply the fix and add the file under ~/.box64rc

The configuration under /etc/box64 isn't necessary, but if you add it, the one in the home directory will take precedence.

As for overwriting, no it should only re-use the existing saves, but backups are always recommended :)

this worked!!!
thank you so muchhhh!!!

on an unrelated note,
even a month or 2 ago, i was getting some bad stuttering when i move around or look around, has anyone else experienced this?
or is my internet just bad? (cos it is right now)

@husjon
Copy link
Author

husjon commented Apr 5, 2024

Glad to see it worked, happy to help. :)

As for the stuttering, during my testing I did not see anything like it.

@RaDiKalDev
Copy link

RaDiKalDev commented Apr 5, 2024 via email

@FrederikBRM
Copy link

Capture
I seem to be getting an error i cant fix. The error is: Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine= @.host --user to connect to bus of other user)

Have you encountered this?

@husjon
Copy link
Author

husjon commented Apr 8, 2024

Hi @FrederikBRM it seem like you're running the script with sudo, this is not necessary. :)

@FrederikBRM
Copy link

I got it working, thanks alot for the help and the great guide!

@Toffy122
Copy link

Toffy122 commented Apr 30, 2024

To run newest version with ashlands run this command instead:

cd ~/steamcmd

./steamcmd.sh \
    +@sSteamCmdForcePlatformType linux \
    +force_install_dir "/home/$USER/valheim_server" \
    +login anonymous \
    +app_update 896660 -beta public-test -betapassword yesimadebackups validate \
    +quit

@husjon
Copy link
Author

husjon commented Apr 30, 2024

Thanks @Toffy122, I've updated the guide to include this for future reference. 👍
See #switching-to-the-public-beta-branch

@Toffy122
Copy link

Toffy122 commented Apr 30, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment