Applicable to:
- SolusVM
Question
How to create a custom Linux SolusVM KVM template?
Answer
- Remove all user accounts and their home directories from source VPS.
In Linux systems there are system accounts and user accounts. By default user account have UID from 1000 to 65534. All users are listed in the file /etc/passwd in format:CONFIG_TEXT: USERNAME:x:UID:GID:description:HOMEDIR:SHELL
To remove user use the following command:
# deluser --remove-all-files USERNAME
- Remove all SSH keys from the source VPS.
For generation 2 templates this procedure is covered by step 4.
For generation 1 templates run the following command on source VPS:# rm /etc/ssh/ssh_host_*
Generation 1 templates are fixed-size byte by byte images. Generation 1 templates should be used if it is required to create a special template that either includes obscure partitions or filesystems that cannot be manipulated from the host node. These include, but are not limited to, FreeBSD (Unix) or logical partitions. Generation 1 templates can have networking setup by SolusVM, however, any filesystem resizing should be scripted inside the template.
-
Prepare a source VPS from which template will be created.
Note: the size of source VPS has to be as small as possible as template will have the size of the source logical volume.
-
Shutdown the server in SolusVM > Virtual Servers > the necessary VPS (note its VMID, for example, kvm101)
On the slave server where the VPS is hosted:
-
Execute the following command to create a template:
# /scripts/kvmtemplate --mode=package --vmid=kvm101 --generation=1
once the script is finished, the location of the created template will be displayed:
# Template: /home/solusvm/kvm/template/template-149fee41d5801f96368c959a00dd6092a56ba031.gz
-
Rename the template:
# mv /home/solusvm/kvm/template/template-149fee41d5801f96368c959a00dd6092a56ba031.gz /home/solusvm/kvm/template/linux-centos-7-x86_64-custom-gen1-v1.gz
-
Upload the created template to the Master server into the same template location:
# /home/solusvm/kvm/template/linux-centos-7-x86_64-custom-gen1-v1.gz
Generation 2 templates are far more flexible than generation 1 templates with respect to filesystem resizing and configuration. Generation 2 templates should be used if the template will use standard filesystems ( ext3 or ext4). Generation 2 templates do not currently support logical volumes or extended partitions, generation 1 templates should be used for that.
Note: for Debian 9/Ubuntu 18 templates ext3 file system should be selected for the data partition. Otherwise, some feature will be not available on CentOS 6 host node.
-
Prepare a source VPS from which template will be created.
-
Shutdown the server in SolusVM > Virtual Servers > the necessary VPS (note its VMID, for example, kvm123):
How to shutdown VPS and find its VMID: -
Check partition table in the source VPS kvm123 to determine which partition should be resizable in the future - the necessary partition contains OS of the VPS/template:
# /scripts/kvmtemplate --mode=prescan --vmid=kvm123 --generation=2
Name Type VFS Label MBR Size Parent UUID
/dev/sda1 filesystem ext4 - - 20G - 23261380-2181-4fee-bf1a-b7235d2b9ad9
/dev/sda2 filesystem swap - - 99M - d0bc2596-74ae-45b2-b2d4-d59f06b54d07
/dev/sda1 partition - - 83 20G /dev/sda -
/dev/sda2 partition - - 82 99M /dev/sda -
/dev/sda device - - - 20G - -In most cases, the partition to resize is the biggest partition. In the example above the biggest partition is
/dev/sda1
, so the partition to resize will be 1. Partition/dev/sd2
is SWAP. -
Prepare the source VPS for template creation by removing any SSH keys, mac addresses, and udev rules:
Note: this procedure is not foolproof. VPS should be prepared manually to verify that all history is removed and configuration files are clean. Also
/etc/fstab
should be correct and any UUIDS are removed if this is a Linux virtual server.# /scripts/kvmtemplate --mode=prepare --vmid=kvm123 --generation=2
-
Create the template:
# /scripts/kvmtemplate --mode=package --vmid=kvm123 --generation=2
the output of the command will contain the location of the created template:
# Template: /home/solusvm/kvm/template/template-149fee41d5801f96368c959a00dd6092a56ba031.gz
-
Rename the template:
# mv /home/solusvm/kvm/template/template-149fee41d5801f96368c959a00dd6092a56ba031.gz /home/solusvm/kvm/template/linux-centos-6-x86_64-custom-gen2-v1.gz
SVM_WARN: template name has to start with "linux", as in the example above - "linux-centos-6-x86_64-custom-gen2-v1.gz".
-
Upload the created template to the Master server into the same template location:
# /home/solusvm/kvm/template/linux-centos-6-x86_64-custom-gen2-v1.gz
-
SVM_WARN: Set the partition to resize and SWAP according to step 4.
Comments
0 commentsPlease sign in to leave a comment.