VM Handlers for Attach/Detach in Linux

There are scripts that are invoked when a device is either attached or detached. These scripts can be found under the /opt/hcs/handlers directory. The attach handler (default.attach) is invoked when a new device is attached and the detach handler (default.detach) is invoked when a new device is detached.

The default attach handler is shown below:

#!/bin/sh

# Post-attach handlers are called with at least 2 and at most 4 arguments:
# 1. the absolute path of the cleartext device e.g. /dev/mapper/clear_sda
# 2. the absolute path of the encrypted_device e.g. /dev/sda
# 3. (optional) mountpoint
# 4. (optional) mount options
# If the mountpoint and mount options are supplied, then the default handler
# will fsck and mount the cleartext device on the given mount point.

if [ $# -lt 2 -o $# -gt 4 ]; then
    exit 1
fi
if [ $# -eq 2 ]; then
    exit 0
fi

cleardev=$1
if [ $# -ge 3 ]; then
    mntpt=$3
fi
if [ $# -eq 4 ]; then
    mntopts=$4
fi

fsck -a "$cleardev"
if [ $? -eq 0 ]; then
    mount $mntopts "$cleardev" "$mntpt"
else
    exit 2
fi

The mount point and mount options are collected along with the clear-text path to the device and a mount call is made.

The handlers can be changed freely. We recommend that you back up your handlers, using your preferred backup solution.