Skip to content

Instantly share code, notes, and snippets.

@koter84
Last active February 16, 2020 01:50
Show Gist options
  • Save koter84/a5ddcb55f88faa416c53 to your computer and use it in GitHub Desktop.
Save koter84/a5ddcb55f88faa416c53 to your computer and use it in GitHub Desktop.
mount TOMTOM.000 TOMTOM.001 etc. files from SD-card through a raid-loop-device
#!/bin/bash
TTDir="$1"
MountDir="$2"
if [ "$TTDir" == "" ]; then
echo "empty ttdir"
exit
fi
if [ "$MountDir" == "" ]; then
echo "empty mountdir"
exit
fi
sudo true
echo -n "> detecting number of loop-files"
if [ -f $TTDir/TOMTOM.010 ]; then
echo " - to high a number found... untested... and not working"
exit
elif [ -f $TTDir/TOMTOM.009 ]; then
TTCnt="9"
elif [ -f $TTDir/TOMTOM.008 ]; then
TTCnt="8"
elif [ -f $TTDir/TOMTOM.007 ]; then
TTCnt="7"
elif [ -f $TTDir/TOMTOM.006 ]; then
TTCnt="6"
elif [ -f $TTDir/TOMTOM.005 ]; then
TTCnt="5"
elif [ -f $TTDir/TOMTOM.004 ]; then
TTCnt="4"
elif [ -f $TTDir/TOMTOM.003 ]; then
TTCnt="3"
elif [ -f $TTDir/TOMTOM.002 ]; then
TTCnt="2"
elif [ -f $TTDir/TOMTOM.001 ]; then
TTCnt="1"
elif [ -f $TTDir/TOMTOM.000 ]; then
TTCnt="0"
else
echo " - no proper TOMTOM.xxx file found"
exit
fi
echo " - $(expr $TTCnt + 1) - done"
echo -n "> attaching loop-files to loop-devices -"
for ((cnt=0; cnt<=$TTCnt; cnt++))
do
echo -n " $cnt"
sudo losetup /dev/loop$cnt $TTDir/TOMTOM.00$cnt
done
echo " - done"
echo -n "> setting up a linear raid from loop-devices"
eval "sudo mdadm --build --auto=part --quiet /dev/md1 --level=linear -n4 /dev/loop[0-$TTCnt]"
echo " - done"
echo -n "> mounting the raid"
sudo mount /dev/md1 $MountDir
echo " - done"
echo ""
echo ">> TOMTOM-filesystem mounted at $MountDir"
read -p ">> press enter to unmount after you are done"
echo ""
echo -n "> unmounting the raid"
sudo umount $MountDir
echo " - done"
echo -n "> disabling the linear raid"
sudo mdadm --quiet -S /dev/md1
echo " - done"
echo -n "> disabling the loop-devices"
eval "sudo losetup -d /dev/loop[0-$TTCnt]"
echo " - done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment