Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # attachiscsi.sh - Attach iSCSI devices attached to the instance to the operating system
- #
- # Author: Steven B. Nelson, Sr. Solutions Architect
- # Oracle Bare Metal Cloud Services
- #
- # 12 March 2017
- # Copyright Oracle, Inc. All rights reserved.
- # Make FIFO pipes for the two loops below
- mkfifo discpipe
- mkfifo sesspipe
- # Find all the iSCSI Block Storage volumes attached to the instance but
- # not configured for use on the instance. Basically, get a list of the
- # volumes that the instance can see, the loop through the ones it has,
- # and add volumes not already configured on the instance.
- #
- # First get the list of volumes visible (attached) to the instance
- iscsiadm -m discovery -t st -p 169.254.0.2:3260 | grep -v uefi | awk '{print $2}' > discpipe &
- # Loop through the list (via the named FIFO pipe below)
- while read target
- do
- # Get the list of the currently attached Block Storage volumes
- iscsiadm -m session -P 0 | grep -v uefi | awk '{print $4}' > sesspipe &
- # Set a flag, and loop through the sessions (attached, but not configured)
- # and see if the volumes match. If so, skip to the next until we get
- # through the list. Session list is via the pipe.
- found="false"
- while read session
- do
- if [ ${target} = ${session} ]
- then
- found="true"
- break
- fi
- done < sesspipe
- # If the volume is not found, configure it. Get the resulting device file.
- if [ ${found} = "false" ]
- then
- iscsiadm -m node -o new -T ${target} -p 169.254.0.2:3260
- iscsiadm -m node -o update -T ${target} -n node.startup -v automatic
- iscsiadm -m node -T ${target} -p 169.254.0.2:3260 -l
- sleep 5
- fi
- done < discpipe
- # Remove the FIFOs
- find . -maxdepth 1 -type p -exec rm {} \;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement