You are on page 1of 8

CD/DVD on demand with LPARs

Pascal Greffier October 08, 2012

In many organizations, sample requests such as a CD mount or umount on logical partitions


(LPARs) must be managed automatically without administrator rights by an events process.
This article can help to automate this process.

Introduction
In a classical environment with IBM® AIX® logical partitions (LPARs), mounting or unmounting a
CD requires administrator rights on the Virtual I/O Server (VIOS). It can be a very costly process if
this operation has to be done frequently.

The aim of this article is to provide tools and methods for users, without administrator rights, to
manage the CD/DVD mount and umount operations on an AIX LPAR.

Users might want to do such operations easily without external help (from system administrator or
Help Desk). A simple procedure can help users to perform this basic operation.

The following example explains the global architecture, preliminary actions, and current
operations.

Architecture
We need:

• One Virtual I/O Server called VIOS on which the Virtual Media Library is created.
• One LPAR called LPAR1 on which the set of tools (scripts) are implemented
• Another LPAR called LPAR2, which is the target where the CD or the DVD is mounted.

LPAR1 and LPAR2 could be gathered in a single LPAR, but we prefer in our example to have two
distinct LPARs one for tools, another to manage the CD/DVD.

Table 1 and Table 2 describe all the necessary steps to mount or unmount a CD/DVD. The steps
can be manual or automatic.

© Copyright IBM Corporation 2012 Trademarks


CD/DVD on demand with LPARs Page 1 of 8
developerWorks® ibm.com/developerWorks/

Table 1. Steps to mount a CD/DVD


Order Step Action

1 Put an ISO CD file on the AIX server (LPAR1) User + command (scp or ftp command) or the
ISO file on the NFS share

2 Push the ISO file to the Virtual Media Library User + mount_CD.ksh script

3 Perform an automatic virtualization process on Automatic process on the VIOS


the VIOS

4 Mount the CD on the AIX server (LPAR2) User + mount command

Table2. Steps to unmount a CD/DVD


Order Step Action

1 Unmount the CD on the AIX server (LPAR2) User + umount command

2 Perform an automatic virtualization process on User + umount_CD.ksh script


the VIOS

3 Perform an automatic removal of the IOS CD Automatic process on the VIOS


file

System requirements
Before running the mount or unmount process, you must perform some preliminary actions:

1. Create a tools account on the VIOS without administrator rights. The tools account belongs to
the staff group.
2. Create a Virtual Media Library on the VIOS and change the ownership of the Virtual Media
Library to the tools account.
3. Create a working directory on the VIOS.
4. Create a tools account on the LPAR1 server.
5. Create a Secure Shell (SSH) public key for the tools account on LPAR1 without passphrase
and add it into the ~tools/.ssh/authorized_keys file on the VIOS.
6. Create a virtual target for a file-backed virtual optical device.

Account creation on the VIOS as root user


Create a tools account without administrator rights on the VIOS.

Listing 1. Creating a user on VIOS


# mkuser id=301 pgrp=staff home=/home/tools shell=/bin/ksh tools

Virtual Media Library on the VIOS


For more information about creating a Virtual Media Library on a VIOS, refer to VIOLoadISo on the
IBM developerWorks® wiki.

After you create the Virtual Media Library, change the ownership to the tools account and provide
rw permissions to the tools account and staff group.

CD/DVD on demand with LPARs Page 2 of 8


ibm.com/developerWorks/ developerWorks®

Creating a working directory on the VIOS


A working directory is required on the VIOS. It contains flag files used by an automatic script.

Listing 2. Creating a working directory


# mkdir –p /var/tools/CDs
# chown tools:staff /var/tools/CDs
# chmod 775 /var/tools/CDs

Account creation on the LPAR1 server as root user


Listing 3. Creating a user on the LPAR1 server
# mkuser id=xxx pgrp=staff home=/home/tools shell=/bin/ksh tools

Where xxx is the user ID.

Create an SSH public key for the tools account on the LPAR1 server
This public key is added to the authorized_keys file of the VIOS tool account. Here, we used an
empty passphrase.

Listing 4. SSH key creation


$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/tools/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/tools/.ssh/id_dsa.
Your public key has been saved in /home/tools/.ssh/id_dsa.pub.
….

On the VIOS, add this generated public key into the ~tools/.ssh/authorized_keys file. At this point
on the LPAR1 server, the tools account is able to launch commands on the VIOS as tools account.

