- Buat folder /root/temp
- Buat file misal chr.sh di folder tersebut
- Masukan bash script berikut
#!/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 ##############"
- Buat chmod a+x chr.sh
- ./chr.sh atau sh chr.sh
- Nanti tinggal pilih versi chr dan VM id
- Setelah itu tinggal running VM nya , lalu tinggal setting IP untuk CHR nya
- source bisa liat di : https://wiki.mikrotik.com/wiki/Manual:CHR_ProxMox_installation