|
本帖最后由 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[0]=/dev/sda1
- MOUNTPOINT[0]="/media/usb0"
- DEVICE[1]=/dev/sda5
- MOUNTPOINT[1]="/media/usb1"
- DEVICE[2]=/dev/sda6
- MOUNTPOINT[2]="/media/usb2"
- DEVICE[3]=/dev/sda7
- MOUNTPOINT[3]="/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[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. 文件开头定义了四个分区及相应挂载位置,请大家修改以满足需要
查看分区信息:
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 Id System
- /dev/sda1 * 63 4209029 2104483+ 7 HPFS/NTFS/exFAT
- /dev/sda2 4209030 625137344 310464157+ f W95 Ext'd (LBA)
- /dev/sda5 4209093 88116524 41953716 7 HPFS/NTFS/exFAT
- /dev/sda6 88116588 457338419 184610916 7 HPFS/NTFS/exFAT
- /dev/sda7 457338483 625137344 83899431 7 HPFS/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
帮到忙的话还请顶一顶,希望可以帮到更多人。 |
|