#!/bin/bash # DATE: 08/12/2018 Updated for LVM by Brijendra Sial at Bullten Web Hosting Solutions to Works with Centos 7 # and may work for Centos 6 Based on partition Table. # This script serves the purpose to work with Modules Factory Proxmox module # for WHMCS to do the following things: # Please note the following things before using this script: # 1. This script assumes the KVM template image files are located at # /var/lib/vz/images/xxx, where xxx is the numeric vmid; # 2. This script assumes qemu-nbd is installed on the Proxmox host; # 3. The virtual machine needs a reboot for the setup to be effective. IN=$@ IFS=',' read varvmid varhostname varusername varpassword varmac varip varnode <<< "$IN";IFS='=' read var1 vmid <<< "$varvmid";IFS='=' read var2 hostname <<< "$varhostname";IFS='=' read var3 password <<< "$varpassword";IFS='=' read var4 username <<< "$varusername";IFS='=' read var5 macs <<< "$varmac";IFS='=' read var6 ips <<< "$varip";IFS='=' read var7 node <<< "$varnode" mp=$((vmid%10)) cd "/var/lib/vz/images/${vmid}" mkdir -p a qemu-nbd -c /dev/nbd${mp} vm-${vmid}* pvscan --cache /dev/nbd${mp}p2 vgscan lvscan vgchange -ay mount /dev/centos/root a cd a IFS=' ' read ip restip <<< $ips IFS=' ' read mac restmac <<< $macs gw=217.182.175.254 mask=255.255.255.255 ns1=213.186.33.99 ns2=8.8.8.8 # Set network # Redhat & derivatives (CentOS, Scientific Linux, ClearOS...) if [ -f usr/bin/yum ]; then cat > etc/sysconfig/network-scripts/ifcfg-eth0 << EOF DEVICE=eth0 BOOTPROTO=none ONBOOT=yes USERCTL=no IPV6INIT=no PEERDNS=yes TYPE=Ethernet NETMASK=$mask IPADDR=$ip GATEWAY=$gw ARP=yes HWADDR=$mac EOF cat > etc/sysconfig/network-scripts/route-eth0 << EOF $gw dev eth0 default via $gw dev eth0 EOF IFS=' ' read -ra ip <<< $restip for i in ${!ip[*]}; do cat > etc/sysconfig/network-scripts/ifcfg-eth0:$i <<- EOF DEVICE="eth0:$i" ONBOOT="yes" BOOTPROTO="none" IPADDR="${ip[$i]}" NETMASK="$mask" BROADCAST="${ip[$i]}" EOF done # DNS cat > etc/resolv.conf << EOF nameserver $ns1 nameserver $ns2 EOF fi cd .. umount a vgchange -a n centos qemu-nbd -d /dev/nbd${mp} rm -r a

Network Setup Script for LVM Based KVM
Started by
Brijendra Sial
, Dec 08 2018 03:43 PM
No replies to this topic
#1
Posted 08 December 2018 - 03:43 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users