dheerajjotwani
Discoverer
okay here is it copy pasted...
Problem:
Tonidoplug when connected with the certain USB drives with multiple partitions, mounts the partitions in random order every time the drive is connected. For example, partition /dev/sda1 is mounted on /media/usb0 when connected, and the same partition /dev/sda1 will be mounted on /media/usb1 when reconnected. This happens only when the USB drive has multiple partitions.
Reason:
When USB drive is connected to Tonidoplug, the Linux OS running in Tonidoplug detects the partitions on the drive in random order. The "usbmount" subsystem mounts the partitions on the available mount point as the partitions are detected.
Solution:
Follow these steps to ensure the partitions are mounted in the same mount point every time the harddisk is connected.
Use this script at your own risk. This script is not supported by codelathe.
- These steps are not tested(since I dont have this problem).
- These steps will work only for USB mounting. Not for USB booting
1) Create a script /etc/usbmount/mount.d/00_a_ensure_mount_order
2) Place the following contents into this new script.
Code:
#!/bin/bash
# Script name: /etc/usbmount/mount.d/00_a_ensure_mount_order
# Beta script: not tested
# This script will ensure mount order of harddisk
# This script will not be effective in changing the boot order
set -e
LOGFILE="/root/usbmount.log"
# Enlist the partitions and its desired mount path
DEVICE[0]=/dev/sda1
MOUNTPOINT[0]="/media/usb0"
DEVICE[1]=/dev/sda2
MOUNTPOINT[1]="/media/usb1"
DEVICE[2]=/dev/sda3
MOUNTPOINT[2]="/media/usb2"
log()
{
echo "$1" >> $LOGFILE
}
start_script()
{
log ">>>Detected device start: $UM_DEVICE>>>>>>>>"
}
exit_script()
{
log "<<<Detected device end : $UM_DEVICE<<<<<<<<"
exit
}
start_script
#Check if the devices and mount points match
if [[ ${#DEVICE[*]} -ne ${#MOUNTPOINT[*]} ]]; then
log "Device and Mount mismatch"
exit_script
fi
MTPOINT=
index=0
#Check if the mounted device is on the desired partitions list
for d in ${DEVICE[*]}
do
if test "${DEVICE[index]}" = "$UM_DEVICE"; then
MTPOINT=${MOUNTPOINT[index]}
fi
let index=$index+1
done
if test ! -z $MTPOINT; then
log "Match found for $UM_DEVICE"
log "Matching mount point $MTPOINT"
else
log "Device not found on the list..exiting."
exit_script
fi
#Unmount the device
# Better logic can be added to check if the device is mounted
# at the correct desired location. Unmount only if not.
log "executing command: umount -l $UM_MOUNTPOINT"
umount -l "$UM_MOUNTPOINT"
#Mount the device at the right path
log "executing command: mount $UM_DEVICE $MTPOINT"
mount $UM_DEVICE $MTPOINT
#Finally set the mount path to UM_MOUNTPOINT
export UM_MOUNTPOINT="$MTPOINT"
exit_script
3) Save the script.
4) The above script has a predefined set of 3 mount points. Add or modify the list.
5) Assign executable permission to the script
Code:
chmod +x /etc/usbmount/mount.d/00_a_ensure_mount_order
6) Connect the USB device multiple times and ensure the mount order. Debug logs will be created under /root/usbmount.log