Prevent the incrementing of eth devices on Linux systems after guest customization of a cloned VM

I’ve ran into this issue before and found the following article written by Chris Greene from Orchestration.io.

After the guest customization process runs on cloned VMs in some VMware products, you may notice that on your Linux systems the eth device number gets incremented. For example, when the system is first built, the first eth device will be eth0. If the system is cloned & customized, the eth device will become eth1. This may not be a problem on some systems, but people often need/prefer the first eth device to be eth0 or at least to not change after the system is customized.

The issue arises because of old entries in the udev network file – /etc/udev/rules.d/70-persistent-net.rules. After an initial install of a Linux system that has a NIC with a MAC of “00:50:56:02:00:7c”, /etc/udev/rules.d/70-persistent-net.rules will look something like

When you perform a clone & customization (as in creating a new vApp from a template in vCloud), the source VM is cloned and has NIC with a new MAC address. When the cloned VMs boots, udev notices the new NIC and updates /etc/udev/rules.d/70-persistent-net.rules with the new NIC and gives it the name eth1.

A new file named /etc/sysconfig/network-scripts/ifcfg-eth1 will be created that points to the eth1 device

Now when ifconfig is ran, you will see eth1 instead of eth0.

To prevent the issue from occurring, delete the /etc/udev/rules.d/70-persistent-net.rules file before shutting down the VM and turning it into a template. This will cause a new /etc/udev/rules.d/70-persistent-net.rules to be created when the customizing VM boots up. The new file will only contain the NICs on the system and they should be labelled as eth0, eth1, etc.

Another thing you may want do before shutting the VM down to be added as a template is modify /etc/sysconfig/network-scripts/ifcfg-eth0 so that ONBOOT is set to no (ONBOOT=no). I’ve seen issues in vCloud where multiple vApp templates are being deploying onto the same network and the VMs have the same IP (that was initially on the VM before it was turned into a template). Then the systems boot, ifup is ran, which runs arping. I’ve seen arpping return an error in these situations, which causes VMware tools to not start. This then causes guest customization to fail since VMware tools is relied up by guest customization.

Installing VMware Tools in a Linux Virtual Machine

This section explains how to install VMware Tools in a Linux virtual machine.

To install VMware Tools in a Linux, FreeBSD, or Solaris Virtual Machine

1. Power on the virtual machine.

2. After the guest operating system has started, prepare your virtual machine to install
VMware Tools.

Choose VM > Install VMware Tools.

The remaining steps take place inside the virtual machine.
Note: You can install VMware Tools either from a terminal in an X window session
or in text mode.

3. As root (su -), mount the VMware Tools virtual CD-ROM image, change to a working
directory (for example, /tmp), uncompress the installer, and unmount the CD-ROM image.

Note You do not use an actual CD-ROM to install VMware Tools, and you do not need
to download the CD-ROM image or burn a physical CD-ROM of this image file.
The VMware Server software contains an ISO image that looks like a CD-ROM to
your guest operating system. This image contains all the files needed to
install VMware Tools in your guest operating system.

a) Using the Tar Installer on Linux Guests: Some Linux distributions use different device
names or organize the /dev directory differently. If your CD-ROM drive is not
/dev/cdrom or if the mount point for a CD-ROM is not /mnt/cdrom, modify the following
commands to reflect the conventions used by your distribution.

Also, some Linux distributions automatically mount CD-ROMs. If your distribution uses
automounting, do not use the mount and umount commands below. You still must untar the
VMware Tools installer to /tmp.

mount /dev/cdrom /mnt/cdrom
cd /tmp
tar zxf /mnt/cdrom/vmware-linux-tools.tar.gz
umount /mnt/cdrom
Go to step 4.

b) Using the RPM Installer on Linux Guests: Some Linux distributions use different device
names or organize the /dev directory differently. If your CD-ROM drive is not /dev/cdrom
or if the mount point for a CD-ROM is not /mnt/cdrom, modify the following commands to
reflect the conventions used by your distribution.

Also, some Linux distributions automatically mount CD-ROMs. If your distribution uses
automounting, do not use the mount and umount commands below.

mount /dev/cdrom /mnt/cdrom
cp /mnt/cdrom/vmware-linux-tools-.i386.rpm
/tmp rpm -Uhv /tmp/vmware-linux-tools-.i386.rpm
umount /mnt/cdrom

where is the build number of the VMware Server release.
Go to step 6.

c) Solaris Guests: The Solaris volume manager—vold—mounts the CD-ROM under /cdrom/vmwaretools.
If the CD-ROM is not mounted, restart the volume manager using the following commands:

/etc/init.d/volmgt stop
/etc/init.d/volmgt start

After the CD-ROM is mounted, use the following commands to extract VMware Tools.

cd /tmp
gunzip -c /cdrom/vmwaretools/vmware-solaris-tools.tar.gz | tar xf –Go to step 4.

d) FreeBSD Guests: Some FreeBSD distributions automatically mount CD-ROMs. If your distribution
uses automounting, do not use the mount and umount commands below. You still must untar the
VMware Tools installer to /tmp.

mount /cdrom
cd /tmp
tar zxf /cdrom/vmware-freebsd-tools.tar.gz
umount /cdrom

4. Run the VMware Tools installer.

cd vmware-tools-distrib
./vmware-install.pl

5. Answer the questions about default directories.

6. Run the configuration program.

vmware-config-tools.pl

7. To change your virtual machine’s display resolution, answer yes, and enter the number that
corresponds to the desired resolution.

8. Log off of the root account.

exit

9. Start X and your graphical environment. If you installed VMware Tools in an X windows session, restart X windows.

10. In an X terminal, launch the VMware Tools background application.

vmware-toolbox &

You can run VMware Tools as root or as a normal user. To shrink virtual disks or to change any VMware Tools scripts, you must run VMware Tools as root (su -).

Note: Always run vmware-toolbox in the guest operating system to ensure you have access to all VMware Tools features, such as copy and paste and mouse ungrab for operating systems for which X display driver is not available.

How to Extend LVM Inside a VM

These instructions have been applied to RedHat and CentOS. I have seen some instances, where these instructions broke the VM. (So I make no promises. They worked for me.)

Article: How to Extend LVM Inside a VM

1. Gracefully shutdown virtual machine.
2. SSH into ESX Server as ‘root’ and navigate to the datastore containing the vmdk that you need to extend.
3. vmkfstools -X G virtual.vmdk (Enter the total size of the new HD – 10G)
4. Start virtual machine and open a terminal window.
5. fdisk /dev/sda (if only 1 disk on linux)
6. in fdisk, create new partition with new freespace (n,new partition#,start,stop)
7. in fdisk, change new partition type to 8e (linux lvm)(t,new partition#,8e)
8. in fdisk print out partition table to verify (p)
9. in fdisk write partition and exit (w)
10. partprobe (shouldn’t be necessary, but rereads partitions)
11. pvcreate /dev/sda3 (if new partition is 3rd partition)
12. vgextend VolumeGroupName /dev/sda3 (add new partition to VG)
13. lvextend -L+1G /dev/VolGroup00/LogVol00 (assuming LogVol00 is lv you wish to grow)
14. ext2online /dev/VolGroup00/LogVol00 (extend an ext3 partition to fill the LV)
(if you want a specific size: ext2online -L10G /dev/VolGroup00/LogVol00)
(if you want to grow a specific size: ext2online -L+1G /dev/VolGroup00/LogVol00)
(Some OSes (CentOS) uses resize2fs: ex. resize2fs /dev/VolGroup00/LogVol00.)
15. sync