Differences between revisions 14 and 27 (spanning 13 versions)
Revision 14 as of 2017-11-11 22:05:00
Size: 1514
Editor: shran
Comment:
Revision 27 as of 2017-12-08 14:04:59
Size: 1920
Comment:
Deletions are marked like this. Additions are marked like this.
Line 9: Line 9:
`clonedomain.sh` `domain_clone.sh`
Line 40: Line 40:
./clonedomain.sh clone ./domain_clone.sh clone
Line 43: Line 43:
== Cleanup == == Console Access ==
Line 45: Line 45:
=== Hostname === Remove console access by [[Domain Editing|editing the domain]].
Line 47: Line 47:
Your new system will need a new hostname == Memory ==
Line 49: Line 49:
 * /etc/hostname
 * /etc/hosts
Increase or decrease amount of memory by [[Domain Editing|editing the domain]].
Line 52: Line 51:
{{{
sed -i 's/stretch-template/clone/g' /etc/hosts
sed -i 's/stretch-template/clone/g' /etc/hostname
}}}
== Unique keys for ssh ==
Line 57: Line 53:
=== sshd ===

Make sure the ssh public/private keys are unique.
Make sure your clone does indeed have unique ssh keys. This is a really important step when cloning. Consider all your clones had the same ssh keys, that qould really be a mess.
Line 64: Line 58:
service sshd restart
Line 65: Line 60:

== Hostname ==

Change the hostname of your new guest.

{{{
cp /etc/hosts /etc/hosts.bak
sed -i "s/stretch-template/clone/g" /etc/hosts
cp /etc/hostname /etc/hostname.bak
sed -i "s/stretch-template/clone/g" /etc/hostname
}}}

== root password ==
{{{
passwd
}}}

Domain Cloning

Once a template system has been installed, that system can be cloned. virt-clone will automatically change the MAC address of your network device.

Cloning

Use the script below to clone your template.

domain_clone.sh

   1 #!/bin/sh
   2 
   3 LVM_GROUP="vg2"
   4 NAME_ORIGINAL="stretch-template"
   5 LVM_NAME_ORIGINAL="kvm_${NAME_ORIGINAL}_vda"
   6 LVM_SIZE_ORIGINAL=`lvs /dev/${LVM_GROUP}/${LVM_NAME_ORIGINAL} -o LV_SIZE --noheadings --units B --nosuffix`
   7 NAME_CLONE="stretch-clone"
   8 LVM_NAME_CLONE="kvm_${NAME_CLONE}_vda"
   9 
  10 if [ $# -gt 0 ]
  11 then
  12         NAME_CLONE=${1}
  13         LVM_NAME_CLONE="kvm_${NAME_CLONE}_vda"
  14 fi
  15 
  16 if [ ! -e /dev/${LVM_GROUP}/${LVM_NAME_CLONE} ]
  17 then
  18         # create lvm partition
  19         lvcreate --size ${LVM_SIZE_ORIGINAL}B --name ${LVM_NAME_CLONE} ${LVM_GROUP}
  20 
  21         # clone the domain
  22         virt-clone --original ${NAME_ORIGINAL} --name ${NAME_CLONE} --file /dev/${LVM_GROUP}/${LVM_NAME_CLONE} --check path_in_use=off,path_exists=off
  23 else
  24         echo "${0}: refusing to overwrite existing domain"
  25 fi

Make a clone.

./domain_clone.sh clone

Console Access

Remove console access by editing the domain.

Memory

Increase or decrease amount of memory by editing the domain.

Unique keys for ssh

Make sure your clone does indeed have unique ssh keys. This is a really important step when cloning. Consider all your clones had the same ssh keys, that qould really be a mess.

rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server
service sshd restart

Hostname

Change the hostname of your new guest.

cp /etc/hosts /etc/hosts.bak
sed -i "s/stretch-template/clone/g" /etc/hosts
cp /etc/hostname /etc/hostname.bak
sed -i "s/stretch-template/clone/g" /etc/hostname

root password

passwd

None: Domain Cloning (last edited 2021-12-31 14:57:50 by Kristian Kallenberg)