Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
zh:docs:guide-user:base-system:hotplug [2019/04/09 09:04] – [block 文件夹] czhongmzh:docs:guide-user:base-system:hotplug [2019/04/09 09:28] – [示例] czhongm
Line 53: Line 53:
 ==== iface 文件夹 ==== ==== iface 文件夹 ====
  
-There are three main environment variables that are passed to each **iface** hotplug script:+传递给每个 **iface** 热插拔脚本有三个主要的环境变量:
 ^ 变量名 ^ 描述 ^ ^ 变量名 ^ 描述 ^
-| ACTION | Either "ifup"  or "ifdown"+| ACTION | "ifup"  或 "ifdown"
-| INTERFACE | Name of the interface which went up or down (e.g. "wan" or "ppp0")+| INTERFACE | 上线或下线的接口名称(例如“wan”或“ppp0”)
-| DEVICE | Physical device name which interface went up or down (e.g. "eth0.1" or "br-lan")|+| DEVICE | 接口上线或下线的物理设备名称(例如“eth0.1”或“br-lan”)|
  
-==== The ntp folder ====+==== ntp 文件夹 ====
  
 ^ 变量名 ^ 描述 ^ ^ 变量名 ^ 描述 ^
-| ACTION | step, stratum, unsync or periodic | +| ACTION | step, stratum, unsync 或 periodic | 
-| freq_drift_ppm | ntp variables +| freq_drift_ppm | ntp 变量 
-| offset | ntp variables +| offset | ntp 变量 
-| stratum | ntp variables +| stratum | ntp 变量 
-| poll_interval | ntp variables |+| poll_interval | ntp 变量 |
  
-Even without NTP sync, you will receive a periodic hotplug event, with stratum=16, about every 11 minutes out of the box.+ 
 +即使没有NTP同步,您也会收到一个定期的热插拔事件,其中stratum=16,开机后大约每11分钟一次。
  
 ==== usb 文件夹 ==== ==== usb 文件夹 ====
 ^ 变量名 ^ 描述 ^ ^ 变量名 ^ 描述 ^
-| ACTION | add, remove as above +| ACTION | add, remove 如上 
-| DEVNAME | eg, "bus/usb/001/002"+| DEVNAME | 如 "bus/usb/001/002"
-| DEVPATH | eg, "/devices/platform/ehci-platform/usb1/1-1"+| DEVPATH | 如 "/devices/platform/ehci-platform/usb1/1-1"
-| DEVICENAME | eg "1-1"+| DEVICENAME | 如 "1-1"
-| DEVNUM | eg 002 |+| DEVNUM | 如 002 |
 | DRIVER | "usb" | | DRIVER | "usb" |
-| TYPE | eg 9/0/1 | +| TYPE | 如 9/0/1 | 
-| PRODUCT | the vendor/productcode/versioneg "424/2640/0" see lsusb +| PRODUCT | 供应商/产品代码/版本如用lsusb看到的 "424/2640/0"
-| SEQNUM | ? eg 335 | +| SEQNUM | ? 如 335 | 
-| BUSNUM | eg 001 | +| BUSNUM | 如 001 | 
-| MAJOR | eg 189 | +| MAJOR | 如 189 | 
-| MINOR | eg 1 |+| MINOR | 如 1 |
  
 ===== 示例 ===== ===== 示例 =====
Line 122: Line 123:
 === 符号链接代替设备重命名 === === 符号链接代替设备重命名 ===
  
-An other script to create a symlink instead of renaming the device.\\ +另一个用于创建符号链接而不是重命名设备的脚本。\\ 
-I test if DEVICE_NAME is empty because when I plug usb device I retrieve two add event, and the first come before created device, so symlink fails.+因为当我插入一个usb设备时会收到2个add事件,而为了确保在创建符号链接前设备已经创建,我在这里增加了一个判断DEVICE_NAME是否为空.
 <code bash> <code bash>
 cat << "EOF" > /etc/hotplug.d/usb/20-cp210x cat << "EOF" > /etc/hotplug.d/usb/20-cp210x
Line 153: Line 154:
 </code> </code>
  
-=== Script that detects if plugged usb device is bluetooth or not. ===+=== 检测插入的usb设备是否蓝牙的脚本 ===
  
 <code bash> <code bash>
Line 180: Line 181:
 </code> </code>
  
-=== Auto start mjpg-streamer when an usb camera is plugged in. ===+=== 当usb摄像头插入时自动启动mjpg-streamer ===
 <code bash> <code bash>
 cat << "EOF" > /etc/hotplug.d/usb/20-mjpg_start cat << "EOF" > /etc/hotplug.d/usb/20-mjpg_start
Line 196: Line 197:
 </code> </code>
  
-=== Custom automount script for xfs ===+=== xfs的自定义自动挂载脚本 ===
 <code bash> <code bash>
 cat << "EOF" > /etc/hotplug.d/block/xfs_automount cat << "EOF" > /etc/hotplug.d/block/xfs_automount
-if a new block device is connected+如果新的block设备已连接
 if [ "$ACTION" = "add" ] ; then if [ "$ACTION" = "add" ] ; then
-    # getting device UUID+    # 获取设备 UUID
     detected_uuid=$( xfs_admin -u /dev/$DEVICENAME | awk '{print $3}' )     detected_uuid=$( xfs_admin -u /dev/$DEVICENAME | awk '{print $3}' )
-    # deciding mountpoint for known UUID+    # 确定已知UUID的挂载点
     mountpoint=""     mountpoint=""
     case "$detected_uuid" in     case "$detected_uuid" in
Line 214: Line 215:
    esac    esac
  
-   # if we have a known UUID we have a mountpoint so we can mount it+   # 如果有一个挂载点,则挂载它
    if [ "$mountpoint" != "" ] ; then     if [ "$mountpoint" != "" ] ; then 
        mount /dev/$DEVICENAME $mountpoint        mount /dev/$DEVICENAME $mountpoint
    fi    fi
 fi fi
-unmounting happens automatically at device disconnection anyway so no logic for that+无论如何,卸载在设备断开时自动发生,因此没有逻辑操作
 EOF EOF
 </code> </code>
  • Last modified: 2019/04/09 09:34
  • by czhongm