CentOS 7 1511 Minimal oVirt Template - rharmonson/richtech GitHub Wiki
CentOS 7 1511 Minimal oVirt Template
Revised: November 16, 2016; add 'yum clean all' to sealvm.sh
Revised: November 12, 2016; added sealvm.sh & update cloud-init
Revised: October 18, 2016; clarified 'sys-unconfig'
Revised: August 15, 2016
The purpose of this article is to describe the process to create a CentOS 7 1511 Minimal oVirt virtual machine for cloning to a template.
Complete you base installation and configuration before completing the tasks described in this article. My base installation guide for CentOS 7 1511 can be found here:
https://github.com/rharmonson/richtech/wiki/CentOS-7-1511-Minimal-x86_64-Base-Installation-Guide
Process
- Update hostname
- Clear machine-id; deletion is problematic next boot
- Delete SSH host keys
- Replace ifcfg-eth0 PREFIX with NETMASK
- Edit ifcfg-eth0 to remove unnecessary values including HWADD
- Delete logs
- Install ovirt-guest-agent-common
- Complete any additional desired configurations or installations.
- (Install cloud-init; optional)
- sys-unconfig (clears host specific information then poweroff)
- Convert virtual machine to template
- Deploy virtual machine using template
Execute
Update the hostname to something generic (optional)
[root@centos7 ~]# hostnamectl set-hostname localhost.localdomain
[root@centos7 ~]# hostnamectl
Static hostname: localhost.localdomain
Icon name: computer-vm
Chassis: vm
Machine ID: 7c84b8bda6e941f1ba4f6eb552ec8659
Boot ID: f17bc3fb1b524cf18d4cfd22686281a2
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.28.2.el7.x86_64
Architecture: x86-64
Clear the machine-id.
[root@centos7 ~]# > /etc/machine-id
Clear host SSH keys and /root/.
[root@centos7 ~]# rm -f /etc/ssh/ssh_host_*
[root@centos7 ~]# rm -rf /root/.ssh/
[root@centos7 ~]# rm -f /root/anaconda-ks.cfg
[root@centos7 ~]# rm -f /root/.bash_history
[root@centos7 ~]# unset HISTFILE
Network Interface
Remove the HWADDR=
line from /etc/sysconfig/network-scripts/ifcfg-eth0
. Note that oVirt using cloud-init does not support PREFIX so update the ifcfg to use the equivalent NETMASK. If using static, I remove all items except, TYPE, BOOTPROTO, DEVICE, ONBOOT, IPADDR, NETMASK, and GATEWAY. Altenatively, use DHCP which result with:
TYPE=Ethernet
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
Clear logs
rm -f /var/log/boot.log
rm -f /var/log/cron
rm -f /var/log/dmesg
rm -f /var/log/grubby
rm -f /var/log/lastlog
rm -f /var/log/maillog
rm -f /var/log/messages
rm -f /var/log/secure
rm -f /var/log/spooler
rm -f /var/log/tallylog
rm -f /var/log/wpa_supplicant.log
rm -f /var/log/wtmp
rm -f /var/log/yum.log
rm -f /var/log/audit/audit.log
rm -f /var/log/ovirt-guest-agent/ovirt-guest-agent.log
rm -f /var/log/tuned/tuned.log
Install oVirt repository, install ovirt agent, and enable it.
[root@centos7 ~]# yum install -y http://resources.ovirt.org/pub/yum-repo/ovirt-release36.rpm
[root@centos7 ~]# yum install ovirt-guest-agent-common
[root@centos7 ~]# systemctl enable ovirt-guest-agent
Cloud Init (OPTIONAL)
Install cloud-init package if desired. I experimented with cloud-init. I had mixed results for Fedora but for CentOS 7.2.1511, it worked beautifully. Remember to enable the service as shown below. Also, I suspect DHCP is a dependency but not taken the time to test.
[root@centos7 ~]# yum install cloud-init
[root@centos7 ~]# systemctl enable cloud-init
Flag as unconfigured (and poweroff).
[root@centos7 ~]# sys-unconfig
Ready to create template!
Seal Script
Peridocially, I update the templates with updates and configuration changes. I use a script to reseal the virtual machine, sealvm.sh.
yum clean all
> /etc/machine-id
rm -f /etc/ssh/ssh_host
rm -rf /root/.ssh/
rm -f /root/anaconda-ks.cfg
rm -f /root/.bash_history
unset HISTFILE
rm -f /var/log/boot.log
rm -f /var/log/cron
rm -f /var/log/dmesg
rm -f /var/log/grubby
rm -f /var/log/lastlog
rm -f /var/log/maillog
rm -f /var/log/messages
rm -f /var/log/secure
rm -f /var/log/spooler
rm -f /var/log/tallylog
rm -f /var/log/wpa_supplicant.log
rm -f /var/log/wtmp
rm -f /var/log/yum.log
rm -f /var/log/audit/audit.log
rm -f /var/log/ovirt-guest-agent/ovirt-guest-agent.log
rm -f /var/log/tuned/tuned.log
sys-unconfig