Skip to content

Instantly share code, notes, and snippets.

@stroebs
Last active January 19, 2025 10:59
Show Gist options
  • Select an option

  • Save stroebs/54fc09734a3911e91eeeb43434f117df to your computer and use it in GitHub Desktop.

Select an option

Save stroebs/54fc09734a3911e91eeeb43434f117df to your computer and use it in GitHub Desktop.

Revisions

  1. stroebs revised this gist May 9, 2022. No changes.
  2. stroebs revised this gist Mar 31, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion make-chr.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/bash
    #
    # Digital Ocean Ubuntu 18.04 x64 Droplet
    # Digital Ocean Ubuntu 18.04 x64 Droplet with "Regular Intel" CPU.
    # Running:
    # git clone https://gist.github.com/54fc09734a3911e91eeeb43434f117df.git
    # cd 54fc09734a3911e91eeeb43434f117df/
  3. stroebs revised this gist Jan 4, 2021. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion make-chr.sh
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,8 @@
    #
    # Digital Ocean Ubuntu 18.04 x64 Droplet
    # Running:
    # wget https://gist.githubusercontent.com/stroebs/54fc09734a3911e91eeeb43434f117df/raw/54fc09734a3911e91eeeb43434f117df/make-chr.sh
    # git clone https://gist.github.com/54fc09734a3911e91eeeb43434f117df.git
    # cd 54fc09734a3911e91eeeb43434f117df/
    # chmod +x make-chr.sh
    # ./make-chr.sh
    #
  4. stroebs revised this gist Jan 4, 2021. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions make-chr.sh
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,16 @@
    #!/bin/bash
    #
    # Digital Ocean Ubuntu 16.04.6 Droplet
    # Digital Ocean Ubuntu 18.04 x64 Droplet
    # Running:
    # wget https://gist.githubusercontent.com/stroebs/54fc09734a3911e91eeeb43434f117df/raw/1ede2fb162d404171122db0c84a9eeea468a92cd/make-chr.sh
    # wget https://gist.githubusercontent.com/stroebs/54fc09734a3911e91eeeb43434f117df/raw/54fc09734a3911e91eeeb43434f117df/make-chr.sh
    # chmod +x make-chr.sh
    # ./make-chr.sh
    #
    # Once the reboot is done, login with root/CHANGEME and change the password!
    # You might get a "Segmentation fault" on line 56 while the image is being written.
    # Most of the time this is absolutely fine. Reboot the droplet and attempt to login using Winbox.
    # If it didn't work, just trash the droplet and try it again.
    #
    wget http://download2.mikrotik.com/routeros/6.37/chr-6.37.img.zip -O chr.img.zip && \
    gunzip -c chr.img.zip > chr.img && \
    apt-get update && \
  5. stroebs revised this gist Aug 31, 2019. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions make-chr.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,11 @@
    #!/bin/bash
    #
    # Digital Ocean Ubuntu 16.04.6 Droplet
    # Running:
    # wget https://gist.githubusercontent.com/stroebs/54fc09734a3911e91eeeb43434f117df/raw/1ede2fb162d404171122db0c84a9eeea468a92cd/make-chr.sh
    # chmod +x make-chr.sh
    # ./make-chr.sh
    #
    wget http://download2.mikrotik.com/routeros/6.37/chr-6.37.img.zip -O chr.img.zip && \
    gunzip -c chr.img.zip > chr.img && \
    apt-get update && \
  6. stroebs revised this gist Aug 31, 2019. No changes.
  7. stroebs revised this gist Aug 31, 2019. 1 changed file with 9 additions and 4 deletions.
    13 changes: 9 additions & 4 deletions make-chr.sh
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,25 @@
    wget http://download2.mikrotik.com/routeros/6.40.5/chr-6.40.5.img.zip -O chr.img.zip && \
    wget http://download2.mikrotik.com/routeros/6.37/chr-6.37.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` && \
    qemu-img resize chr.qcow2 1073741824 && \
    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 && \
    partprobe /dev/nbd0 && \
    sleep 5 && \
    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` && \
    PASSWORD="CHANGEME" && \
    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
    /user set 0 name=root password=$PASSWORD
    /ip dns set servers=1.1.1.1,1.0.0.1
    /system package update install
    " > /mnt/rw/autorun.scr && \
    umount /mnt && \
    echo "Magic constant is 65537 (second partition address). You can check it with fdisk before appliyng this" && \
    @@ -35,6 +39,7 @@ echo "Warming up sleep" && \
    sleep 1 && \
    echo "Writing raw image, this will take time" && \
    zcat /mnt/chr-extended.gz | pv > /dev/vda && \
    echo "Don't forget your password: $PASSWORD" && \
    echo "Sleep 5 seconds (if lucky)" && \
    sleep 5 || true && \
    echo "sync disk" && \
  8. stroebs revised this gist Nov 30, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion make-chr.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    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 && \
    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 && \
  9. stroebs revised this gist Nov 30, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion make-chr.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    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 && \
    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 && \
  10. stroebs revised this gist Nov 30, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions make-chr.sh
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,7 @@ 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` && \
  11. stroebs revised this gist Nov 22, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion make-chr.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    wget http://download2.mikrotik.com/routeros/6.40.4/chr-6.40.4.img.zip -O chr.img.zip && \
    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 && \
  12. stroebs revised this gist Oct 28, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion make-chr.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    wget http://download2.mikrotik.com/routeros/6.36.4/chr-6.40.4.img.zip -O chr.img.zip && \
    wget http://download2.mikrotik.com/routeros/6.40.4/chr-6.40.4.img.zip -O chr.img.zip && \
    gunzip -c chr.img.zip > chr.img && \
    apt-get update && \
    apt install -y qemu-utils pv && \
  13. stroebs created this gist Oct 28, 2017.
    42 changes: 42 additions & 0 deletions make-chr.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    wget http://download2.mikrotik.com/routeros/6.36.4/chr-6.40.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