Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Mikrotik CHR on a Digital Ocean droplet
wget http://download2.mikrotik.com/routeros/6.40.5/chr-6.40.5.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 && \
partx -a /dev/nbd0 && \
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
@stroebs

This comment has been minimized.

Copy link
Owner Author

stroebs commented Oct 28, 2017

Can be used on a fresh Ubuntu 16.04 installation.
Kudos: https://www.digitalocean.com/community/questions/installing-mikrotik-routeros

@stroebs

This comment has been minimized.

Copy link
Owner Author

stroebs commented Nov 30, 2017

Updated to include a partx on line 11 - Script stopped at mount /dev/nbd0p2 /mnt with /dev/nbd0p2 missing

@stroebs

This comment has been minimized.

Copy link
Owner Author

stroebs commented Jan 24, 2018

Update: Your droplet is likely to run into Kernel Panic while the image is writing to disk.

You'll need to forcefully stop your droplet in the DO control panel and start it up again. After that it's good to go!

@electropolis

This comment has been minimized.

Copy link

electropolis commented Jan 27, 2018

Does work only in DO ? I tried that on Ubuntu on UpCloud provider and server restarted again to the same system what it was before .. Ubuntu

-bash: relocation error: -bash: symbol , version GLIBC_2.2.5 not defined in file libc.so.6 with link time reference -bash: relocation error: -bash: symbol , version GLIBC_2.2.5 not defined in file libc.so.6 with link time reference

Ok although it started somehow beside those error on servers from DO and UpCloud. You could also add eth1 for ether2 with private IP which is very important

@hklkf

This comment has been minimized.

Copy link

hklkf commented Feb 25, 2018

how to fix it?

2018-02-25 02:59:05 (4.87 MB/s) - ‘chr.img.zip’ saved [45164547/45164547]

make-chr.sh: line 3: apt-get: command not found

@fyrstyk

This comment has been minimized.

Copy link

fyrstyk commented Mar 7, 2018

DO have updated to ubuntu 16.04.4, and it looks like the script no longer works when writing to /dev/vda :(

Any ideas?

Thanks in advance.

@happy201807

This comment has been minimized.

Copy link

happy201807 commented Aug 31, 2018

If the ip addr NIC is ens3 instead of eth0, I can't connect to vps after installation. What do I need to change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.