34 lines
939 B
Bash
Executable File
34 lines
939 B
Bash
Executable File
#!/bin/sh
|
|
|
|
exitmsg () {
|
|
echo $1
|
|
exit 1;
|
|
}
|
|
|
|
[ "$#" -lt 3 ] && echo 'Usage: lvmmount VGNAME VOLNAME PARTNUM [LOOPDEVICE]' && exit 2
|
|
VG=$1
|
|
vgs -qq $VG > /dev/null 2>&1 || exitmsg "The specified VG ($VG) does not exist"
|
|
|
|
VOL=$2
|
|
lvs -qq $VG/$VOL > /dev/null 2>&1 || exitmsg "The specified volume ($VOL) does not exist"
|
|
|
|
PART=$3
|
|
echo $PART | grep -qE "^[[:digit:]]+$" || exitmsg "The specified partition ($PART) must be a number"
|
|
|
|
DST=${4:-/dev/loop0}
|
|
|
|
losetup -P $DST /dev/$VG/$VOL || exitmsg "$DST is already used, specify another loop device (or deactivate it with losetup -D $DST"
|
|
if [ ! -e ${DST}p${PART} ]
|
|
then
|
|
losetup -D $DST
|
|
exitmsg "The is no partition ${PART} in ${VG}/{$VOL}"
|
|
fi
|
|
|
|
DSTDIR=/tmp/${VG}_${VOL}_${PART}
|
|
[ -e $DSTDIR ] && exitmsg "The $DSTDIR directory already exists, please check what you are doing"
|
|
|
|
mkdir -p $DSTDIR
|
|
mount ${DST}p${PART} ${DSTDIR}
|
|
echo "Mounted /dev/${VG}/${VOL} part ${PART} in ${DSTDIR}"
|
|
exit 0
|