Skip to main content
This guide walks through installing MikroTik Cloud Hosted Router (CHR) on an Ubuntu-based EDBB VPS.
You’ll download the latest CHR image, inject an autorun script with your current IP settings, write the image to the VPS disk, and reboot straight into RouterOS.
Winbox is then used to complete the initial configuration.

1. Prepare the VPS

  1. Reinstall the VPS with a clean Ubuntu 22.04 environment using the EDBB VPS Portal.
  2. Boot the VPS and connect via SSH.
The script automatically pulls your existing IPv4 and gateway from Ubuntu before overwriting the disk. Make sure the VPS has internet connectivity during the process.

2. Create the Installation Script

  1. Create a new script file (example name: install_chr.sh):
nano install_chr.sh
  1. Paste the following script provided by EDBB:
#!/bin/bash
set -euo pipefail

# Step 0: Run as root
if [[ $EUID -ne 0 ]]; then
    echo "Please run as root (e.g. sudo $0)"
    exit 1
fi

# Install required tools
apt-get update
apt-get -y install wget curl gzip kpartx unzip

# Step 1: Get latest CHR version
latest_version=$(curl -s https://mikrotik.com/download \
  | grep -oP 'chr-\K[0-9]+\.[0-9]+\.[0-9]+(?=\.img\.zip)' \
  | sort -V | tail -n1)

echo "[*] Latest CHR version: $latest_version"

# Step 2: Download image
download_url="https://download.mikrotik.com/routeros/$latest_version/chr-$latest_version.img.zip"
echo "[*] Downloading from $download_url ..."
wget --no-check-certificate "$download_url" -O chr.img.zip

# Step 3: Extract image
echo "[*] Extracting image..."
unzip -o chr.img.zip
mv "chr-$latest_version.img" chr.img

# Step 4: Detect root disk (the device that hosts /)
root_disk=$(df / | tail -1 | awk '{print $1}' | sed 's/[0-9]*$//')
if [[ -z "${root_disk}" ]]; then
  echo "[-] Could not detect root disk!"
  exit 1
fi
echo "[*] Root disk detected: $root_disk"

# Step 5: Map partitions and mount
echo "[*] Mapping partitions..."
loop_dev=$(losetup -f --show chr.img)         # e.g. /dev/loop6
kpartx_out=$(kpartx -av "$loop_dev" || true)  # some images may have 1 partition only
echo "$kpartx_out"

# Wait for device nodes
udevadm settle || true
sleep 1

base=$(basename "$loop_dev")  # loopN
candidates=(/dev/mapper/${base}p*)
parts=()
for p in "${candidates[@]}"; do [[ -e "$p" ]] && parts+=("$p"); done

# If no mapper partitions, try mounting the whole loop device (rare case)
if [[ ${#parts[@]} -eq 0 ]]; then
  parts=("$loop_dev")
fi

# Choose the highest partition if multiple exist
part_to_mount="${parts[-1]}"
echo "[*] Mounting $part_to_mount ..."
mkdir -p /mnt/chr
mount "$part_to_mount" /mnt/chr

# Step 6: Collect current network settings from Ubuntu
iface=$(ip -o -4 addr show up primary scope global | awk '{print $2}' | head -n1 || true)
ipaddr=$(ip -o -4 addr show dev "${iface:-}" | awk '{print $4}' | head -n1 || true)
gateway=$(ip route | awk '/^default/ {print $3; exit}' || true)

if [[ -z "${ipaddr}" || -z "${gateway}" ]]; then
  echo "[-] Could not determine IP/Gateway from host. Proceeding but autorun will miss L3 config."
fi

# Step 7: Inject autorun.scr (prefer /rw if present)
echo "[*] Injecting autorun.scr ..."
target_dir="/mnt/chr"
if [[ -d "/mnt/chr/rw" ]]; then
  target_dir="/mnt/chr/rw"
fi

cat > "${target_dir}/autorun.scr" <<EOF
/ip address add address=${ipaddr} interface=[/interface ethernet find where name=ether1]
/ip route add gateway=${gateway}
/ip dns set servers=1.1.1.1,1.0.0.1 allow-remote-requests=yes
/ip service disable telnet
EOF

sync

# Step 8: Cleanup mounts and mappings
umount /mnt/chr || true
kpartx -dv "$loop_dev" || true
losetup -d "$loop_dev" || true
rm -rf /mnt/chr

# Step 9: Overwrite root disk with CHR (IRREVERSIBLE)
echo "[*] Installing CHR on $root_disk (this will erase Ubuntu!)"
dd if=chr.img of="$root_disk" bs=4M oflag=sync status=progress

# Step 10: Reboot into CHR
echo "[*] Done. Rebooting into CHR in 5 seconds..."
sleep 5
echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger
  1. Save the file (Ctrl + O, Enter) and exit (Ctrl + X).

3. Run the Installer

chmod +x install_chr.sh
sudo ./install_chr.sh
  • The script verifies root privileges, installs dependencies, fetches the newest CHR image, injects the autorun script, writes the image to the VPS disk, and reboots the server.
  • Expect the SSH session to terminate once the image begins writing and the reboot occurs.
The dd step erases the existing Ubuntu installation. Ensure all required data is backed up before running the script.

4. Connect with Winbox

After the VPS restarts, it will boot into MikroTik RouterOS. Finish the initial setup using Winbox:
  1. Download Winbox from mikrotik.com/download.
  2. Launch Winbox and create a new session:
    • Connect To: public IPv4 address of the VPS.
    • Login: admin
    • Password: leave blank on first login.
    • Click Connect.
  3. When prompted, set a strong password for the admin account.
  4. Verify that ether1 carries the IP address from the autorun script, adjust DNS settings if required, and continue with your RouterOS configuration.
You now have a clean MikroTik CHR deployment on EDBB infrastructure, ready for routing, firewall, and VPN services.