树莓派论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2812|回复: 0
收起左侧

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

[复制链接]
发表于 2013-3-19 11:34:23 | 显示全部楼层 |阅读模式
本帖最后由 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. 编辑文件加入代码:
  1. #!/bin/bash
  2. # Script name: /etc/usbmount/mount.d/00_a_ensure_mount_order
  3. # Beta script: not tested
  4. # This script will ensure mount order of harddisk
  5. # This script will not be effective in changing the boot order

  6. set -e
  7. LOGFILE="/root/usbmount.log"

  8. # Enlist the partitions and its desired mount path
  9. DEVICE[0]=/dev/sda1
  10. MOUNTPOINT[0]="/media/usb0"
  11. DEVICE[1]=/dev/sda5
  12. MOUNTPOINT[1]="/media/usb1"
  13. DEVICE[2]=/dev/sda6
  14. MOUNTPOINT[2]="/media/usb2"
  15. DEVICE[3]=/dev/sda7
  16. MOUNTPOINT[3]="/media/usb3"
  17. log()
  18. {
  19.        echo "$1" >> $LOGFILE
  20. }

  21. start_script()
  22. {
  23.    log ">>>Detected device start: $UM_DEVICE>>>>>>>>"
  24. }
  25. exit_script()
  26. {
  27.    log "<<<Detected device end : $UM_DEVICE<<<<<<<<"
  28.    exit
  29. }

  30. start_script

  31. #Check if the devices and mount points match
  32. if [[ ${#DEVICE[*]} -ne ${#MOUNTPOINT[*]} ]]; then
  33.         log "Device and Mount mismatch"
  34.         exit_script
  35. fi

  36. MTPOINT=
  37. index=0

  38. #Check if the mounted device is on the desired partitions list
  39. for d in ${DEVICE[*]}
  40. do
  41.         if test "${DEVICE[index]}" = "$UM_DEVICE"; then
  42.                 MTPOINT=${MOUNTPOINT[index]}
  43.         fi
  44.         let index=$index+1
  45. done

  46. if test ! -z $MTPOINT; then
  47.         log "Match found for $UM_DEVICE"
  48.         log "Matching mount point $MTPOINT"
  49. else
  50.         log "Device not found on the list..exiting."
  51.         exit_script
  52. fi

  53. #Unmount the device
  54. # Better logic can be added to check if the device is mounted
  55. # at the correct desired location. Unmount only if not.
  56. log "executing command: umount -l $UM_MOUNTPOINT"
  57. umount -l "$UM_MOUNTPOINT"

  58. #Mount the device at the right path
  59. log "executing command: mount $UM_DEVICE $MTPOINT"
  60. mount $UM_DEVICE $MTPOINT

  61. #Finally set the mount path to UM_MOUNTPOINT
  62. export UM_MOUNTPOINT="$MTPOINT"

  63. exit_script
复制代码
3. 文件开头定义了四个分区及相应挂载位置,请大家修改以满足需要
查看分区信息:
sudo fdisk -l
例如我的:
  1. Disk /dev/sda: 320.1 GB, 320072931328 bytes
  2. 255 heads, 63 sectors/track, 38913 cylinders, total 625142444 sectors
  3. Units = sectors of 1 * 512 = 512 bytes
  4. Sector size (logical/physical): 512 bytes / 512 bytes
  5. I/O size (minimum/optimal): 512 bytes / 512 bytes
  6. Disk identifier: 0x76692ca8

  7.    Device Boot      Start         End      Blocks   Id  System
  8. /dev/sda1   *          63     4209029     2104483+   7  HPFS/NTFS/exFAT
  9. /dev/sda2         4209030   625137344   310464157+   f  W95 Ext'd (LBA)
  10. /dev/sda5         4209093    88116524    41953716    7  HPFS/NTFS/exFAT
  11. /dev/sda6        88116588   457338419   184610916    7  HPFS/NTFS/exFAT
  12. /dev/sda7       457338483   625137344    83899431    7  HPFS/NTFS/exFAT
复制代码
需要说明的是其中的/dev/sda2对应整个扩展分区(sda5, sda6, sda7),所以不用挂它

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

帮到忙的话还请顶一顶,希望可以帮到更多人。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|树莓派论坛 ( 粤ICP备15075382号-1  

GMT+8, 2024-11-26 01:47 , Processed in 1.109375 second(s), 24 queries , Gzip On.

Powered by Shumeipai.net! X3.2

© 2001-2015 树莓派论坛安全联盟

快速回复 返回顶部 返回列表