Udev/ko

udev는 리눅스 커널용 장치 관리자입니다. 의 장치 노드를 관리하며 장치를 추가하고 제거할 때 모든 사용자 공간 처리 동작을 관리합니다. 이 글의 독자 여러분은 udev의 포크 버전인 eudev도 살펴보셔야 합니다.

/dev 디렉터리
When Linux users talk about the hardware on their system in the vicinity of people who believe Linux is some sort of virus or brand of coffee, the use of "slash dev slash foo" will return strange looks for sure. But for the fortunate user (and that includes the reader of this article) using is just a fast way of referring to the primary master SATA, first partition. That's pretty easy, right?

Most Linux users know what a device file is. Some even know why device files have special numbers. Take a close look at device list when is issued in the  folder. What users take for granted is that the primary SATA disk is referred to as Some users might not see it this way, but this is a flaw by design.

Think about hotpluggable devices like USB, IEEE1394, hot-swappable PCI, etc. What is the first device? And for how long? What will the other devices be named when the first one disappears? How will that affect ongoing transactions? Wouldn't it be fun that a printing job is suddenly moved from a super-new laser printer to an almost-dead matrix printer because someone's mom decided to pull the plug of the laser printer which just so happened to be the first printer?

Enter. The goals of the udev project are both interesting and needed. Udev:


 * Runs in userspace;
 * Dynamically creates and removes device files;
 * Provides consistent naming;
 * Provides a userspace application program interface (API).

Every time a change happens within the device structure, the kernel emits a uevent which gets picked up by. then follows the rules as declared in the, and  directories. Based on the information contained within the uevent, it finds the rule or rules it needs to trigger and performs the required actions. These actions can be creating or deleting device files, but can also trigger the loading of particular firmware files into kernel memory.

커널
에서는 다음 커널 옵션이 필요합니다:

USE 플래그
Portage knows the  global USE flag for enabling support for udev in other packages. Adding this USE flag value to the USE flag list (default in all Linux profiles) will pull in the package automatically:

Emerge
USE 변수를 설정한 후, 시스템을 업데이트하여 바뀐 설정을 적용하십시오:

서비스
부팅 시간에 udev를 시작하려면 sysinit 럴레벨에 추가하십시오. 다음 명령을 루트 권한으로 실행하면 처리할 수 있습니다:

규칙
udev provides a set of rules that match against exported values of uevents (events sent by the kernel) and properties of the discovered device. A matching rule will possibly name and create a device node and run configured programs to setup and configure the device.

정의 규칙은 다음 두군데에 저장합니다:


 * 1)  - Rules in this directory are installed by certain packages, they generally should not be changed by users;
 * 2)  - This folder is for end-user specified rules. Any new rules should be added in this directory;

In these directories, multiple rule files (with suffix ) are traversed in alphanumerical order. Inside the rules files, udev will find expressions that might match a uevent together with the state to match (is the uevent because a device is added or removed) and the command to execute.

The event matching is based on information such as:


 * The SUBSYSTEM of the uevent (for which type of device is the uevent fired);
 * The ACTION that is taken (add, change, or remove);
 * One or more attributes (through ATTR or ATTRS), such as the device class, vendor or other device information;
 * The kernel-provided name (through KERNEL), such as sd* (for SCSI/SATA disks) or input* (for input devices such as mice and keyboards);
 * One or more environment settings (through ENV), used to send information between multiple rules.

이 정보를 기반으로 다음의 조건에 따라, 규칙을 세울 수 있습니다:


 * 1) 일부 정보는 (환경 변수로)최종 이벤트와 공유해야 합니다
 * 2) 에 링크를 만들어야 합니다
 * 3) 명령을 실행해야 합니다

Udev does this for every rule that matches (it does not stop after the first match) to allow a flexible device management approach.

영속 장치 이름
The kernel detects devices asynchronously, udev mirrors the kernel's sysfs filesystem and so the devices are named and numbered in order of detection. So by default udev provides no persistent device names. However there are mechanisms for some device classes to provide these:


 * Udev creates for storage devices additional symlinks based on the device's ID, label, UUID and path. See the directory. So instead of using e.g. the device file  use the file.


 * The same for input devices in the directory.


 * Using custom rules enables users to create their own device files.

사용법
몇가지 쓸모있는 명령이 있습니다.


 * 주어진 장치에 대한 모든 메시지를 보여줍니다;


 * udev 활동을 감시합니다:

더 많은 정보는 udevadm 맨 페이지en 를 참고하십시오

감시 메시지 기록
를 실행할 때 모든 메시지를 기록하려면 다음 설정 파일을 수정하십시오:

에 새 로그 파일을 만듭니다

디버깅 모드
디버깅 모드를 활성화하면 더 많은 기록 메시지를 출력합니다:

기록 우선순위를 설정하십시오:

기록 파일을 만들겠지만 어떤 메시지도 기록하지 않습니다. 최근의 udev 버전에서는 에 모든 메시지를 기록합니다.

과 장치가 빠졌다고 합니다
일부 udev 버전에서는 udev가 제대로 동작하려면 과 이 필요합니다. 그러나 자체적으로 만들 수는 없습니다. 이 파일을 직접 만들려면 루트 권한으로 다음 명령을 실행하십시오:

NIC에 eth0을 할당했는데 eth1으로 바뀌네요
Those having dual network cards on their motherboards may run into a situation where may show no eth0 or eth1. may show their NIC detected as eth0, and later moved to eth1. Performing a will also show the NIC as eth1. This is caused by using the kernel assigned names in the first place. Users should write custom rules like to use free names like lan0 or wireless0 or use predictable interface names (which have been enabled by default since udev version 197).

또한 이전 버전의 udev에 있던 오래된 파일의 제거를 잊지 마십시오.

추가 참조
eudev - 젠투에서 관리하는 udev 포크 버전.