°Ô½Ã¹° 1,369°Ç
   
udev rule
±Û¾´ÀÌ : ÃÖ°í°ü¸®ÀÚ ³¯Â¥ : 2013-05-15 (¼ö) 09:26 Á¶È¸ : 7601
±ÛÁÖ¼Ò :
                                
Ãâó : http://visionmaru.com/wp/?p=147


ÀÌ ¹®¼­´Â http://www.reactivated.net/writing_udev_rules.html ¸¦ ¿ä¾à Á¤¸®ÇÑ °ÍÀ¸·Î, udevÀÇ ruleÀ» Á¤ÀÇÇÏ´Â ¹æ¹ý¿¡ °üÇÑ ±ÛÀÌ´Ù.


udev¶õ?

    ¸®´ª½º hotplug ÇÁ·ÎÁ§Æ®ÀÇ ÇÏÀ§(?) ÇÁ·ÎÁ§Æ®·Î ÀåÄ¡°¡ Ãß°¡µÇ¾úÀ»¶§ÀÇ Ã³¸®¿¡ °üÇØ Ä¿³ÎÀÇ uevent¸¦ ÀÌ¿ëÇÏ¿© ó¸®ÇÏ´Â ÇÁ·ÎÁ§Æ®ÀÌ´Ù. ÀÚ¼¼ÇÑ »çÇ×Àº ¿©±â¸¦ ÂüÁ¶ÇϽöó.
    udev ruleÀº udev°¡ µ¿ÀÛÇÏ´Â ±ÔÄ¢À» ¸»ÇÏ´Â °ÍÀ¸·Î, ¾î¶°ÇÑ uevent°¡ ¹ß»ý ÇßÀ»¶§ ¾î¶»°Ô ó¸®ÇÒ Áö¸¦ ¸í½ÃÇØ µÐ ÅؽºÆ®·Î ±¸¼ºµÈ ±ÔÄ¢ ÆÄÀÏÀÌ´Ù.


rule ÆÄÀÏ ±ÔÄ¢

    /etc/udev/udev.d/ µð·ºÅ丮¿¡ Á¸ÀçÇؾßÇϸç, suffix´Â .rules À̾î¾ß ÇÑ´Ù.


±âº» ¹®¹ý

    ¸ðµç ·êÀº key-value pair·Î ±¸¼ºµÇ°í, ±âº» ¹®¹ýÀº ´ÙÀ½°ú °°´Ù.

    match[, <match>]*, assignment[, <assignment>]*\n

    1°³ÀÌ»óÀÇ match¿Í 1°³ÀÌ»óÀÇ assignment°¡ ,(ÄÞ¸¶)·Î ¿¬°áµÇ°í °ø¹éÀ¸·Î ±¸ºÐµÇ¾îÁ® ÀÖ°í ÇϳªÀÇ ¶óÀÎÀ¸·Î ±¸¼ºµÈ´Ù.

    • match´Â Á¶°ÇÀÌ´Ù. ¸¸Á·ÇÒ °æ¿ì ÇØ´ç rule¿¡ ±âÀçµÈ assignment°¡ ½ÇÇàµÈ´Ù. <match-key>¿Í <Á¶°Ç>»çÀÌ¿¡ ¡°==¡±À¸·Î ¿¬°áµÈ´Ù.
    • assignment´Â ÀÏÁ¾ÀÇ actionÀÌ´Ù. matchÁ¶°ÇÀÌ ¸¸Á·ÇÒ °æ¿ì¸¸ ½ÇÇàµÈ´Ù. <assignment-key>¿Í »çÀÌ¿¡ ¡°=¡±À¸·Î ¿¬°áµÈ´Ù.



