Files
valheim-linode/stackscript.md
T
2026-09-20 22:27:52 -07:00

2.3 KiB

Valheim Volume StackScript

A Linode StackScript that mounts the pre-existing Valheim volume on first boot. Running it as a StackScript means the mount happens as root during deployment, so no SSH session (and therefore no SSH key) is needed to configure it.

This mirrors the steps in voldirections.txt. The filesystem (mkfs.ext4) is not created here, because that step has already been completed on the volume; the script only creates the mountpoint, mounts the device, and adds the /etc/fstab entry.

Instructions

  1. Log in to the Linode Cloud Manager and open StackScripts.
  2. Click Create StackScript.
  3. Set Label to something like valheim-volume-mount and choose Debian 13 (or "Any") as the Target Images.
  4. Paste the code block below into the Script editor.
  5. Leave the UDF (User Defined Fields) section empty — the values are hard-coded, so nothing needs to be entered at deploy time.
  6. Click Save. The numeric ID of the StackScript appears in the URL and in the StackScript list; copy it.
  7. Put that ID in create-linode.sh as the STACKSCRIPT_ID value near the top of the file.

After that, create-linode.sh c <label> passes the StackScript on the create call and the volume is mounted automatically on first boot.

StackScript

#!/bin/bash
# Linode StackScript: mount the pre-existing Valheim volume on first boot.
# Runs as root during deployment; no SSH access required.

set -euo pipefail

# The volume already has an ext4 filesystem (see voldirections.txt), so only
# the mountpoint, the mount, and the fstab entry are handled here.
VOLUME_NAME="ValVol202609"
VOLUME_DEVICE="/dev/disk/by-id/scsi-0Linode_Volume_${VOLUME_NAME}"
VOLUME_MOUNT="/mnt/${VOLUME_NAME}"

# The volume is attached by the API after deployment starts, so wait for the
# device to show up before trying to mount it.
for _ in $(seq 1 30); do
  [ -e "$VOLUME_DEVICE" ] && break
  sleep 5
done

if [ ! -e "$VOLUME_DEVICE" ]; then
  echo "Volume device ${VOLUME_DEVICE} did not appear; skipping mount." >&2
  exit 1
fi

mkdir -p "$VOLUME_MOUNT"
mount "$VOLUME_DEVICE" "$VOLUME_MOUNT"

# Mount on every boot, without duplicating the line on re-runs.
grep -q "$VOLUME_DEVICE" /etc/fstab || \
  echo "${VOLUME_DEVICE} ${VOLUME_MOUNT} ext4 defaults,noatime,nofail 0 2" >> /etc/fstab

echo "Mounted ${VOLUME_DEVICE} at ${VOLUME_MOUNT}."