Hello!
I would like to set up VPN server for my company using Mikrotik RouterOS. Is it possible to install it from iso?
RouterOS lacks some virtIO drivers and thus can only be installed on Xen VPS.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
6 answers

Take a fresh Ubuntu 16.04 droplet and run this command:

wget http://download2.mikrotik.com/routeros/6.36.4/chr-6.36.4.img.zip -O chr.img.zip  && \
gunzip -c chr.img.zip > chr.img  && \
mount -o loop,offset=33554944 chr.img /mnt && \
ADDRESS=`ip addr show eth0 | grep global | cut -d' ' -f 6 | head -n 1` && \
GATEWAY=`ip route list | grep default | cut -d' ' -f 3` && \
echo "/ip address add address=$ADDRESS interface=[/interface ethernet find where name=ether1]
/ip route add gateway=$GATEWAY
 " > /mnt/rw/autorun.scr && \
umount /mnt && \
echo u > /proc/sysrq-trigger && \
dd if=chr.img bs=1024 of=/dev/vda && \
reboot

After half a minute you will be able to login into your new cloud router. Do not forget to setup a password!
That image will also keep IP and gateway after configuration reset.

  • Fixed reboot in script and added default root password = “xxxxxx”

    wget http://download2.mikrotik.com/routeros/6.36.4/chr-6.36.4.img.zip -O chr.img.zip  && \
    gunzip -c chr.img.zip > chr.img  && \
    mount -o loop,offset=33554944 chr.img /mnt && \
    ADDRESS=`ip addr show eth0 | grep global | cut -d' ' -f 6 | head -n 1` && \
    GATEWAY=`ip route list | grep default | cut -d' ' -f 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
     " > /mnt/rw/autorun.scr && \
    umount /mnt && \
    echo u > /proc/sysrq-trigger && \
    dd if=chr.img bs=1024 of=/dev/vda && \
    echo "sync disk" && \
    echo s > /proc/sysrq-trigger && \
    echo "Sleep 5 seconds" && \
    sleep 5 && \
    echo "Ok, reboot" && \
    echo b > /proc/sysrq-trigger
    
    • Thanks for the script - it worked well.

      RouterOS is showing it’s HDD size as ~ 95MB. I’m on a 40GB droplet. Is it the dd command that in effect “sets” this size? Is it possible to change? Or, add another disk that would show up under RouterOS “Disks”?

      • Here is new, updated script, which extends disk space.
        This script very depends on utils output and routeros partitions and etc, so it could probably fail in the future. But the main idea should be quite clear.
        I prefer to use previous variant of this script because it runs quite faster. In fact, I do not know why you could ever need to have a big partition on router vm.

        wget http://download2.mikrotik.com/routeros/6.36.4/chr-6.36.4.img.zip -O chr.img.zip  && \
        gunzip -c chr.img.zip > chr.img  && \
        apt-get update && \
        apt install -y qemu-utils pv && \
        qemu-img convert chr.img -O qcow2 chr.qcow2 && \
        qemu-img resize chr.qcow2 `fdisk /dev/vda -l | head -n 1 | cut -d',' -f 2 | cut -d' ' -f 2` && \
        modprobe nbd && \
        qemu-nbd -c /dev/nbd0 chr.qcow2 && \
        echo "Give some time for qemu-nbd to be ready" && \
        sleep 2 && \
        mount /dev/nbd0p2 /mnt && \
        ADDRESS=`ip addr show eth0 | grep global | cut -d' ' -f 6 | head -n 1` && \
        GATEWAY=`ip route list | grep default | cut -d' ' -f 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
         " > /mnt/rw/autorun.scr && \
        umount /mnt && \
        echo "Magic constant is 65537 (second partition address). You can check it with fdisk before appliyng this" && \
        echo "This scary sequence removes seconds partition on nbd0 and creates new, but bigger one" && \
        echo -e 'd\n2\nn\np\n2\n65537\n\nw\n' | fdisk /dev/nbd0 && \
        e2fsck -f -y /dev/nbd0p2 || true && \
        resize2fs /dev/nbd0p2 && \
        sleep 1 && \
        echo "Compressing to gzip, this can take several minutes" && \
        mount -t tmpfs tmpfs /mnt && \
        pv /dev/nbd0 | gzip > /mnt/chr-extended.gz && \
        sleep 1 && \
        killall qemu-nbd && \
        sleep 1 && \
        echo u > /proc/sysrq-trigger && \
        echo "Warming up sleep" && \
        sleep 1 && \
        echo "Writing raw image, this will take time" && \
        zcat /mnt/chr-extended.gz | pv > /dev/vda && \
        echo "Sleep 5 seconds (if lucky)" && \
        sleep 5 || true && \
        echo "sync disk" && \
        echo s > /proc/sysrq-trigger && \
        echo "Ok, reboot" && \
        echo b > /proc/sysrq-trigger
        
        • zcat /mnt/chr-extended.gz | pv > /dev/vda <– this step cannot proceed to the end, VM is hanging and SSH is droped usually arount 58-78%

          Any clue ?

    • Hi

      Im trying in my Droplet but i have no luck.

      I have a “no such directory error”.

      Can you help me?

      In the advanced and expanded disk, always hang it.

  • I have install this script mow my ssh is not coming.However, i have below configuration.

    IP : 68.183.217.169
    OS : Ubuntu
    HDD : 25 GB
    IP : 68.183.217.169

    Also guide is there is any other configuration is required or how i take console to this router

Is it possible to install it from iso?

DO doesn’t support installation of custom ISO from user end..

You can only deploy from the OS options available as standard in DO list of OS..

Refer to the FAQ section for more details..

i got error dd: error writing ’/dev/vda’: No space left on device @@

fdisk: cannot open /dev/vda: No such file or directory. why ?

Give some time for qemu-nbd to be ready
mount: special device /dev/nbd0p2 does not exist
resize2fs 1.42.13 (17-May-2015)
open: No such file or directory while opening /dev/nbd0p2

always stuck in there

  • I’m struggling with this as well. I had it working flawlessly and have a running version of RouterOS on the latest and greatest but simply cannot get partx to recognise the partitions in the image file on a new server.

    root@scw-ab2c4b:~# partx -va /dev/nbd0
    partition: none, disk: /dev/nbd0, lower: 0, upper: 0
    /dev/nbd0: partition table type ‘dos’ detected
    partx: /dev/nbd0: adding partition #1 failed: Invalid argument
    partx: /dev/nbd0: adding partition #2 failed: Invalid argument
    partx: /dev/nbd0: error adding partitions 1-2

  • Confirmed my updated script is working: https://gist.github.com/stroebs/54fc09734a3911e91eeeb43434f117df

    wget https://gist.githubusercontent.com/stroebs/54fc09734a3911e91eeeb43434f117df/raw/6e5d32781dcee606a65cb498a50063382c8ea2d0/make-chr.sh
    bash make-chr.sh
    

    (Requires Ubuntu 16.04.3 64-bit droplet)

Submit an Answer