Last active
February 18, 2018 21:54
-
-
Save td512/c7ed96ecf7fb2e6573947a57894985f1 to your computer and use it in GitHub Desktop.
Quickly converts physical machines to VZ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Monarch Solutions VZ conversion script | |
CTID=$1 | |
HOST=$2 | |
IP=$3 | |
NS=$4 | |
echo "Starting VZ conversion, CTID $CTID" | |
echo "Host node: $HOST" | |
echo "CT IP: $IP" | |
echo "CT NS: $NS" | |
echo "Creating CT with ID $CTID" | |
vzctl create $CTID --ostemplate centos-6-x86-minimal | |
vzctl set $CTID --ipadd $IP --save | |
vzctl set $CTID --nameserver $NS --save | |
vzctl start CTID | |
vzctl stop $CTID | |
echo "Recreating CT $CTID private" | |
rm -rf /vz/private/$CTID | |
mkdir /vz/private/$CTID | |
echo "Starting RSYNC from $HOST to CT $CTID" | |
rsync -arvpz --exclude=/dev --exclude=/mnt --exclude=/proc --exclude=/sys --exclude=/tmp -e ssh root@$HOST:/ /vz/private/$CTID/ | |
clear | |
echo "Setting up special devices for CT $CTID" | |
sed -i -e 's/^[0-9].*getty.*tty/#&/g' /vz/private/$CTID/etc/inittab | |
echo "none /dev/pts devpts rw 0 0" > /vz/private/$CTID/etc/fstab | |
mkdir /vz/private/$CTID/dev | |
mkdir /vz/private/$CTID/mnt | |
mkdir /vz/private/$CTID/proc | |
mkdir /vz/private/$CTID/sys | |
mkdir /vz/private/$CTID/tmp | |
mkdir /vz/private/$CTID/dev/pts | |
mkdir /vz/private/$CTID/etc/udev/devices | |
/sbin/MAKEDEV -d /vz/private/$CTID/dev -x {p,t}ty{a,p}{0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f} console core full kmem kmsg mem null port ptmx random urandom zero ram0 | |
/sbin/MAKEDEV -d /vz/private/$CTID/etc/udev/devices -x {p,t}ty{a,p}{0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f} console core full kmem kmsg mem null port ptmx random urandom zero ram0 | |
chmod 1777 /vz/private/$CTID/tmp | |
chmod 1777 /vz/private/$CTID/var/tmp | |
echo "Disabling networking and setting up repos on CT $CTID" | |
sed -i 's/ONBOOT=yes/ONBOOT=no/g' /vz/private/$CTID/etc/sysconfig/network-scripts/ifcfg-eth* | |
cat >/vz/private/$CTID/etc/yum.repos.d/vz.repo <<EOF | |
[vz-base] | |
name=vz-base | |
mirrorlist=http://vzdownload.swsoft.com/download/mirrors/redhat-el6 | |
gpgcheck=0 | |
[vz-updates] | |
name=vz-updates | |
mirrorlist=http://vzdownload.swsoft.com/download/mirrors/updates-released-rhel6 | |
gpgcheck=0 | |
EOF | |
echo "All done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment