Download CHR
Download the mikrotik CHR raw image and unzip it
wget 'https://download.mikrotik.com/routeros/6.46.1/chr-6.46.1.img.zip'
unzip chr-6.46.1.img.zip
Create the LVM
Craete a new LVM and copy the data from the image
lvcreate -L 1G -n chr vg0
dd if=chr-6.46.1.img of=/dev/vg0/chr.lcx.at-disk
Create XEN configuration
Generate new UUID
If you intend to buy a license for this CHR you need to make sure that yhe software-id does not change with every reboot, unforutnately the default setting would results in a new software id after every reboot, this would break the CHR license and you are stuck with 1Mbit. Trying to purchase a license will give you this error:
status: ERROR: This System ID is not valid for license
To create a unique uuid, run uuidgen
and use this in the xen configuration below, thanks to the Mikrotik forum for this hint.
$ uuidgen
27F7EDA4-78DD-4706-89D8-0601964BD6BC
Craete a file /etc/xen/chr.cfg
with the xen config
builder = 'hvm'
name = 'chr'
memory = 512
maxmem = 512
# this is needed so that the system id does not change
uuid = "27F7EDA4-78DD-4706-89D8-0601964BD6BC"
vcpus = 1
pae = 1
acpi = 1
viridian = 0
apic = 1
device_model = '/bin/true'
boot = 'cd'
sdl = 0
usb = 1
usbdevice = 'tablet'
vnc = 1
vnclisten = '0.0.0.0'
serial = 'pty'
vif = [ 'type=ioemu, bridge=xenbr0, ip=127.0.0.1, mac=some:mac:address:here']
disk = [ 'phy:/dev/vg0/chr,hda,w']
on_poweroff = 'preserve'
on_reboot = 'restart'
on_crash = 'restart'
replace the ip and mac address, you can use this Random MAC Address Generator to generate a new random MAC Address for the vm.
Start it
now you can start the mikrotik CHR and connect to it via VNC
xl create /etc/xen/chr.cfg
Credits
XEN script is based on this post on the mikrotik forum from maznu