Skip to content

thinktanktom/OpenWRT-Initram-Flash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Guidelines on Flashing OpenWRT on a Mikrotik Machine via a VM

This guide takes inspiration from OpenWRT Mikrotik Guide.

Prerequisites

  • Nix Package Manager (optional but recommended)
  • Vagrant or any other VM software

If you're using NixOS like I am, and want to follow this guide without changing your distribution, consider installing the Nix package manager from here.

Flash Guide

  1. Create a Directory for TFTP Server

    mkdir ~/tftpserver/
    cd ~/tftpserver/
    mkdir srv/
  2. Prepare Boot Files

    Place the boot files for your specific router in the srv/ directory. Connect your Ethernet cable to port 1 of your router and the other end to your host machine. Access your router via WinBox or your browser, and navigate to System -> RouterBoot -> Settings. Change the following setting:

    • Boot method: DHCP (optional as dnsmasq supports bootp as well)

    Note: If you can't access the router via WinBox through the eth1 port, try connecting the cable to port 2. However, the flash will only work through port 1.

  3. Initialize a Vagrant VM

    cd ~/tftpserver/
    vagrant init alpine/alpine64

    Edit the generated Vagrantfile to include the following line, ensuring the VM is on the same subnet as the router:

    config.vm.network "public_network", dev: "network_interface_placeholder"

    Replace network_interface_placeholder with the network interface of the Ethernet connection associated with your router.

  4. Boot and Access the VM

    vagrant up
    vagrant ssh

    Change the root password in your VM:

    sudo passwd root
  5. Transfer Boot Files to the VM

    From your host machine, transfer the initramfs file to the VM:

    scp tftpserver/srv/openwrt-23.05.0-ath79-mikrotik-mikrotik_routerboard-951ui-2nd-*.bin vagrant@192.168.121.*:/home/vagrant/
  6. Install and Configure dnsmasq

    sudo apk update
    sudo apk add dnsmasq
    which dnsmasq
  7. Create and Execute loader.sh Script

    Create a script named loader.sh with the following content:

    #!/bin/bash
    IFNAME=eth1
    /sbin/ip addr replace 192.168.88.10/24 dev $IFNAME
    /sbin/ip link set dev $IFNAME up
    /usr/sbin/dnsmasq \
      --no-daemon \
      --listen-address 192.168.88.10 \
      --bind-interfaces \
      -p0 \
      --dhcp-authoritative \
      --dhcp-range=192.168.88.100,192.168.88.200 \
      --bootp-dynamic \
      --dhcp-boot=/home/vagrant/openwrt-19.07-*-initramfs-* \
      --log-dhcp \
      --enable-tftp \
      --tftp-root=/home/vagrant/

    Ensure the script is executable and the initramfs file has the correct permissions:

    chmod +x loader.sh
    chmod 644 /home/vagrant/openwrt-23.05.0-ath79-mikrotik-mikrotik_routerboard-951ui-2nd-*.bin

    Run the TFTP server:

    su
    ./loader.sh
  8. Boot the Router into OpenWRT

    Power off the router, press the reset button, and hold it while powering it back on for 15-20 seconds or until logs appear in the VM terminal. Your router should boot into OpenWRT. On rebooting, it will revert to RouterOS.

    Note: Access OpenWRT via your browser at http://192.168.1.1/.

Debugging Steps

If the router isn't accessible via WinBox or your browser, try the following:

  • Change the IP address attached to the network interface of your router's Ethernet connection to one in the same network as the router. NixOS users can add this to their configuration.nix:

    networking.firewall.enable = false;
    networking.interfaces.<network_interface_placeholder> = {
      ipv4.addresses = [
        {
          address = "192.168.88.x";
          prefixLength = 24;
        }
      ];
      useDHCP = true;
    };

If the router remains inaccessible, power it off, hold the reset button for 15-20 seconds while powering it back on. Access the router configuration page via WinBox or your browser, and go to System -> Reset Configuration to reset the router to the default RouterOS configuration.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published