Customer portal
← Knowledge Base

Installing MikroTik RouterOS on Linux with Deployment Script

This document outlines a procedure for deploying MikroTik RouterOS (CHR) onto a Linux host using an automated Bash script. The method leverages raw disk imaging (dd), loop-mounted filesystems, and dynamic extraction of host network parameters. Due to the destructive nature of disk writes involved, this workflow should only be executed after you have taken all needed backup actions.

Deploy a VM with Ubuntu 18.04, 20.04, or 22.04, and execute this script to install MikroTik RouterOS (CHR) on the system.

Check Interfaces & Disks

ip a
lsblk

Create Script

Use your favorite editor for this

nano script.sh

Script Content

#!/bin/bash
wget https://download.mikrotik.com/routeros/7.5/chr-7.5.img.zip -O chr.img.zip && \
gunzip -c chr.img.zip > chr.img && \
mount -o loop,offset=512 chr.img /mnt && \
ADDRESS=$(ip addr show enp0s3 | grep global | awk '{print $2}' | head -n1) && \
GATEWAY=$(ip route list | awk '/default/ {print $3}') && \
echo "/ip address add address=$ADDRESS interface=[/interface ethernet find where name=ether1]
/ip route add gateway=$GATEWAY
/ip service disable telnet
/user set 0 name=root password=xxxxxx" && \
echo u > /proc/sysrq-trigger && \
dd if=chr.img bs=1024 of=/dev/sda status=progress && \
sync && \
echo s > /proc/sysrq-trigger && \
sleep 5 && \
echo b > /proc/sysrq-trigger

Make Executable

chmod 755 script.sh

Run Script

./script.sh

OR

sudo ./script.sh

Replace in Script Before Running

enp0s3 ← your interface

/dev/sda ← your target disk

xxxxxx ← your root user password

Reminder

Running this will overwrite the target disk completely.

Complete restart is required after the installation.