±âº» »çÇ×

    match key´Â ´ÙÀ½°ú °°Àº°ÍÀÌ ÀÖ´Ù.

    • KERNEL – Ä¿³Î¿¡¼­ »ç¿ëÇÏ´Â ÀåÄ¡¸í
    • SUBSYSTEM – ÀåÄ¡°¡ ¼ÓÇÑ SUBSYSTEM
    • DRIVER – ÀåÄ¡ µå¶óÀ̹öÀÇ À̸§

    assignment key´Â ´ÙÀ½°ú °°Àº°ÍÀÌ ÀÖ´Ù.

    • NAME – ÀåÄ¡ ³ëµåÀÇ À̸§
    • SYMLINK – NAME¿Ü¿¡ symbolicÀ¸·Î ¸µÅ©ÇÒ À̸§

    KERNEL=="hdb", NAME="my_spare_disk"
    hdbÀåÄ¡°¡ Ãß°¡µÇ¸é /dev/my_spare_disk ³ëµå¸¦ »ý¼ºÇÑ´Ù.

    KERNEL=="hdb", DRIVER=="ide-disk", SYMLINK+="my_spare_disk"
    hdbÀåÄ¡°¡ Ãß°¡µÇ°í hdbÀÇ µå¶óÀ̹ö°¡ ide-diskÀ̸é (/dev/hdb³ëµå¸¦ »ý¼ºÇÏ°í) /dev/my_spare_disk·Î symbolic link ÇÑ´Ù. NAME assignment°¡ »ý·«µÇ¸é default node¸¦ »ý¼ºÇϴµ¥ ¿©±â¼­´Â /dev/hdb°¡ µÈ´Ù.

    KERNEL=="hdc", SYMLINK+="cdrom cdrom0"
    hdcÀåÄ¡°¡ Ãß°¡µÇ¸é (/dev/hdc³ëµå¸¦ »ý¼ºÇÏ°í) /dev/cdrom°ú /dev/cdrom0·Î symbolic linkÇÑ´Ù.


