|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# |
| 4 | +# Multi Mounter, 2015 by ppelikan |
| 5 | +# Mount images containing multiple partitions |
| 6 | +# USAGE: call multimounter as root and as the parameter provide name of the disk image file |
| 7 | +# Example: |
| 8 | +# user@user:~$ sudo ~/multimounter.sh disk_image.img |
| 9 | +# It will mount (in the current directory that is ~/) partitions from the image in the file disk_image.img |
| 10 | +# Calling it for the second time will unmount the mounted images |
| 11 | +# |
| 12 | + |
| 13 | +if [ -z "$*" ] ; then |
| 14 | +echo " ~ Multi Mounter, 2015 by ppelikan ~ " |
| 15 | +echo "Mount images containing multiple partitions" |
| 16 | +echo "USAGE: call multimounter as root and as the parameter provide name of the disk image file" |
| 17 | +echo "Example:" |
| 18 | +echo "user@user:~$ sudo ~/multimounter.sh disk_image.img" |
| 19 | +echo "It will mount (in the current directory that is ~/) disks from the image in the file disk_image.img" |
| 20 | +echo "Calling it for the second time will unmount the mounted images" |
| 21 | +exit 0 |
| 22 | + |
| 23 | +fi |
| 24 | + |
| 25 | +NAME=$(basename $1) |
| 26 | +FDIS=$(fdisk -o device,start -l $1 | awk '/'$NAME'[1-9]/ {print $2}') |
| 27 | +UNIT=$(fdisk -u -l $1 | grep -Eo '= [0-9]+' | awk '{print $2}') |
| 28 | + |
| 29 | +PAR1=$(echo $FDIS | awk '{print $1}') |
| 30 | +PAR2=$(echo $FDIS | awk '{print $2}') |
| 31 | +PAR3=$(echo $FDIS | awk '{print $3}') |
| 32 | +PAR4=$(echo $FDIS | awk '{print $4}') |
| 33 | +PAR5=$(echo $FDIS | awk '{print $5}') |
| 34 | +PAR6=$(echo $FDIS | awk '{print $6}') |
| 35 | +PAR7=$(echo $FDIS | awk '{print $7}') |
| 36 | +PAR8=$(echo $FDIS | awk '{print $8}') |
| 37 | +PAR9=$(echo $FDIS | awk '{print $9}') |
| 38 | + |
| 39 | + |
| 40 | +DIR="parition1" |
| 41 | +if [ -n "$PAR1" ] ; then |
| 42 | + if [ -d "$DIR" ] ; then |
| 43 | + umount $DIR |
| 44 | + rmdir $DIR |
| 45 | + echo "Unmounted " $DIR |
| 46 | + else |
| 47 | + let OFFSET1=$PAR1*$UNIT |
| 48 | + mkdir $DIR |
| 49 | + mount -o loop,offset=$OFFSET1 $1 $DIR |
| 50 | + echo "Mounted " $DIR |
| 51 | + fi |
| 52 | +fi |
| 53 | + |
| 54 | +DIR="parition2" |
| 55 | +if [ -n "$PAR2" ] ; then |
| 56 | + if [ -d "$DIR" ] ; then |
| 57 | + umount $DIR |
| 58 | + rmdir $DIR |
| 59 | +echo "Unmounted " $DIR |
| 60 | + else |
| 61 | + let OFFSET2=$PAR2*$UNIT |
| 62 | + mkdir $DIR |
| 63 | + mount -o loop,offset=$OFFSET2 $1 $DIR |
| 64 | +echo "Mounted " $DIR |
| 65 | + fi |
| 66 | +fi |
| 67 | + |
| 68 | +DIR="parition3" |
| 69 | +if [ -n "$PAR3" ] ; then |
| 70 | + if [ -d "$DIR" ] ; then |
| 71 | + umount $DIR |
| 72 | + rmdir $DIR |
| 73 | +echo "Unmounted " $DIR |
| 74 | + else |
| 75 | + let OFFSET3=$PAR3*$UNIT |
| 76 | + mkdir $DIR |
| 77 | + mount -o loop,offset=$OFFSET3 $1 $DIR |
| 78 | +echo "Mounted " $DIR |
| 79 | + fi |
| 80 | +fi |
| 81 | + |
| 82 | +DIR="parition4" |
| 83 | +if [ -n "$PAR4" ] ; then |
| 84 | + if [ -d "$DIR" ] ; then |
| 85 | + umount $DIR |
| 86 | + rmdir $DIR |
| 87 | +echo "Unmounted " $DIR |
| 88 | + else |
| 89 | + let OFFSET4=$PAR4*$UNIT |
| 90 | + mkdir $DIR |
| 91 | + mount -o loop,offset=$OFFSET4 $1 $DIR |
| 92 | +echo "Mounted " $DIR |
| 93 | + fi |
| 94 | +fi |
| 95 | + |
| 96 | +DIR="parition5" |
| 97 | +if [ -n "$PAR5" ] ; then |
| 98 | + if [ -d "$DIR" ] ; then |
| 99 | + umount $DIR |
| 100 | + rmdir $DIR |
| 101 | +echo "Unmounted " $DIR |
| 102 | + else |
| 103 | + let OFFSET5=$PAR5*$UNIT |
| 104 | + mkdir $DIR |
| 105 | + mount -o loop,offset=$OFFSET5 $1 $DIR |
| 106 | +echo "Mounted " $DIR |
| 107 | + fi |
| 108 | +fi |
| 109 | + |
| 110 | +DIR="parition6" |
| 111 | +if [ -n "$PAR6" ] ; then |
| 112 | + if [ -d "$DIR" ] ; then |
| 113 | + umount $DIR |
| 114 | + rmdir $DIR |
| 115 | +echo "Unmounted " $DIR |
| 116 | + else |
| 117 | + let OFFSET6=$PAR6*$UNIT |
| 118 | + mkdir $DIR |
| 119 | + mount -o loop,offset=$OFFSET6 $1 $DIR |
| 120 | +echo "Mounted " $DIR |
| 121 | + fi |
| 122 | +fi |
| 123 | + |
| 124 | +DIR="parition7" |
| 125 | +if [ -n "$PAR7" ] ; then |
| 126 | + if [ -d "$DIR" ] ; then |
| 127 | + umount $DIR |
| 128 | + rmdir $DIR |
| 129 | +echo "Unmounted " $DIR |
| 130 | + else |
| 131 | + let OFFSET7=$PAR7*$UNIT |
| 132 | + mkdir $DIR |
| 133 | + mount -o loop,offset=$OFFSET7 $1 $DIR |
| 134 | +echo "Mounted " $DIR |
| 135 | + fi |
| 136 | +fi |
| 137 | + |
| 138 | +DIR="parition8" |
| 139 | +if [ -n "$PAR8" ] ; then |
| 140 | + if [ -d "$DIR" ] ; then |
| 141 | + umount $DIR |
| 142 | + rmdir $DIR |
| 143 | +echo "Unmounted " $DIR |
| 144 | + else |
| 145 | + let OFFSET8=$PAR8*$UNIT |
| 146 | + mkdir $DIR |
| 147 | + mount -o loop,offset=$OFFSET8 $1 $DIR |
| 148 | +echo "Mounted " $DIR |
| 149 | + fi |
| 150 | +fi |
| 151 | + |
0 commit comments