阿里云安装 MikroTik CHR 方法
网上查的基本都是一个方法,基于linux覆盖安装,过程中有几部莫名其妙会失败,这里记录一下,以便自查
1、# 下载
wget https://download.mikrotik.com/routeros/6.47.1/chr-6.47.1.img.zip
2、# 解压
gunzip -c chr-6.47.1.img.zip > chr.img
3、# 挂载并写入自定义脚本,目的是修改阿里云内网IP地址,其实外网IP地址阿里云不写在Linux上,统一由路由转发
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
4、# 写入镜像到虚拟磁盘,of=/dev/vda 代表全盘,不要加数字!
echo u > /proc/sysrq-trigger && \
dd if=chr.img bs=1024 of=/dev/vda
5、# 重启
reboot
以上是通用教程,其中
3、有点问题,按照offset=33554944可能会报错,为啥会报错,插入一段找到的说明,一般新安装的阿里云centos7.x系统 start字段值一般是1(红色字体那个),所以这个命令一般都直接敲mount -o loop,offset=512 chr.img /mnt基本没问题
##############################
至于为什么要跳过33554944,才能到分区,这个也不太清楚。论坛上说,磁盘镜像文件的前多少个字节,是给MBR,master boot record用的,
33554944=512*65537.其中一个扇区的大小是512,第一个扇区用来存放MBR,其后的65537个扇区作为保留扇区
不同系统的开始扇区可能不一样,如何查找呢。输入如下指令:
# fdisk -l chr.img
You must set cylinders.
You can do this from the extra functions menu.
Disk centorg.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000db6d8
Device Boot Start End Blocks Id System
chr.img1 * 65537 15358139 7679038+ 83 Linux
chr.img2 15358140 16771859 706860 82 Linux swap / Solaris
Partition 2 has different physical/logical endings:
phys=(1023, 254, 63) logical=(1043, 254, 63)
第一个的开始扇区为65537。所以要跳过的字节数为 65537*512
###########################
4、of=/dev/vda 这个参数的问题,用df -h 查看挂载情况,一般 有 /dev/sda1 或者 /dev/vda1 ,去掉数字把前边的填进去,带数字不行
总结:其实第3步实测没有用,即使你做了第3步,进入到chr以后,也不会得到固定IP!!!!,直接 1 2 4 5 就行了
因为chr会默认给ether1增加了dhcp-client,所以重启系统后,肯定会获取到阿里云DHCP分配的IP,和原来 centos时是一样的,就动态那么用就行了!!!
祝大家成功~