From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Mdev and the translation is 40% complete.
Outdated translations are marked like this.

This article documents how to replace udev in Linux with mdev, thus allowing a separate /usr partition, without an initramfs. The author uses Gentoo Linux with IceWM as the window manager. The instructions here should be, with some small adjustments, applicable to other distributions.

mdev is a udev replacement from Busybox, it populates and updates /dev (official docs). Replacing eudev or udev is non-trivial, and is probably most adapted to embedded systems.

Может ли mdev работать на моей системе?

The mdev application is definitely suitable as long as the system does not use a full-fledged desktop environment. Note that a desktop environment is not required to run AbiWord, Firefox, GIMP, Gnumeric, etc. However, KOffice applications like KMail seem to pull in most of KDE as a dependency. In general, when using KDE or GNOME, mdev is not suitable. Also using LVM might be troublesome.

It will work very well when using the default Gentoo profiles:

  • default/linux/x86/13.0
  • default/linux/amd64/13.0

List the currently used profile by using following command:

user $eselect profile list
Current /etc/portage/make.profile symlink:
Recent versions of evdev (as provided through x11-drivers/xf86-input-evdev) and www-client/chromium require udev. They will not build without it.

There is one more sanity check that Gentoo users can run to check for udev dependency.

Sanity check

Get a general overview which packages might depend on udev. The output could look similar to the one shown below:

user $equery d udev
 * These packages depend on udev:
media-libs/mesa-9.0.1 (gbm ? virtual/udev)
sys-apps/hwids-20130329 (udev ? >=virtual/udev-197-r1)
sys-apps/util-linux-2.22.2 (udev ? virtual/udev)
virtual/dev-manager-0 (virtual/udev)
x11-base/xorg-server-1.13.4 (udev ? >=virtual/udev-150)
x11-drivers/xf86-video-intel-2.20.13 (udev ? virtual/udev)
x11-libs/cairo-1.10.2-r3 (drm ? >=virtual/udev-136)

Добавьте следующую строку в файл /etc/portage/package.mask/mdev (который можно создать, если он не существует):

ФАЙЛ /etc/portage/package.mask/mdevМаскируем udev

Отключите USE-флаг udev глобально в файле /etc/portage/make.conf:

root #euse -D udev

Перекомпилируйте все пакеты с новым -udev USE-флагом:

root #emerge -uDNvp @world

If the only error that comes up is that Portage is not able to re-install udev as required by virtual/dev-manager, proceed to the next stage. Otherwise, sys-fs/udev might be an hard dependency of one or more packages installed on the system.

Software requiring extra steps

ATI/AMD binary blobs

Some ATI/AMD Radeon cards require binary blobs. The Gentoo sys-firmware/radeon-ucode package pulls in all the binary blobs available at to support many different models.

With all the binary blobs in the library directory, the kernel needs udev to figure out which one of the many binary blobs to load. If all but one of the binary blobs are removed, leaving only the correct one in the library directory, the binary blob is loaded automatically.

Замена udev на mdev

This is a critical step which might result in a non-bootable Linux system. Only proceed if the above approach has not revealed any additional udev dependencies.

Настройка devtmpfs в ядре

Настройте ядро для поддержки и автомонтирования файловой системы devtmpfs в каталог /dev:

