Differences between revisions 1 and 23 (spanning 22 versions)
Revision 1 as of 2017-10-12 22:50:14
Size: 1032
Editor: shran
Comment:
Revision 23 as of 2017-11-11 22:45:20
Size: 1794
Editor: shran
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Once a template system has been installed, that system can be cloned. Use the following script to clone your template Once a template system has been installed, that system can be cloned. `virt-clone` will automatically change the MAC address of your network device.
Line 5: Line 5:
`clonedomain.sh`
{{{
== Cloning ==

Use the script below to clone your template.

`domain_clone.sh`
{{{#!highlight bash
Line 10: Line 14:
Line 17: Line 20:

if [ $# -eq 0 ]
if [ $# -gt 0 ]
Line 20: Line 22:
        echo "${0}: domain-name"
else
Line 36: Line 36:
}}}
Line 37: Line 38:
Make a clone.
{{{
./domain_clone.sh clone
Line 38: Line 42:

== Cleanup ==

=== Hostname ===

Your new system will need a new hostname

 * /etc/hostname
 * /etc/hosts

{{{
sed -i 's/stretch-template/clone/g' /etc/hosts
sed -i 's/stretch-template/clone/g' /etc/hostname
}}}

=== sshd ===

Make sure the ssh keys are unique.

{{{
rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server
}}}

=== Root Password ===

Reset your root passwd.

{{{
passwd
}}}

== Update ==

Since the template can be quite old, you might as well update it.

{{{
apt-get update
apt-get upgrade
}}}

== Console Access ==

Remove console access by [[Domain Editing|editing the domain]].

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

Cleanup

Hostname

Your new system will need a new hostname

  • /etc/hostname
  • /etc/hosts

sed -i 's/stretch-template/clone/g' /etc/hosts
sed -i 's/stretch-template/clone/g' /etc/hostname

sshd

Make sure the ssh keys are unique.

rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server

Root Password

Reset your root passwd.

passwd

Update

Since the template can be quite old, you might as well update it.

apt-get update
apt-get upgrade

Console Access

Remove console access by editing the domain.

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