From Gentoo Wiki
Jump to: navigation, search
This page contains changes which are not marked for translation.

The aim of this page is to document 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 applicable to other distros, assuming you can make the necessary changes.

Will mdev work on my system?

I run a simple Gentoo install, using IceWM, and no "desktop environment". An xorg.conf is not required on my system. Note that a "desktop environment" is not required to run AbiWord, Firefox, GIMP, Gnumeric, etc. However, "Koffice apps" like KMail seem to pull in most of KDE as a dependency. In general, if you use KDE or GNOME lvm2, you may have problems, and may not be able to get by with mdev. One beta tester reports getting close with lvm2, but it's not there yet.

It will work for you very well if you use the default Gentoo profile

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

You can show the used profile by using following command:

user $eselect profile list
Current /etc/portage/make.profile symlink:
Recent versions of evdev x11-drivers/xf86-input-evdev and Chromium 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. I don't think this can be duplicated in other distros.

Sanity check

Get an 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)

To /etc/portage/package.mask/mdev, add the line

FILE /etc/portage/package.mask/mdevMask away udev

Disable the udev USE flag globally in /etc/portage/make.conf:

root #euse -D udev

Rebuild all packages with the new -udev USE flag

root #emerge -uDNvp @world

If the only errors you get are for not being able to re-install udev as required by virtual/dev-manager, you can proceed to the next stage. Otherwise, sys-fs/udev might be an hard dependency of some package you requested.

Software requiring extra steps

ATI/AMD binary blobs

Some ATI/AMD Radeon cards require binary blobs. The Gentoo sys-firmware/radeon-ucode package pulls down 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, it loads automatically.

Warning / Disclaimer

This solution may result in a not boot-able Linux.

Proceed only if the above stages don't reveal any udev dependencies.

Replacing udev with mdev

Setting up your kernel for devtmpfs

Set up your kernel to support and automount a devtmpfs filesystem at /dev:

Device Drivers --->
    Generic Driver Options --->
        [*] Maintain a devtmpfs filesystem to mount at /dev
        [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs

Once you've made the changes, rebuild the kernel. Do NOT reboot yet.

Emerging busybox

For our circumstance, you will need the mdev USE flag set for sys-apps/busybox. The static USE flag is probably also a good idea. In the /etc/portage/package.use/mdev file, add the line:

FILE /etc/portage/package.use/mdev
sys-apps/busybox static mdev

Now, you may run

root #emerge --ask --oneshot busybox

If you're using a distro other than Gentoo, or building BusyBox manually, do whatever necessary in your situation to enable the mdev option.

Mounting devpts

devpts exhibits non-standard behaviour. 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 behaviour. This command will also be run from a script at startup.

FILE /etc/local.d/000.startMount of devpts at bootup and change /dev/shm permissions
mount devpts
chmod 1777 /dev/shm

Notes regarding scripts used in /etc/local.d/

  • The files must be executable.
  • They must have the extension ".start" on order to run at startup.
  • They must have the extension ".stop" on order to run at stop.

Editing /etc/fstab is a optional step only for Linux 3.5.7. It is not needed for newer kernels.

As of approximately kernel 3.5.7, devpts has to be included in /etc/fstab with the following parameters:
FILE /etc/fstabEntry for devpts
devpts     /dev/pts      devpts      defaults 0 0

Replace the udev service

Remove udev from the services list, replacing it with mdev:

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


Reboot to your new kernel. Your system should now be running using mdev.


Remove udev from your system by running emerge --unmerge sys-fs/udev. In the /etc/portage/package.mask, append the line sys-fs/udev. Create /etc/portage/package.mask if it doesn't already exist.

You should now have 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

Rebuild the kernel

For libusb (and hence CUPS) to see the USB ports, set CONFIG_USB_DEVICE_CLASS=y and CONFIG_USB_DEVICEFS=y in your kernel configuration. You will also need to enable CONFIG_USB_PRINTER, despite the injunction in the cups-1.5.2 ebuild to disable it. If you use make menuconfig, these items are found here:

KERNEL 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 "DEPRECATED"s.)

Configure the new kernel into your bootloader and reboot into it

Verify the presence of the new device nodes

You should see a hierarchy of device nodes under /dev/bus/usb/. If you switch on your printer, you will probably see a node for it at /dev/lp0. You should be able to run lsusb successfully, and this should display your printer's details.

Configure your printer in CUPS

You should now be able to configure CUPS in the usual way. CUPS should find your printer, and will give it a URI something like parallel:/dev/lp0.


Linux modules missing at boot sequence

If Linux modules are required and not loaded on boot after migration, you might might chose or combine following solutions:

  • Add Linux modules to /etc/conf.d/modules
  • Compile modules into Linux kernel, without the need of loading them on demand.
  • Write your own module loader:
FILE /sbin/hotplug
test -n "$MODALIAS" && modprobe "$MODALIAS";
exec /sbin/mdev

Install it as your hotplug handler instead of mdev. Note that the earlier you get this installed, the better. You might consider naming this script /sbin/hotplug, since that is the default value of /proc/sys/kernel/hotplug (or, change the default value in your kernel)


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 thus you will need to use /etc/conf.d/modules and put there all the modules like you used to load (nvidia, wl etc.). Also, /etc/conf.d/modules have own _args variables as it does not support /etc/modprobe.d. You may need to move your configuration there.
  • mdev -s does not create /dev/mapper nodes. You may need to manualy create them or use dmsetup mknodes from lvm2 (good idea is to add it after mdev -s in init script).
  • you should use mouse and kbd drivers for xorg inputs. evdev need udev to be built. Mousedrv (mouse) may conflict with synaptics driver, when both are loaded.
  • Kernel configuration option CONFIG_INPUT_EVDEV not only provides the keyboard and mouse as input device events, it will provide lid and buttons to acpid as well.

See also

External resources