This script is specific to my setup which has two NICs one using the Microsoft Hyper-V Synthetic Ethernet Driver and one using the normal driver.

I haven’t tested this script out yet so there may be typos

#!/bin/bash

if [ -e /root/tools/upgrade-kernel.state ]; then
  eval `cat /root/tools/upgrade-kernel.state`
fi


if [ ! -e /root/tools/upgrade-kernel.state -o "$state" = "phase2 of kernel update complete" ]; then
    echo "Updating kernel"
    echo "state=\"about to update kernel\"" >/root/tools/upgrade-kernel.state
    if yum update -y kernel kernel-devel kernel-headers; then
      echo "state=\"kernel updated\"" >/root/tools/upgrade-kernel.state
    else
      echo "kernel update failed"
      echo "state=\"kernel failed update\"" >/root/tools/upgrade-kernel.state
      exit 1
    fi

    echo "Removing 'hda=noprobe hdb=noprobe' from all kernel entries in the boot menu"
    echo "state=\"about to remove 'hda=noprobe hdb=noprobe' from the boot menu\"" >/root/tools/upgrade-kernel.state
    if sed -i -e 's/LogVol00 hda=noprobe hdb=noprobe/LogVol00/g' /boot/grub/menu.lst; then
      echo "state=\"removed 'hda=noprobe hdb=noprobe' from the boot menu\"" >/root/tools/upgrade-kernel.state
    else
      echo "failed to modify boot menu"
      echo "state=\"failed to modify boot menu\"" >/root/tools/upgrade-kernel.state
      exit 1
    fi

    echo "Enabling eth0 onboot and disabling seth0 onboot"
    echo "state=\"about to enable eth0 and disable seth0\"" >/root/tools/upgrade-kernel.state
    if sed -i -e 's/#ONBOOT=yes/ONBOOT=yes/gi' -e 's/ONBOOT=no/#ONBOOT=no/gi' /etc/sysconfig/network-scripts/ifcfg-eth0 &&
          sed -i -e 's/#ONBOOT=no/ONBOOT=no/gi' -e 's/ONBOOT=yes/#ONBOOT=yes/gi' /etc/sysconfig/network-scripts/ifcfg-seth0; then
       echo "state=\"enabled eth0 and disabled seth0\"" >/root/tools/upgrade-kernel.state
    else
      echo "failed to enable eth0 and disable seth0 onboot"
      echo "state=\"failed to enable eth0 and disable seth0 onboot\"" >/root/tools/upgrade-kernel.state
      exit 1
    fi

    echo "Press ENTER to reboot"
    read a
    echo "state=\"phase1 of kernel update complete\"" >/root/tools/upgrade-kernel.state
    reboot
elif [ "$state" == "phase1 of kernel update complete" ]; then
    echo "Buildind vm tools"
    echo "state=\"about to build vm tools\"" >/root/tools/upgrade-kernel.state
    if cd /opt/linux_ic && make && make install; then
      echo "state=\"vm tools built\"" >/root/tools/upgrade-kernel.state
    else
      echo "failed to build vm tools"
      echo "state=\"failed to build vm tools\"" >/root/tools/upgrade-kernel.state
      exit 1
    fi

    echo "Enabling seth0 onboot and disabling eth0 onboot"
    echo "state=\"about to enable seth0 and disable eth0\"" >/root/tools/upgrade-kernel.state
    if sed -i -e 's/#ONBOOT=yes/ONBOOT=yes/gi' -e 's/ONBOOT=no/#ONBOOT=no/gi' /etc/sysconfig/network-scripts/ifcfg-seth0 &&
          sed -i -e 's/#ONBOOT=no/ONBOOT=no/gi' -e 's/ONBOOT=yes/#ONBOOT=yes/gi' /etc/sysconfig/network-scripts/ifcfg-eth0; then
       echo "state=\"enabled seth0 and disabled eth0\"" >/root/tools/upgrade-kernel.state
    else
      echo "failed to enable seth0 and disable eth0 onboot"
      echo "state=\"failed to enable seth0 and disable eth0 onboot\"" >/root/tools/upgrade-kernel.state
      exit 1
    fi

    echo "Press ENTER to reboot"
    read a
    echo "state=\"phase2 of kernel update complete\"" >/root/tools/upgrade-kernel.state
    reboot
else
    "Error : Stopping because state is \"$state\""
    exit 1
fi