Clone a z/VM Linux user/guest instance from another Linux guest

Cloning a virtual machine or user as it is called in z/VM terms from within another guest/user running Linux can be used in a lot of different scenario’s. Especially when the people managing the z/VM platform and virtual machines are less experienced with z/VM, it could be good to let them create a clone without the need to access a 3270 terminal. This scenario can also be used to let users do some self service and provide them with new instances without intervention.

This post will describe how to create a new z/VM user and provide it with the data from another instance, customize it and prepare it to be bootable. All of this should be done from a Linux guest running on the sam z/VM environment without the need to open a terminal or have any deep knowledge of z/VM.

For this explanation, I was using a guest (or user as it should be called in z/VM terms) is running Linux for zSeries (zLinux as it once was) on a z/VM host. I was using SLES11 running on z/VM 6.3. The system from where I will execute all steps is called the cloner. As a source for the new VM, I will use the volume that was the result of a minimal installation of SLES11 (Suse Linux Enterprise System). This source needs to be created once and can be used as much as you want to generate different clones.

Connect the cloner to the FCP-device of the z/VM machine

This first step is to connect the cloner to the FCP-devices on the z/VM host. In my example, I’m using different devices to connect to the LUN devices. Device 6022 will be used to connect to the source LUN (the result of the minimal install) and FCP device 6023 will be used to connect to the target LUN (the disk that will be used by the new VM).

Attaching devices requires the necessary privileges on the z/VM environment. To be sure that we can communicate from the guest (user) to the host (CMS), we need to make sure that kernel module vmcp is loaded in the cloner:

After loading vmcp, we can send commands to the z/VM host and attach two FCP-devices to our cloner. Cloner is the hostname of the Linux VM and also the z/VM user’s name.

After attaching the FCP devices, we need to put them online and we can check if the device correspondends with the correct WWPN’s of the SAN:

As you can see, the cloner was already connected to FCP device 8000F and now we can also use devices 6022 and 6023 to connect the cloner to the source and target LUN’s.

Connect the cloner to the source and target LUN

Now that we have access to a few FCP-devices, we can connect our cloner to the source and target LUN. The source LUN contains a minimal SLES install (installed with the GUI and bootable from it’s own device, configured with a fixed IP). The target LUN is a a new LUN of the same size.

  • LUN 0x003c000000000000 is the source for our clone
  • LUN 0x003d000000000000 is the target for our clone

Connect to the LUN using the previously connected FCP adapters:

In the above output we can see that the LUN’s are connected to the system including the disk of the cloner itself.

To use the LUN’s on Linux, we need to know the device name in /dev. We can find these with lsscsi:

Clone the data from source to target

In the previous step, we connected the source and target LUN to the cloner and got to know the device names that represent those LUN’s. The next step is to clone the data from our source LUN to the target LUN:

After cloning the data, we need to inform the cloner that we have a new partition configuration since we cloned the partitions from the source LUN to the target LUN

Customize the data of the clone

In the previous step we cloned the filesystem of another Linux instance so we need to customize the data on the cloned filesystem in order to make it bootable from another FCP device and LUN and to not interfere with the original system.

To customize the cloned filesystem, we’ll mount the cloned filesystem on /mnt/clone and adjust some files:

Change the network configuration and hostname:

Change the IPL configuration to include the correct FCP-device and new LUN. The /dev/disk/by-path/ccw- corresponds to the portname and LUN which can be found with lszfcp -D for FCP-device 6023.

Now all file adjustments have been done and we need to generate a new initrd and write a new bootsector that includes the correct FCP-device and LUN:

Let’s chroot into the cloned filesystem:

Re-create the initrd:

Re-create the bootsector using zipl:

At this stage, the filesystem is prepared and should be bootable from the changed LUN and FCP-device.

Let’s leave the chroot and cleanup mounts and devices:

Create a new z/VM user

The next thing to do is to create a new user (or VM) on the z/VM environment. In a previous post, I described how you can access CMS-files from a Linux guest running on z/VM. This technique will be used to create the user and a PROFILE.EXEC for that new user. More information here: Read and write a CMS minidisk on a z/VM system from a user/guest running Linux.

First, we need to load the kernel module fuse to be able to access the CMS-files:

The next steps are to connect to minidisk 191 owned by user cloner, which is running our current Linux system. On the minidisk, we need to write a file that contains the configuration of the new z/VM user. Then, we’ll use dirmaint to create that new user on the z/VM machine. The new user will be called newvm.

Put minidisk 191 online and mount it:

Create a new, empty file and set it’s attributes to FB 80:

Create a temporary file and add the configuration for the new user to the NEVWM.DIRECT file. Make sure that the configuration contains the correct device numbers for your configuration. Device 6023 corresponds to the FCP-adapter which I put in the zipl configuration and which will be used from the newly generated bootloader:

I created the file in /tmp/newvm.direct so it needs to be copied to the cloner’s 191 minidisk. It’s important to not directly edit the file on the minidisk but copy it after changing. See the post about writing to minidisks from Linux to find out more about this.

The next step is to use the newly created file to actually create the user using dirmaint. The rest of the user creation get’s handled by dirmaint (that’s what it’s made for):

At this time, the new z/VM user gets created. This is an asynchronous proces so it’s hard to tell when the creation is completed.

Create a PROFILE.EXEC for the new z/VM user

Once the user has been created, we need to create a 191-minidisk and a PROFILE.EXEC for the new user containing the correct boot-device in order to easily IPL that new user.

First link the 191-minidisk of the new user NEWVM to 291 of the cloner:

Put minidisk 291 online in the cloner and mount it:

Create a new PROFILE.EXEC on the 291 minidisk and set the correct attributes for the file:

Create a temporary file and write the following to the file. The LOADDEV PORTNAME and LUN corresponds to the portname which can be found with lszfcp -D for FCP-device 6023.

Now copy the temporary file containing the user’s PROFILE.EXEC, which we just created, to the mounted 291 minidisk:

After these steps, the system is ready to boot but first we should cleanup our devices and mounts:

This should be all it takes to clone a system. You could repeat these steps multiple times, using a different FPC device, different LUN and different IP address. After the clone, logon to the newly created user with the password written in the NEWVM.DIRECT file and enter IPL 6023 to start the clone. With a little bit of trying, this should be possible from the cloner as well.

Leave a Reply

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