Manual:CHR ProxMox installation

From MikroTik Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
  • Create a new guest with the system disk and other devices as required.
  • Then you have to manually upload the CHR disk (in qcow format) on the ProxMox host.
  • Use scp or any other comparable tool as that will use SSH for the upload and it does not require any additional configuration.
  • Either copy the file to the server and then manually edit the VM's .conf file or replace previously created system image file used for booting the guest.
  • Local storage on ProxMox is in /var/lib/vz directory. There should be a subdirectory called images with a directory for each VM (named by the VM number). You can copy the files directly there.
  • For adding the existing file to the VM, edit the VM's .conf file directly. Look in /etc/pve/qemu-server/ for a file with the VM number followed by .conf.
Icon-note.png

Note: It's a good idea to create a second test VM so you can refer to it's .conf file to make sure you get the syntax right


Alternative approach

  • Create Basic VM via ProxMox web GUI.
  • Make sure that VM storage is on local storage (this way there will no need to work with LVM config side, and disk image can be moved later on to LVM or other desired storage if needed).
  • Log into ProxMox host via SSH and navigate to VM image directory. Default local storage is located in: var/lib/vz/images/(VM_ID)
  • Via scp, wget or any other tool download CHR raw image (.img file) into this directory.
  • Now convert chr raw image to qcow2 format via qemu-img tool:
qemu-img convert -f raw -O qcow2 chr-6.40.3.img vm-(VM_ID)-disk-1.qcow2

Bash script approach

If you have access to ProxMox host then CHR VM can also be created quickly via bash script. Below example of one such script.

What this script does:

  • Stores tmp files in: "/root/temp" dir
  • Downloads raw image archive from MikroTik AWS download page.
  • Converts image file to qcow format
  • Creates basic VM that is attached to MGMT bridge.
#!/bin/bash

#vars
version="nil"
vmID="nil"

echo "############## Start of Script ##############

## Checking if temp dir is available..."
if [ -d /root/temp ] 
then
    echo "-- Directory exists!"
else
    echo "-- Creating temp dir!"
    mkdir /home/root/temp
fi
# Ask user for version
echo "## Preparing for image download and VM creation!"
read -p "Please input CHR version to deploy (6.38.2, 6.40.1, etc):" version
# Check if image is available and download if needed
if [ -f /root/temp/chr-$version.img ] 
then
    echo "-- CHR image is available."
else
    echo "-- Downloading CHR $version image file."
    cd  /root/temp
    echo "
---------------------------------------------------------------------------"
    wget https://download2.mikrotik.com/routeros/$version/chr-$version.img.zip
    unzip chr-$version.img.zip
    echo "
---------------------------------------------------------------------------

"
fi
# List already existing VM's and ask for vmID
echo "== Printing list of VM's on this hypervisor!

"
qm list
echo ""
read -p "Please Enter free vm ID to use:" vmID
echo ""
# Create storage dir for VM if needed.
if [ -d /var/lib/vz/images/$vmID ] 
then
    echo "-- VM Directory exists! Ideally try another vm ID!"
    read -p "Please Enter free vm ID to use:" vmID
else
    echo "-- Creating VM image dir!"
    mkdir /var/lib/vz/images/$vmID
fi
# Creating qcow2 image for CHR.
echo "-- Converting image to qcow2 format "
qemu-img convert \
    -f raw \
    -O qcow2 \
    /root/temp/chr-$version.img \
    /var/lib/vz/images/$vmID/vm-$vmID-disk-1.qcow2
# Creating VM
echo "-- Creating new CHR VM"
qm create $vmID \
  --name chr-$version \
  --net0 virtio,bridge=vmbr0 \
  --bootdisk virtio0 \
  --ostype l26 \
  --memory 256 \
  --onboot no \
  --sockets 1 \
  --cores 1 \
  --virtio0 local:$vmID/vm-$vmID-disk-1.qcow2
echo "

############## End of Script ##############"

Useful tips

  • Useful snippet to clean sh file from Windows formatting that may interfere with script if it's edited on Windows workstation: "sed -i -e 's/\r$//' *.sh"