ЯДРО Включаем devtmpfs
Device Drivers --->
    Generic Driver Options --->
        [*] Maintain a devtmpfs filesystem to mount at /dev
        [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs

Once the changes have been made, rebuild the kernel. Do NOT reboot yet.

Установка busybox

Make sure that the mdev USE flag is set for sys-apps/busybox. The static USE flag is probably also a good idea. In the /etc/portage/package.use or /etc/portage/package.use/mdev file, add the follwoing line:

ФАЙЛ /etc/portage/package.use/mdev
sys-apps/busybox static mdev

Сейчас (пере)установите busybox:

root #emerge --ask --oneshot busybox

Монтирование devpts

The devpts filesystem exhibits non-standard behavior. It does not automount, at bootup, or with mount -a. An explicit mount devpts command is required. The standard solution for udev-based systems is to run rc-update add udev-mount sysinit as root, and have the udev-mount script do the mounting at startup. An mdev-based system will probably not have udev installed. An alternative way to do this at bootup is to include the command mount devpts in a shell script in /etc/local.d/. In this example, the file will be named /etc/local.d/000.start.

Another side-effect of not using udev-mount is that /dev/shm is only writable by root. The command chmod 1777 /dev/shm is required to restore the standard behavior. This command will also be run from the script at startup.

ФАЙЛ /etc/local.d/000.startМонтируем devpts при загрузке и меняем права на /dev/shm
mount devpts
chmod 1777 /dev/shm
Scripts used in /etc/local.d/
  • must be executable
  • must have the extension ".start" in order to run at startup
  • must have the extension ".stop" in order to run at shutdown

Замена сервиса udev

Удалите udev из списка сервисов и замените его на mdev:

root #rc-update del udev sysinit
root #rc-update add mdev sysinit


Reboot to the new kernel. The system should now be running using mdev.


Удалите udev из системы:

root #emerge --unmerge sys-fs/udev

In the /etc/portage/package.mask file (or a file in this directory), add sys-fs/udev and sys-fs/eudev.

This now results in a completely udev-free machine.

Setting up a USB printer running under CUPS

Make 'find' available at early boot-time

root #cd /bin
root #ln -s /bin/busybox find

Перекомпиляция ядра

For libusb (and hence CUPS) to see the USB ports, set CONFIG_USB_DEVICE_CLASS=y and CONFIG_USB_DEVICEFS=y in the kernel configuration. Also enable CONFIG_USB_PRINTER=y, despite the injunction in the cups-1.5.2 ebuild to disable it. When using make menuconfig, these items are found here:

ЯДРО Enabling generation of USB devices at boot time
Device Drivers --->
    [*] Support for Host-side USB
      [*] USB device filesystem [DEPRECATED]
      [*] USB device class-devices [DEPRECATED]
    [*] USB Printer support
Don't worry about the deprecation warnings.

Configure the new kernel into the bootloader and reboot into it

Verify the presence of the new device nodes

A hierarchy of device nodes should be present under /dev/bus/usb/. When switching on the printer, a node for it should occur at /dev/lp0. lsusb should run successfully, and this should display the printer's details.

Конфигурация принтера в CUPS

Configure CUPS in the usual way. CUPS should find the printer, and will give it a URI like parallel:/dev/lp0.

Устранение проблем

Linux modules missing at boot sequence

If Linux modules are required and not loaded on boot after migration, execute one or more of the following solutions:

  • Добавьте модули Linux в файл /etc/conf.d/modules
  • Compile modules into the Linux kernel, without the need of loading them on demand.
  • Write a custom module loader:
ФАЙЛ /sbin/hotplug
test -n "$MODALIAS" && modprobe "$MODALIAS";
exec /sbin/mdev

Install it as the hotplug handler instead of mdev. Note that the earlier this gets executed, the better. Consider naming this script /sbin/hotplug, since that is the default value of /proc/sys/kernel/hotplug (or change the default value in the kernel configuration).


This set of instructions was originally written by Walter Dnes and hosted at his personal website. It was imported to the Gentoo wiki with some editing by Michael Mol per discussion on the gentoo-user mailing list.
  • mdev unlike udev does not support auto-modules loading. Create files ending with .conf in /etc/modules-load.d/ and put all the modules there that should be loaded (nvidia, wl, etc.) one per line. Customize options via files ending with .conf in /etc/modprobe.d (see man 5 modprobe.d for syntax). It might be necessary to move the module configuration to this location.
  • mdev -s does not create /dev/mapper nodes. Either manually create them or use dmsetup mknodes from lvm2. It is a good idea to add it after mdev -s in the init script.
  • Use mouse and keyboard drivers for xorg inputs. Evdev needs udev to be built. Mousedrv (for the mouse driver) may conflict with the synaptic driver when both are loaded.
  • The Kernel configuration option CONFIG_INPUT_EVDEV not only provides the keyboard and mouse as input device events, it will provide lid and button events to acpid as well.

Смотрите также

Внешние ресурсы