Skip to content

Instantly share code, notes, and snippets.

@gardart
Last active March 23, 2023 22:27
Show Gist options
  • Save gardart/30b788867f759df071c5fc35f2d2a933 to your computer and use it in GitHub Desktop.
Save gardart/30b788867f759df071c5fc35f2d2a933 to your computer and use it in GitHub Desktop.
Golden image for RHEL7 on Hyper-V (VMM)

Step 1: Create build and capture machine for RHEL7 Step 2: Update machine, install packages Step 3: Create checkpoint Step 4: Sysprep Step 5: Copy vhdx file to your VMM library Step 6: Create template from your last BAC vhdx file Step 7: Revert to checkpoint created yearlier

To update RHEL7 template start at Step 3 and down to step 7.

Step 1

Download RHEL 7.3 image http://example.com/rhel-server-7.3-x86_64-dvd.iso Copy to your VMM library folder (\vmm_server\MSSCVMMLibrary) and refresh the library

Create build and capture virtual machine (Gen2) in VMM called BAC-RHEL7-G2-1603. Specs:

  • 1G ram
  • GEN 2
  • Secure boot disabled
  • Dynamic virtual disk, 10GB
  • High availability
  • select RHEL7 iso as your cdrom
  • select Operating System as "Red Hat Enterprise Linux 7 (64bit)"

Create and power up your new BAC machine, BAC-RHEL7-G2-1603.

Install OS to your machine with minimal install

Step 2

Register with RH subscription manager and enable some repos

subscription-manager register [email protected] --password=Password --auto-attach
subscription-manager repos --enable=rhel-7-server-extras-rpms
subscription-manager repos --enable=rhel-7-server-optional-rpms
yum install -y epel-release

Update the system

yum update -y
yum clean all

Install some dep packages

yum install -y policycoreutils net-tools wget telnet git yum-utils zip unzip htop python-setuptools vim

Install Hyper-V daemons

yum install -y hyperv-daemons

Install Microsoft Azure Linux Agent

yum install -y WALinuxAgent

OPTIONAL: Install Microsoft Azure Linux Agent from source (or build/install rpm)

yum install -y python-setuptools
cd /tmp
wget https://github.com/Azure/WALinuxAgent/archive/v2.2.14.zip
unzip v2.2.14.zip
cd WALinuxAgent-2.2.14
python setup.py install --register-service

Install VMM Agent for Linux. Find the correct files on your VMM server under => "C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\agents\Linux". Copy all the files from this directory to the /tmp folder on your BAC machine.

# This assumes that install and scvmmguestagent files are already under /tmp folder
cd /tmp
chmod +x install
./install scvmmguestagent.1.0.2.1075.x64.tar
... 03/15/17 21:12:25 UTC Installing SCVMM Guest Agent to /opt/microsoft/scvmmguestagent
... 03/15/17 21:12:25 UTC Successfully installed SCVMM Guest Agent

Install init scripts cd /opt git clone https://github.com/gardart/Provisioning.git

Step 3 - Create checkpoint (save before sysprepping)

In your VMM console, create checkpoint named BAC-RHEL7-G2-1603

Step 4 - Sysprep

Stop services

service rsyslog stop
service auditd stop

Cleanup

package-cleanup --oldkernels --count=1
yum clean all

Force the logs to rotate & remove old logs

logrotate -f /etc/logrotate.conf
rm -f /var/log/*-???????? /var/log/*.gz
rm -f /var/log/dmesg.old
rm -rf /var/log/anaconda

Truncate the audit logs (and other logs we want to keep placeholders for).

/bin/cat /dev/null > /var/log/audit/audit.log
/bin/cat /dev/null > /var/log/wtmp
/bin/cat /dev/null > /var/log/lastlog
/bin/cat /dev/null > /var/log/grubby

Remove the history

/bin/rm -f ~root/.bash_history
unset HISTFILE

Clean /tmp out

/bin/rm -rf /tmp/*
/bin/rm -rf /var/tmp/*

Sysprep/Deprovision

subscription-manager unregister
waagent -deprovision
init 0

Create VMM Template for RHEL7

Create Guest OS Template

Set RunOnce command Add the init script that configures system at initial startup. Init script configures static ipaddress, gateway, dns and registers with Puppet. It also updates the system. /bin/sh -c "chmod +x /opt/Provisioning/rhel7/init.sh && /bin/sh /opt/Provisioning/rhel7/init.sh -d"

Create Hardware Template

Create Virtual machine template

First clone or export your BAC machine for backup Next create new template from this machine (this will delete the machine)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment