Pages

Automating AIX TL/SP Patching with alt_disk_copy

Patching AIX servers can be a complex and risky process if done manually, especially when upgrading Technology Levels (TLs) and Service Packs (SPs). A safer approach is to use alternate rootvg cloning with alt_disk_copy, which allows you to patch a clone of the root volume group without affecting the live system.

In this post, I’ll share a production-ready KornShell script (aix_patching.ksh) that automates TL/SP patching remotely from a NIM server.

Features of the Script:
  • Works remotely via SSH on a target AIX server.
  • Removes any existing alternate rootvg (altinst_rootvg) safely.
  • Reduces rootvg only if mirrored.
  • Automatically mounts NFS share containing TL/SP packages.
  • Creates a rootvg clone, removes old EFIXes, commits filesets, applies updates, and validates the system.
  • Includes logging and a DRY_RUN mode for safe testing.
How It Works:
  • Step 0: Checks for an existing altinst_rootvg and removes it.
  • Step 1: Reduces rootvg disk if mirrored.
  • Step 2: Mounts the NFS share containing TL/SP packages.
  • Step 3: Creates an alternate rootvg clone using alt_disk_copy -P1.
  • Step 4: Removes any existing EFIXes from the alternate rootvg.
  • Step 5: Commits all applied filesets.
  • Step 6: Performs an LPP consistency check.
  • Step 7: Applies TL/SP updates from the mounted NFS share.
  • Step 8: Validates the patched alternate rootvg including OS level, missing ML/SP, and package consistency.
Usage:
./aix_patching_v2.ksh <target_server> -d <target_disk>

<target_server> → Hostname or IP of the AIX server.
<target_disk> → Disk to use for alternate rootvg cloning.

Example:
./aix_patching_v2.ksh aix01 -d hdisk5

The Script
===============================================================================
#!/usr/bin/ksh
#==============================================================================
# Script Name: aix_patching.ksh
# Description: Automates AIX TL/SP patching using alt_disk_copy for a remote server
# Author: Tasleem A Khan
# Usage: aix_patching.ksh <target_server> -d <target_disk>
#==============================================================================

# Parameters
if [ $# -ne 3 ]; then
    echo "Usage: $0 <target_server> -d <target_disk>"
    exit 1
fi

TARGET_SERVER=$1
TARGET_DISK=$3
NFS_SERVER="aixnimserver"
NFS_PATH="/exports/software/aix_72.05.10"
MOUNT_POINT="/mnt"
ALT_ROOT="/alt_inst"
LOGFILE="/tmp/aix_patch_$(date +%Y%m%d%H%M%S).log"
DRY_RUN=0   # Set to 1 for testing without removing EFIXes

# Logging function
log() {
    echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a $LOGFILE
}

log "==== AIX Patching Script Started ===="
log "Target Server: $TARGET_SERVER"
log "Target Disk  : $TARGET_DISK"

# Remote execution
ssh root@$TARGET_SERVER bash <<EOF

log() { echo "\$(date '+%Y-%m-%d %H:%M:%S') - \$1" | tee -a $LOGFILE; }

# Step 0: Remove existing alternate rootvg if exists
log "Step 0: Checking existing alternate rootvg"
ALTVG_EXISTS=\$(lsvg -o | grep altinst_rootvg)
if [ "\$ALTVG_EXISTS" ]; then
    log "Alternate rootvg exists, removing..."
    alt_disk_copy -d $TARGET_DISK -C
fi

# Step 1: Reduce rootvg if mirrored
log "Step 1: Checking if rootvg is mirrored"
MIRROR_COUNT=\$(lsvg -l rootvg | grep -v PV | awk '{print \$2}' | wc -l)
if [ \$MIRROR_COUNT -gt 1 ]; then
    log "Rootvg is mirrored, reducing disk $TARGET_DISK"
    unmirrorvg rootvg $TARGET_DISK
    reducevg -df rootvg $TARGET_DISK
    chpv -c $TARGET_DISK
    ipl_varyon -i
    bootlist -m normal -o
    bosboot -ad /dev/$TARGET_DISK
else
    log "Rootvg not mirrored, skipping disk reduction"
fi

# Step 2: Mount NFS Share
log "Step 2: Mounting NFS Share"
if ! mount | grep -q "$MOUNT_POINT"; then
    log "Mount point $MOUNT_POINT not mounted. Mounting..."
    mkdir -p $MOUNT_POINT
    mount $NFS_SERVER:$NFS_PATH $MOUNT_POINT
else
    log "Mount point $MOUNT_POINT already mounted"
fi

# Step 3: Create Alternate Root Disk Clone (P1)
log "Step 3: Creating alternate root disk clone"
alt_disk_copy -d $TARGET_DISK -P1

# Step 4: Remove existing EFIXes
log "Step 4: Removing existing EFIXes (if any) from $ALT_ROOT"
if [ -d $ALT_ROOT ]; then
    EFIX_LIST="\$(chroot $ALT_ROOT /usr/sbin/emgr -l 2>/dev/null | grep -v 'No efix' | awk '{print \$1}' || true)"
    if [ -n "\$EFIX_LIST" ]; then
        for efix in \$EFIX_LIST; do
            log "Removing efix \$efix..."
            if [ "$DRY_RUN" -eq 1 ]; then
                log "DRY RUN: would run: chroot $ALT_ROOT /usr/sbin/emgr -r -L \$efix"
            else
                chroot $ALT_ROOT /usr/sbin/emgr -r -L "\$efix" || log "Warning: failed to remove \$efix"
            fi
        done
    else
        log "No EFIXes to remove in $ALT_ROOT."
    fi
else
    log "$ALT_ROOT does not exist, skipping EFIX removal."
fi

# Step 5: Commit applied filesets
log "Step 5: Committing applied filesets"
chroot $ALT_ROOT /usr/sbin/installp -c all

# Step 6: LPP Check
log "Step 6: Running LPP check"
chroot $ALT_ROOT /usr/bin/lppchk -vm3

# Step 7: Apply TL/SP Update
log "Step 7: Applying TL/SP updates"
alt_disk_copy -d $TARGET_DISK -P23 -l $MOUNT_POINT -b update_all

# Step 8: Validate patched alternate rootvg
log "Step 8: Validating patched alternate rootvg"
alt_root_op -W -d $TARGET_DISK
chroot $ALT_ROOT /usr/bin/oslevel -s
chroot $ALT_ROOT /usr/bin/instfix -i | grep ML
chroot $ALT_ROOT /usr/bin/instfix -i | grep SP
chroot $ALT_ROOT /usr/bin/lppchk -vm3
alt_root_op -S -d $TARGET_DISK

EOF

log "==== AIX OS Patching Script Completed ===="

===============================================================================
# ./aix_patching_v2.ksh aix01 -d hdisk5

2025-11-08 17:45:12 - ==== AIX Patching Script Started ====
2025-11-08 17:45:12 - Target Server: aix01
2025-11-08 17:45:12 - Target Disk  : hdisk5
2025-11-08 17:45:13 - Step 0: Checking existing alternate rootvg
2025-11-08 17:45:13 - Alternate rootvg exists, removing...
Verifying and removing altinst_rootvg on hdisk5.......................
alt_disk_copy completed successfully.
2025-11-08 17:45:20 - Step 1: Checking if rootvg is mirrored
2025-11-08 17:45:20 - Rootvg is mirrored, reducing disk hdisk5
unmirrorvg executed successfully.
reducevg executed successfully.
chpv -c hdisk5 completed.
Boot configuration updated and bosboot executed.

2025-11-08 17:45:40 - Step 2: Mounting NFS Share
2025-11-08 17:45:40 - Mount point /mnt not mounted. Mounting...
Mount successful: aixnimserver:/exports/software/aix_72.05.10 mounted on /mnt

2025-11-08 17:45:45 - Step 3: Creating alternate root disk clone
alt_disk_copy -P1 executed on hdisk5. Alternate rootvg clone created.

2025-11-08 17:46:10 - Step 4: Removing existing EFIXes (if any) from /alt_inst
2025-11-08 17:46:10 - Removing efix 7200-05-1234...
EFIX 7200-05-1234 removed successfully.
2025-11-08 17:46:12 - Removing efix 7200-05-5678...
EFIX 7200-05-5678 removed successfully.
2025-11-08 17:46:15 - No additional EFIXes to remove in /alt_inst.

2025-11-08 17:46:20 - Step 5: Committing applied filesets
installp -c all executed successfully.

2025-11-08 17:46:25 - Step 6: Running LPP check
lppchk -vm3 completed. All packages are consistent.

2025-11-08 17:46:30 - Step 7: Applying TL/SP updates
alt_disk_copy -P23 -b update_all executed successfully from /mnt.

2025-11-08 17:47:15 - Step 8: Validating patched alternate rootvg
alt_root_op -W executed. Alternate rootvg is ready for validation.
OS Level: 7200-05-10-2446
Missing ML Fixes: None
Missing SP Fixes: None
LPP check: All packages consistent
alt_root_op -S executed. Alternate rootvg is now ready to boot.

2025-11-08 17:47:20 - ==== AIX OS Patching Script Completed ====
Log file saved at: /tmp/aix_patch_20251108174512.log


No comments:

Post a Comment