HPVM Mass Production with hpvmclone

This post is about cloning HP-UX virtual machines, or HPVMs.

Once you have built an HPVM, the hpvmclone command can be used to produce many more.  hpvmclone does not create a copy of the HPVM, it just creates a copy of the configuration.  The data copy is done manually, for example with the dd command.

Basic HPVM Cloning

The following procedure is a simplified version of that found on Juanma’s Blog, in the section “Method 1”.

Clone an existing, installed HPVM called “oldhpvm” to create another called “newhpvm”.  The new HPVM is created in the same LVM volume group as oldhpvm.  First, create a logical volume to act as the root disk.  The size chosen in this case is 35Gb, and should be the same size as oldhpvm’s root device:

hostA # lvcreate -L 35840 -n newhpvm_root /dev/vghpvm

“hostA” is the name of the system parenting, or hosting the HPVM.  Shut down oldhpvm and copy the boot disk, which contains HP-UX:

hostA # hpvmstop -P oldhpvm
hostA # dd if=/dev/vghpvm/oldhpvm_root of=/dev/vghpvm/rnewhpvm_root bs=1024k

Issue the hpvmclone command.  The “-d” option removes the old root device.  “-a” adds the new root device.  “-B” tells the new HPVM not to auto-boot on start up.


hostA # hpvmclone -P oldhpvm -N newhpvm -d disk:aviostor::lv:/dev/vghpvm/oldhpvm_root
-a disk:aviostor::lv:/dev/vghpvm/rnewhpvm_root
-B manual

Start the new HPVM with hpvmstart

hostA # hpvmstart -P newhpvm

On booting for the first time, the new HPVM will say something about not recognizing its root physical volume (PV), will then scan the new PV, and accept the new PV as part of its root volume group.

Golden HPVM

The new HPVM an be taken into use immediately.  However it is more useful to tweak the newhpvm, turning it into a “vanilla” system, and then use it to make more HPVM clones.  Newhpvm can then be reserved as a kind of “golden image”, an HPVM whose only purpose is to be cloned.

Log into the new HPVM.  Edit /etc/hosts and /etc/rc.config.c/netconf.  Remove all of the IP addresses and default gateway information.  At this time, make any other changes to the configuration that may be desirable for your site.  For example, set the timezone and root password. Create any user accounts  that you want to be present on all the HPVM clones.  Since the networking information has been removed, this system and clones made from it will not be networked, and can be booted on the same network with impunity.


hostA # hpvmconsole -P newhpvm
newhpvm# vi /etc/hosts
newhpvm# vi /etc/rc.config.d/netconf

Stop the HPVM
hostA # hpvmstop -P newhpvm

Create Many Clones

Many HPVMs can now be created.  Create four right away, called hpvm1, hpvm2, hpvm3, hpvm4.  They are all to reside in volume group vghpvm, which will need at least 140 Gb of available space.

Create the boot disk LVM volumes:


hostA # lvcreate -L 35840 -n hpvm1_root /dev/vghpvm
hostA # lvcreate -L 35840 -n hpvm2_root /dev/vghpvm
hostA # lvcreate -L 35840 -n hpvm3_root /dev/vghpvm
hostA # lvcreate -L 35840 -n hpvm4_root /dev/vghpvm

Copy the data from newhpvm to each new root device:


hostA # dd if=/dev/vghpvm/rnewhpvm_root of=/dev/vghpvm/rhpvm1_root bs=1024k
hostA # dd if=/dev/vghpvm/rnewhpvm_root of=/dev/vghpvm/rhpvm2_root bs=1024k
hostA # dd if=/dev/vghpvm/rnewhpvm_root of=/dev/vghpvm/rhpvm3_root bs=1024k
hostA # dd if=/dev/vghpvm/rnewhpvm_root of=/dev/vghpvm/rhpvm4_root bs=1024k

Perform the clone:


