-
-
Save amingholami/8c71bf2dbd95bd1ad187dd078635d7bf to your computer and use it in GitHub Desktop.
Install Mikrotik CHR on a DigitalOcean Droplet (2021)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 partx && \ | |
| 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 |
Many thanks for this, I was struggling with some scripts suitable for Ubuntu 16.x which weren't working now.
and to install a version 7.x?
and to install a version 7.x?
Replace the link with this link:
https://download.mikrotik.com/routeros/7.2.3/chr-7.2.3.img.zip
very pleasent and working instruction .
if you install the lastest 7.X version it needs to set a mac address .
just dont forget to setup
/interface ethernet set ether1 mac-address=[MACADDRESS]
mac address format should be XX:XX:XX:XX:XX
Thanks a lot, it save my day !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for right/clear instruction for Install CHR at DO. 👍