sysfs attributes¸¦ match key·Î »ç¿ëÇϱâ

    SUBSYSTEM=="block", ATTR{SIZE}=="234441648", SYMLINK+="my_disk"
    block ÀåÄ¡ Áß¿¡¼­ Å©±â°¡ 234441648ÀÎ ÀåÄ¡¸¦ /dev/my_disk·Î symbolic link ÇÑ´Ù. /sys/block/*/size°¡ Ãâ·ÂÇÏ´Â °ªÀ» »ç¿ëÇÑ °ÍÀÌ´Ù.


¹®ÀÚ¿­ ´ëÀÔ

    %k Ä¿³Î À̸§¿¡ ´ëÀÀÇÑ´Ù. ¡°sda¡±, ¡°sda1¡È µî.
    %n ÀåÄ¡ ¹øÈ£¿¡ ´ëÀÀÇÑ´Ù. ¡°sda1¡È¿¡¼­ ¡°1¡ÈÀÌ ¿©±â¿¡ ÇØ´çÇÑ´Ù.
    %% escape·Î¼­ ¡°%¡±¸¦ Ç¥ÇöÇÑ´Ù.
    $$ ÀÌ°Í ¿ª½Ã escape·Î¼­ ¡°$¡±¸¦ ³ªÅ¸³½´Ù.

    KERNEL=="mice", NAME="input/%k"
    µðÆúÆ®·Î miceÀåÄ¡°¡ Ãß°¡µÇ¸é /dev/mice¸¦ »ý¼ºÇØ¾ß ÇÏÁö¸¸, ÀÌ·ê¿¡ ÀÇÇØ /dev/input/mice ¸¦ »ý¼ºÇÑ´Ù.

    KERNEL=="loop0", NAME="loop/%n", SYMLINK+="%k"
    loop0°¡ Ãß°¡µÇ¸é /dev/loop/0¸¦ »ý¼ºÇÏ°í Ãß°¡·Î /dev/loop0¸¦ symbolicÀ¸·Î linkÇÑ´Ù.


¹®ÀÚ¿­ ºñ±³

    • ¡°*¡± 0ÀÌ»óÀÇ ¾î¶°ÇÑ ¹®ÀÚ
    • ¡°?¡± 1°³ÀÇ °ø¹éÀÌ ¾Æ´Ñ ¹®ÀÚ
    • ¡°[]¡± ´ë°ýÈ£ ¾È¿¡ Á¸ÀçÇÏ´Â ¹®ÀÚ Áß Çϳª(range Çã¿ë)

    KERNEL=="fd[0-9]*", NAME="floppy/%n", SYMLINK+="%k"
    fd0, fd1, ¡¦, fd9, fd10, fd11, ¡¦ µîÀÌ Ãß°¡µÇ¸é /dev/floppy/¹øÈ£ ³ëµå¸¦ »ý¼ºÇÏ°í /dev/floppy¹øÈ£ symbolic linkµµ »ý¼ºÇÑ´Ù.

    KERNEL=="hiddev*", NAME="usb/%k"
    hiddev·Î ½ÃÀÛÇÏ´Â ÀåÄ¡°¡ Ãß°¡µÇ¸é /dev/usb/ÀåÄ¡¸íÀ¸·Î ³ëµå¸¦ »ý¼ºÇÑ´Ù.


±ÇÇÑ ¹× ¼ÒÀ¯±Ç Á¦¾î

    KERNEL=="fb[0-9]*", NAME="fb/%n", SYMLINK+="%k", GROUP="video"
    GROUP assignment keyÀÌ´Ù. ÁöÁ¤µÈ ±×·ì¸íÀ¸·Î ¼Ò¼Ó ±×·ìÀ» ÁöÁ¤ÇÑ´Ù.

    KERNEL="fb[0-9]*", OWNER="john"
    OWNER assignment keyÀÌ´Ù. ÁöÁ¤µÈ »ç¿ëÀÚ¸íÀ¸·Î ¼ÒÀ¯ÀÚ¸¦ ÁöÁ¤ÇÑ´Ù.

    KERNEL="inotify", NAME="misc/%k", SYMLINK+="%k", MODE="0666"
    MODE assignment keyÀÌ´Ù. ÆÄÀÏÀÇ ¸ðµå¸¦ ¼³Á¤ÇÑ´Ù.


³×À̹ÖÀ» À§ÇØ ¿ÜºÎ ÇÁ·Î±×·¥ »ç¿ëÇϱâ

    PROGRAM assignment key¿Í ¡°%c¡± substitutionÀÌ »ç¿ëµÈ´Ù.
    PROGRAM=¡±absolute-path-to-executable arg1 arg2 ¡¦ argN¡±

    KERNEL==¡±hda¡±, PROGRAM=¡±/bin/device_namer %k¡±, SYMLINK+=¡±%c¡±
    hdaÀåÄ¡°¡ Ãß°¡µÇ¸é ¡°/bin/device_namer hda¡±¸¦ ½ÇÇàÇÏ°í, stdoutÀ¸·Î ³ª¿Â °á°ú ¹®ÀÚ¿­À» ÀÌ¿ëÇؼ­ symbolic linkÇÑ´Ù.

    KERNEL==¡±hda¡±, PROGRAM=¡±/bin/device_namer %k¡±, NAME=¡±%c{1}¡±, SYMLINK+=¡±%c{2}¡±
    hdaÀåÄ¡°¡ Ãß°¡µÇ¸é ¡°/bin/device_namer hda¡±¸¦ ½ÇÇàÇÏ°í, stdoutÀ¸·Î ³ª¿Â °á°ú ¹®ÀÚ¿­Áß¿¡ 1¹ø° °á°ú°ªÀ¸·Î ³ëµå¸¦ »ý¼ºÇÏ°í, 2¹ø° °á°ú°ªÀ» ÀÌ¿ëÇؼ­ symbolic linkÇÑ´Ù.

    KERNEL==¡±hda¡±, PROGRAM=¡±/bin/device_namer %k¡±, NAME=¡±%c{1}¡±, SYMLINK+=¡±%c{2+}¡±
    hdaÀåÄ¡°¡ Ãß°¡µÇ¸é ¡°/bin/device_namer hda¡±¸¦ ½ÇÇàÇÏ°í, stdoutÀ¸·Î ³ª¿Â °á°ú ¹®ÀÚ¿­Áß¿¡ 1¹ø° °á°ú°ªÀ¸·Î ³ëµå¸¦ »ý¼ºÇÏ°í, 2¹ø°ºÎÅÍ ¸ðµç °á°ú°ªÀ» ÀÌ¿ëÇؼ­ symbolic linkÇÑ´Ù.


¿ÜºÎ ÇÁ·Î±×·¥ µ¿ÀÛ½ÃÅ°±â

    À§¿¡¼­´Â ³×À̹ÖÀ» À§ÇØ ¿ÜºÎ ÇÁ·Î±×·¥À» µ¿ÀÛ ½ÃÄ×À¸³ª, ƯÁ¤ÇÑ ¾×¼ÇÀ» ÃëÇÏ°Ô ÇϱâÀ§ÇØ ¿ÜºÎ ÇÁ·Î±×·¥À» ¼öÇà ½Ãų ¼ö ÀÖ´Ù. ¼öÇà ½ÃÁ¡Àº ³ëµå°¡ »ý¼ºµÈ ÀÌÈÄÀÌ´Ù. ÁÖÀÇÁ¡Àº Áï½Ã ¼öÇàÀÌ ¿Ï·áµÇ¾î¾ß ÇÑ´Ù. ÀÌ ÇÁ·Î±×·¥ÀÌ µ¿ÀÛÁß¿¡ udev´Â ¸ØÃçÀִ´Ù. ÀÌ ÇÁ·Î±×·¥Àº udevÀÇ È¯°æº¯¼ö¸¦ ÀÚ½ÅÀÇ È¯°æº¯¼ö·Î »ç¿ëÇÒ ¼ö ÀÖ´Ù. ¿¹¸¦µé¾î val = getenv(¡°ACTION¡±); À» ÅëÇØ valÀÌ ¡°add¡±ÀÏ °æ¿ì¿Í ¡°remove¡±ÀÏ °æ¿ì¿¡ °¢°¢ µ¿ÀÛÀ» ´Þ¸® ÇÒ ¼ö ÀÖ´Ù.

    KERNEL=="sdb", RUN+="/usr/bin/my_program"
    sdbÀåÄ¡°¡ Ãß°¡µÇ¸é(Ãß°¡µÇ°í ³ëµå°¡ »ý¼ºµÇ¸é) /usr/bin/my_programÀ» ¼öÇàÇÑ´Ù.


ȯ°æº¯¼ö »ç¿ë

    ENV´Â matching key¿Í assignment key µÎ°¡Áö·Î »ç¿ëÇÒ ¼ö ÀÖ´Ù.

      assignment key·Î »ç¿ëÇϱâ
      KERNEL=="fd0", SYMLINK+="floppy", ENV{some_var}="value"
      fd0¶ó Ãß°¡µÇ¸é $some_var°¡ value·Î ¼³Á¤µÈ´Ù.
      matching key·Î »ç¿ëÇϱâ
      KERNEL=="fd0", ENV{an_env_var}=="yes", SYMLINK+="floppy"
      fd0°¡ Ãß°¡µÇ°í ȯ°æº¯¼ö $an_env_varÀÇ °ªÀÌ ¡°yes¡± ÀÏ °æ¿ì /dev/floppy·Î symbolic link ÇÑ´Ù.

À̸§ Æнº¿öµå
ºñ¹Ð±Û (üũÇÏ¸é ±Û¾´À̸¸ ³»¿ëÀ» È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.)
¿ÞÂÊÀÇ ±ÛÀÚ¸¦ ÀÔ·ÂÇϼ¼¿ä.
   

 



 
»çÀÌÆ®¸í : ¸ðÁö¸®³× | ´ëÇ¥ : ÀÌ°æÇö | °³ÀÎÄ¿¹Â´ÏƼ : ·©Å°´åÄÄ ¿î¿µÃ¼Á¦(OS) | °æ±âµµ ¼º³²½Ã ºÐ´ç±¸ | ÀüÀÚ¿ìÆí : mojily°ñ¹ðÀÌchonnom.com Copyright ¨Ï www.chonnom.com www.kyunghyun.net www.mojily.net. All rights reserved.