hostA # hpvmclone -P newhpvm -N hpvm1 -d disk:aviostor::lv:/dev/vghpvm/rnewhpvm_root -a disk:aviostor::lv:/dev/vghpvm/hpvm1_root -B manual
hostA # hpvmclone -P newhpvm -N hpvm2 -d disk:aviostor::lv:/dev/vghpvm/rnewhpvm_root -a disk:aviostor::lv:/dev/vghpvm/hpvm2_root -B manual
hostA # hpvmclone -P newhpvm -N hpvm3 -d disk:aviostor::lv:/dev/vghpvm/rnewhpvm_root -a disk:aviostor::lv:/dev/vghpvm/hpvm3_root -B manual
hostA # hpvmclone -P newhpvm -N hpvm4 -d disk:aviostor::lv:/dev/vghpvm/rnewhpvm_root -a disk:aviostor::lv:/dev/vghpvm/hpvm4_root -B manual

Start each new HPVM.  Log in to each HPVM.  Edit /etc/hosts and /etc/rc.config.d/netconf.  The hostname on each is still “newhpvm”.  Change it to the appropriate hostname.  Add in the correct IP address(es) and default gateway information for your site.


hostA # hpvmconsole -P hpvm1
hpvm1# vi /etc/hosts
hpvm1# vi /etc/rc.config.d/netconf

Lastly, reboot the HPVM.  Et voila!  It should come up with its new hostname and correct networking information.

Remote HPVM Cloning

A “golden image” HPVM was created with the above procedure.  Clones from it can be deployed onto other HPVM hosts just as easily.  In this procedure, the “golden image” HPVM, called “newhpvm”, is copied to the new system, and thereafter used to build more clones.

Log in to the target host.  Create a volume group to house the HPVMs and a 35 Gb logical volume (in this case) to act as the root device of the first HPVM to be created.  The target system in this case is called “hostB”.


hostB # vgcreate <whatever> /dev/vghpvm
hostB # lvcreate -L 35840 -n newhpvm_root /dev/vghpvm

In this case, the volume group on hostB has the same name as the volume group on hostA – /dev/vghpvm.

Back on hostA, Make sure newhpvm (the “golden” HPVM) is shut down.  Copy its boot device over the network to hostB, where it will be used to make another clone:

hostA # hpvmstop -P newhpvm
hostA# dd if=/dev/vghpvm/rnewhpvm_root bs=1024k | ssh -l root hostB "dd of=/dev/vghpvm/rnewhpvm_root bs=1024k"
Password:
35840+0 records in
35840+0 records out

The copy took about 23 minutes on my network.

Create the “Golden Image” on the Remote System

On hostB, create an HPVM and associate it with the root device just copied.
hostB # hpvmcreate -P newhpvm -O hpux -c 2 -r 4g
hostB # hpvmmodify -P newhpvm -a disk:aviostor::lv:/dev/vghpvm/rnewhpvm_root

Start the HPVM and open a console to it.

hostB # hpvmstart -P newhpvm
hostB # hpvmconsole -P newhpvm

Again, it will initially complain about being unable to activate the root  volume group, then it will do an LVM scan of the root disk, then the root volume  group will be successfully activated.  This is presumably caused by path of the  root disk changing, or the volume group ID.

The new HPVM will boot up to the EFI shell level but probably no further.  Sadly, it does not know the path of its own root disk.  Set the disk path with this nifty procedure, borrowed from Juanma’s Blog:

Exit the EFI shell and enter the “Boot option maintenance menu”.  Then select “Boot from File”.  Select the first volume in the list, which in this case, was
“IA64_EFI [Acpi(PNP0A03,0)/Pci(0|0)/Scsi(Pun1,Lun0)/HD(Part1,Sig4)”.  Drill down into the directories EFI -> HPUX and select the file “hpux.efi”.  The HPVM will now boot properly.

When it is booted, log in to the HPVM and identify the boot disk.

hostB # /usr/sbin/ioscan -fNnC disk

Set the boot path permanently.  In this case the path was /dev/dsk/disk4_p2:

setboot -p /dev/disk/disk4_p2
Primary boot path set to 0/0/0/0.0x1.0x0 (/dev/disk/disk4_p2)

Reboot the HPVM. To make sure it can boot up all the way.
newhpvm:/root# reboot

Create Many Clones on Remote System

Finally, shut down the HPVM and clone it to make as many clones on hostB as desired, using the “Golden HPVM” procedure above.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.