Commit 6d3e24cc authored by Gonzalo S Nido's avatar Gonzalo S Nido
Browse files

Added mountpoint

parent 0fa3e557
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
# - ONLY ONE PARTITION # - ONLY ONE PARTITION
# - IS STILL UNMOUNTED (does not have a mountpoint) # - IS STILL UNMOUNTED (does not have a mountpoint)
# #
# USAGE: mount_disk_by_lun.sh <LUN> # USAGE: mount_disk_by_lun.sh <LUN> <MOUNTPOING>
# <LUN>: Logical Unit Number, specified in Azure when attaching the disk to # <LUN>: Logical Unit Number, specified in Azure when attaching the disk to
# the VM. # the VM.
# <MOUNTPOINT>: Mount point for the drive. It will be created if it did not
# exist
# #
# ERROR CODES: The script with the following error codes: # ERROR CODES: The script with the following error codes:
# (1) Illegal number of arguments # (1) Illegal number of arguments
...@@ -15,16 +17,17 @@ ...@@ -15,16 +17,17 @@
# (4) The LUN-assigned drive is not partitioned # (4) The LUN-assigned drive is not partitioned
# (5) There are more than one partitions # (5) There are more than one partitions
# (6) The partition is already mounted # (6) The partition is already mounted
# (7) The drive is not formatted as "ext4" # (7) The drive is not formatted as "ext2", "ext3", or "ext4"
if [[ $# -ne 1 ]]; then if [[ $# -ne 2 ]]; then
echo "[ERROR] Provide LUN as argument (HOST:CHANNEL:TARGE:LUN)" echo "[ERROR] Provide LUN (HOST:CHANNEL:TARGE:LUN) and the mountpoint destination"
echo "USAGE: mount_disk_by_lun.sh <LUN>" echo "USAGE: mount_disk_by_lun.sh <LUN> <MOUNTPOINT>"
exit 1 exit 1
fi fi
LUN=$1 LUN=$1
DESTINATION=$2
DEV=( $( lsblk -o NAME,HCTL,TYPE | grep "^sd" | awk -v lun=$LUN 'BEGIN{regexp="^[0-9]+:[0-9]+:[0-9]+:"lun"$"}{if ($2 ~ regexp && $3 ~ /disk/) { print $1 }}' ) ) DEV=( $( lsblk -o NAME,HCTL,TYPE | grep "^sd" | awk -v lun=$LUN 'BEGIN{regexp="^[0-9]+:[0-9]+:[0-9]+:"lun"$"}{if ($2 ~ regexp && $3 ~ /disk/) { print $1 }}' ) )
if [[ -z "$DEV" ]]; then if [[ -z "$DEV" ]]; then
...@@ -48,13 +51,13 @@ FS=( $( lsblk -o NAME,TYPE,FSTYPE /dev/$DEV | awk '$2 ~ "part"{ print $3 }' ) ) ...@@ -48,13 +51,13 @@ FS=( $( lsblk -o NAME,TYPE,FSTYPE /dev/$DEV | awk '$2 ~ "part"{ print $3 }' ) )
PTNAME=( $( lsblk -o KNAME,TYPE,FSTYPE /dev/$DEV | awk '$2 ~ "part"{ print $1 }' ) ) PTNAME=( $( lsblk -o KNAME,TYPE,FSTYPE /dev/$DEV | awk '$2 ~ "part"{ print $1 }' ) )
if [[ "${#PART[@]}" -eq 0 ]]; then if [[ "${#PART[@]}" -eq 0 ]]; then
echo "Disk /dev/$DEV is not partitioned (ONE partition required)" echo "[ERROR] Disk /dev/$DEV is not partitioned (ONE partition required)"
lsblk -o NAME,HCTL,SIZE,TYPE,MOUNTPOINT,FSTYPE /dev/$DEV lsblk -o NAME,HCTL,SIZE,TYPE,MOUNTPOINT,FSTYPE /dev/$DEV
exit 4 exit 4
fi fi
if [[ "${#PART[@]}" -gt 1 ]]; then if [[ "${#PART[@]}" -gt 1 ]]; then
echo "Disk /dev/$DEV has more than one partition (${#PART[@]}). Only ONE partition allowed" echo "[ERROR] Disk /dev/$DEV has more than one partition (${#PART[@]}). Only ONE partition allowed"
lsblk -o NAME,TYPE,MOUNTPOINT,FSTYPE /dev/$DEV lsblk -o NAME,TYPE,MOUNTPOINT,FSTYPE /dev/$DEV
exit 5 exit 5
fi fi
...@@ -82,16 +85,12 @@ fi ...@@ -82,16 +85,12 @@ fi
if [[ ${FS} == "ext2" || ${FS} == "ext3" || ${FS} == "ext4" ]]; then if [[ ${FS} == "ext2" || ${FS} == "ext3" || ${FS} == "ext4" ]]; then
echo "LUN=${LUN}: one partition in ext fileformat without mountpoint:" echo "LUN=${LUN}: one partition in ext fileformat without mountpoint:"
lsblk -o NAME,KNAME,HCTL,SIZE,TYPE,FSTYPE /dev/${DEV} lsblk -o NAME,KNAME,HCTL,SIZE,TYPE,FSTYPE /dev/${DEV}
sudo mkdir /bsdata sudo mkdir -p ${DESTINATION}
sudo mount /dev/${PTNAME} ${DESTINATION}
if [[ $? == 0 ]]; then if [[ $? == 0 ]]; then
sudo mount /dev/${PTNAME} /bsdata echo "MOUNTED IN ${DESTINATION}"
if [[ $? == 0 ]]; then
echo "MOUNTED IN /bsdata"
else
echo "[ERROR] Could not mount in /bsdata"
fi
else else
echo "[ERROR] The folder /bsdata exists already" echo "[ERROR] Could not mount in ${DESTINATION}"
fi fi
else else
echo "[ERROR] The partition is not in ext2, ext3 or ext4 format" echo "[ERROR] The partition is not in ext2, ext3 or ext4 format"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment