mosesgi 发表于 2013-3-19 11:34:23

解决XBian下挂载分区移动硬盘的分区乱序问题

本帖最后由 mosesgi 于 2013-3-19 11:35 编辑

坛子里用XBian的不少,XBian使用usbmount自动挂载USB存储设备。
但这带来一个问题:如果挂了分区的移动硬盘的话,每次启动后移动硬盘的分区挂载顺序是乱的。
比如上次移动硬盘的第一分区挂到/media/usb0,下次就挂到/media/usb3去了。

下面是解决办法,使挂载目录固定。请按步骤执行。

1. 建立文件:/etc/usbmount/mount.d/00_a_ensure_mount_order
2. 编辑文件加入代码:#!/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=/dev/sda1
MOUNTPOINT="/media/usb0"
DEVICE=/dev/sda5
MOUNTPOINT="/media/usb1"
DEVICE=/dev/sda6
MOUNTPOINT="/media/usb2"
DEVICE=/dev/sda7
MOUNTPOINT="/media/usb3"
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}" = "$UM_DEVICE"; then
                MTPOINT=${MOUNTPOINT}
      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. 文件开头定义了四个分区及相应挂载位置,请大家修改以满足需要
查看分区信息:
sudo fdisk -l
例如我的:Disk /dev/sda: 320.1 GB, 320072931328 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142444 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x76692ca8

   Device Boot      Start         End      Blocks   IdSystem
/dev/sda1   *          63   4209029   2104483+   7HPFS/NTFS/exFAT
/dev/sda2         4209030   625137344   310464157+   fW95 Ext'd (LBA)
/dev/sda5         4209093    88116524    41953716    7HPFS/NTFS/exFAT
/dev/sda6      88116588   457338419   184610916    7HPFS/NTFS/exFAT
/dev/sda7       457338483   625137344    83899431    7HPFS/NTFS/exFAT
需要说明的是其中的/dev/sda2对应整个扩展分区(sda5, sda6, sda7),所以不用挂它

4. 保存退出
5. 加可执行权限chmod +x /etc/usbmount/mount.d/00_a_ensure_mount_order本人重启了几次测试是可用的。
原帖:http://www.tonido.com/forum/viewtopic.php?f=37&t=776

帮到忙的话还请顶一顶,希望可以帮到更多人。
页: [1]
查看完整版本: 解决XBian下挂载分区移动硬盘的分区乱序问题