Create a virtual target for a file-backed virtual optical device


As a padmin user on the VIOS, use the mkdev command to create your virtual optical device
assigned to vhost.

Listing 5. Create virtual optical device


$ mkvdev -fbo -vadapter vhost#
vtopt# Available

Where vhost# is the virtual Small Computer System Interface (VSCSI) device for the VIOS LPAR2
— you can check this with the lsmap –all command. The mkdev command creats the vtopt#
device.

Remember LPAR2 vhost# and associated vtopt#. These two name are used as parameters in
scripts.

CD/DVD on demand with LPARs Page 3 of 8


developerWorks® ibm.com/developerWorks/

Implementation
Four scripts, one on the VIOS and three on the LPAR1 server, need to be implemented.

One script on the VIOS is dedicated for the automatic process:

• mnt_CD.ksh

Three scripts on LPAR1 are the user's script:

• mount_CD.ksh
• umount_CD.ksh
• check_CD.ksh

On the VIOS, the mnt_CD.ksh script is scheduled for every minute and checks the flag files to
perform the mount or unmount operations. This script also creates a report about the virtual optical
device and the Virtual Media Library.

VIOS implementation
The mnt_CD.ksh script must be created in the padmin user's home directory. This script checks
the existing flag files that are created in the /var/tools/CDs folder by the user's scripts from LPAR1.

Flag file Description Action done by the script

ISO_file.mount Contains the ISO file name to mount Loads the virtual optical disk (ISO file) from
the Virtual Medial Library into the virtual optical
device

ISO_file.umount Is the trigger for removing the virtual optical Removes a virtual optical media disk from a
device virtual optical device

ISO_file.remove Contains the ISO file name to remove Removes the corresponding ISO file name

After each iteration, the script removes the existing flag file. A report is also produced by the script.
You can find more details in the mount_CD.ksh script.

Some parameters inside the mnt_CD.ksh script must be set according to your local configuration.

Listing 6. mnt_CD.ksh script


$ ls -l /home/padmin/mnt_CD.ksh
-rwxr-xr-x 1 padmin staff 1929 Sep 23 08:46 /home/padmin/mnt_CD.ksh

This script must be croned inside the root's crontab file.

Listing 7. Adding an new entry in the root's crontab file


#crontab –e
Append the following entry :
* * * * * su - padmin " -c mnt_CD.ksh " > /tmp/MNT_CD.log 2>&1
Save and close file.

CD/DVD on demand with LPARs Page 4 of 8


ibm.com/developerWorks/ developerWorks®

LPAR1 implementation
From the LPAR1 server, the tools user is able to launch scripts to mount or unmount CDs. Three
scripts are available:

Script Description

mount_CD.ksh Copy or mount the ISO file

umount_CD.ksh Unmount or delete the ISO file

check_CD.ksh Display the report generated by the automatic script on the VIOS

Before using the mount_CD.ksh or umount_CD.ksh scripts check your configuration with the
check_CD.ksh script.

check_CD script
The check_CD.ksh script displays reports generated by the periodic script on VIOS. The -h option
provides information about the usage. The syntax for the check_CD.ksh script is check_CD.ksh [-
h].

This script generates a report from the VIO and displays it as a status. The report is divided into
three parts:

The first part provides the results about the latest operation done by the periodic script. The
second part provides the status about the virtual device that is mapped to LPAR2 (in particular,
about the virtual optical device and its backing device), and the third part provides information
about the Virtual Media Repository.

Example 1. check_CD.ksh output


INFO - : DATE: 09/28/11 TIME: 02:28:00 --> ========= Tasks done by script ========
INFO - : DATE: 09/28/11 TIME: 02:28:00 --> No CD to mount
INFO - : DATE: 09/28/11 TIME: 02:28:00 --> No CD to umount
INFO - : DATE: 09/28/11 TIME: 02:28:00 --> No Removal requested
INFO - : DATE: 09/28/11 TIME: 02:28:00 -->
=================== Vhost status ===================================
SVSA Physloc Client Partition ID
--------------- -------------------------------------------- ------------------
vhost9 U9117.MMA.10D8D22-V2-C44 0x00000010
……
……
VTD vtopt1
Status Available
LUN 0x8400000000000000
Backing device /var/vio/VMLibrary/HACMP_5.4.1.iso
Physloc
INFO - : DATE: 09/28/11 TIME: 02:28:01 -->
=================== CD Library list ================================
Size(mb) Free(mb) Parent Pool Parent Size Parent Free
16322 7456 lparvg 2856960 2049024
Name File Size Optical Access
HACMP_5.4.1.iso 457 vtopt1 rw
IBM_Installation_Toolkit_42.iso 1590 None rw
TEST_Toolkit_42.iso 1590 None rw
VIO21-1108.iso 67 None rw

CD/DVD on demand with LPARs Page 5 of 8


developerWorks® ibm.com/developerWorks/

rhel_srv_56_ppc.iso 3680 vtopt0 rw

mount_CD script
The mount_CD.ksh script is used to copy, if necessary, an ISO file on the Virtual Media Library and
add it to the virtual optical device that is linked to the LPAR2 server. Scripts must be launched as
the tools user. The following syntax applies:
mount_CD.ksh <-f <ISO file>> [-c] [-h]

The options are:

-f <ISO file> Indicates the ISO file to transfer and mount

-c Indicates that the ISO file must be copied to the VIOS (inside the Virtual
Media Library)

-h Gives usage

Before mounting the CD, make sure that the backing device associated with the virtual optical
device is free. Check it by using the check_CD.ksh script.

Example 2. Copying the MY_CD.iso file and mounting it

$ mount_CD.ksh –f MY_CD.iso –c

Example 3. Mounting an already copied ISO file on the LPAR1 server as the tools user

$ mount_CD.ksh –f MY_CD.iso

Wait for at least 1 minute to make sure that the ISO file is defined in the virtual optical device.
Check this by using the check_CD.ksh script and the verification line about the backing device of
the virtual optical device.

After making sure that everything is fine, you can mount the CD on the LPAR2 server with an
appropriate mount command.

On the LPAR2 server, run the following command:

$ mount -o ro -v cdrfs /dev/cd# /mnt

/dev/cd# is the associated device to the virtual optical device on the VIOS.

umount_CD script
Name: umount_CD.ksh

Syntax: umount_CD.ksh <-f <ISO file>> [-r [-h]

Description:

CD/DVD on demand with LPARs Page 6 of 8


ibm.com/developerWorks/ developerWorks®

The umount_CD.ksh script is used to remove, if necessary, an ISO file in the Virtual Media Library
and to free the backing device associated with the virtual optical device. Scripts must be launched
as the tools user.

Options:

-f <ISO file> Indicates the ISO file to remove (inside the Virtual Media Library)

-r Indicates that the ISO file must be removed (inside the Virtual Media
Library)

-h Gives usage

Warnings:

Before releasing the backing device, the CD must be unmounted from the LPAR2 server.

Example 4. Remove only an existing ISO file, MY_CD.iso

$ umount_CD.ksh -r MY_CD.iso

Check the results with the check_CD.ksh script and verify that the MY_CD.iso file does not exist in
the Media Library List.

Example 5. Releasing the backing device for the virtual optical device

$ umount_CD.ksh –u

Check the results with the check_CD.ksh script and verify that the backing device is released.

Summary
In this article, we describe how to mount a CD/DVD on an LPAR without having any administrator
rights on the VIOS. This example is not very complicated, as we have a separate LPAR (LPAR1
and LPAR2), but it is not mandatory. You can have only one LPAR or more than one targeted
LPAR by improving the scripts. You can also improve the scripts to add more functionality.
Nevertheless, the basis is described to offer this service.

Resources
Download shell scripts
• mnt_CD.ksh

• mount_CD script

• umount_CD script

• check_CD.ksh

CD/DVD on demand with LPARs Page 7 of 8


developerWorks® ibm.com/developerWorks/

Learn
• Refer to the following links for more information relating to virtual optical devices.

• The VIOS_Optical_Commands wiki gives information about the VIO server optical
commands.
• The More on Virtual Optical Devices article describes the commands to manage virtual optical
devices.

Discuss
• Join the developerWorks community, a professional network and a unified set of community
tools for connecting, sharing, and collaborating.

© Copyright IBM Corporation 2012


(www.ibm.com/legal/copytrade.shtml)
Trademarks
(www.ibm.com/developerworks/ibm/trademarks/)

CD/DVD on demand with LPARs Page 8 of 8

You might also like