Mdev: Difference between revisions

From Alpine Linux
(mark as draft)
(moved content from Editing Custom network interface names page)
 
(25 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Draft|This is almost complete but needs testing that it works when followed as a step by step guide.}}
{{DISPLAYTITLE:mdev}}
 
mdev is the default [[Device_Manager|device manager]] on Alpine Linux. It is provided by busybox as alternative to [https://man.archlinux.org/man/udev.7 systemd's udev].
== mdev ==
mdev is '''not''' a drop in replacement for udev. See [[eudev]] for that instead. mdev lacks some features which makes it not recommended for a full blown desktop enviroment.
 
Mdev is the default device manager on Alpine Linux. It is provided by busybox as alternative to [https://man.archlinux.org/man/udev.7 systemd's udev].
Mdev is '''not''' a drop in replacement for udev. See [[eudev]] for that instead. Mdev lacks some features which makes it not recommended for a full blown desktop enviroment.


== Installation ==
== Installation ==


The easy way to setup mdev is throught the [[#Setup_Script|setup script]]. For custom installation see the [[#Manually|manually section]]. Note that this is only recommended for advanced users.
The easy way to setup mdev is throught the [[#Setup_Script|setup script]]. For custom installation see the [[#Manually|manually section]]. Note that a manual installation is only recommended for advanced users.


=== Setup Script ===
=== Setup Script ===
Line 14: Line 11:
The {{pkg|alpine-conf}} package privides [https://git.alpinelinux.org/alpine-conf/tree/setup-devd.in setup-devd] to easily install and setup device managers.
The {{pkg|alpine-conf}} package privides [https://git.alpinelinux.org/alpine-conf/tree/setup-devd.in setup-devd] to easily install and setup device managers.


Install {{pkg|alpine-conf}} if not already.
Install {{pkg|alpine-conf}} if it is not already installed.
{{cmd|# apk add {{pkg|alpine-conf}}}}
{{cmd|# apk add {{pkg|alpine-conf}}}}
Setup mdev.
Setup mdev.
Line 22: Line 19:


Mdev is provided by the {{pkg|busybox}} package which is pre installed on any alpine installation. To run mdev the [[OpenRC]] init scripts are required too. If it isn't already installed install it:
Mdev is provided by the {{pkg|busybox}} package which is pre installed on any alpine installation. To run mdev the [[OpenRC]] init scripts are required too. If it isn't already installed install it:
{{cmd|# apk install {{pkg|busybox-mdev-openrc}}}}
{{cmd|# apk add {{pkg|busybox-mdev-openrc}}}}
 
 
Before starting mdev you need to [[eudev#Disable|disable eudev]].
{{Note|I have no idea what happens if you don't}}


{{Note|If you already have a device manager installed you need to stop it before you start mdev.}}


Enable the mdev service.
Enable the mdev service.
{{cmd|# rc-update add mdev sysinit}}
{{cmd|# rc-update add mdev sysinit}}
{{cmd|# rc-update add hwdrivers sysinit}} {{todo|verify need of the hwdrivers service}}
{{cmd|# rc-update add hwdrivers sysinit}}
If you are not running in a chroot you will also want to start mdev.
If you are not running in a chroot you will also want to start mdev.
{{cmd|# rc-service mdev start}}
{{cmd|# rc-service mdev start}}
{{cmd|# rc-service hwdrivers start}}
{{cmd|# rc-service hwdrivers start}}


== Disable ==
You might also want to take a look at [[#libudev replacement|libudev replacement]] if programms you want to use depend on udev.
 
== Remove ==


{{warning|Disabling mdev without setting up a different device manager can result in an unusable system.}}
{{warning|Use [[#Setup script|Setup script]] to change device manager. Manual removal of a device manager without first setting up an alternative may cause unexpected issues.}}


To disable mdev when using a different device manager like [[eudev]] you need to stop and remove the service.
First stop the service. This step can be skipped when you are running in a chroot.
{{cmd|# rc-service mdev stop}}
{{cmd|# rc-service mdev stop}}
Then disable it.
{{cmd|# rc-update delete mdev sysinit}}
{{cmd|# rc-update delete mdev sysinit}}


You might also want to uninstall the init scripts since they are not used anymore.
You might also want to uninstall the init scripts since they are not used anymore.
{{cmd|# apk del {{pkg|busybox-mdev-openrc}}}}
{{cmd|# apk del {{pkg|busybox-mdev-openrc}}}}
The mdev binary is part of the {{pkg|busybox}} package and therefor can't be uninstalled.
== libudev replacement ==
{{pkg|libudev-zero}} provides udev apis but is independent from the device manager used. When installed it will make '''some''' udev reliant programms work with mdev. See <code>[https://github.com/illiliti/libudev-zero/#what-doesnt-work What doesn't work]</code>.
== Configuration ==
''mdev'' reads {{path|/etc/mdev.conf}} and according to [https://git.busybox.net/busybox/plain/docs/mdev.txt mdev documentation] one can define a command to be executed per device definition.
=== Custom network interface name ===
The command {{ic|nameif}} is used to change network interface name to set custom network interface name.
The file {{path|/etc/mdev.conf}} needs to be edited as follows:{{cat|/etc/mdev.conf|<nowiki>-SUBSYSTEM=net;DEVPATH=.*/net/.*;.*    root:root 600 @/sbin/nameif -s</nowiki>}}
The above command tell ''mdev'' to call ''nameif'' for devices found in {{path|/sys/class/net/}}.
{{cmd|# ls -d -C -1 /sys/class/net/eth*
/sys/class/net/eth1
/sys/class/net/eth2
/sys/class/net/eth3
/sys/class/net/eth4
/sys/class/net/eth5
}}
To view hwaddr or mac address with interface name {{ic|eth0}}, use the command {{Cmd|# cat /sys/class/net/eth0/address}}


== Custom network interfaces ==
The command {{ic|nameif}} reads {{path|/etc/mactab}} by default. To set custom network interface name as {{ic|dmz0}} for  hwaddr {{ic|90:e2:ba:04:28:c0}}, add an entry in the file {{path|/etc/mactab}} as follows: {{Cat|/etc/mactab|
See [[Custom network interface names]]
dmz0 90:e2:ba:04:28:c0}}


== USB Printer ==
Since {{path|/etc/mdev.conf}} is part of ramdisk, ramdisk rebuild is required. Issue the following command to configure: {{cmd|# grep /etc/mdev.conf /etc/mkinitfs/features.d/*.files
See [[Printer_Setup#mdev_hacks_for_USB_printers|mdev hacks for USB printers]]
/etc/mkinitfs/features.d/base.files:/etc/mdev.conf
}}


== Raspberry Pi Bluetooth Speaker ==
To rebuild ramdisk:{{cmd|<nowiki># mkinitfs $(ls /lib/modules/)
==> initramfs: creating /boot/initramfs-lts
</nowiki>}}
 
To use renamed network interface without reboot, just call {{ic|nameif}} while the network interface is down:{{cmd|# nameif -s}}
 
=== USB Printer ===
See [[Printer_Setup#configure_mdev_for_USB_printers|configure mdev for USB printers]]
 
=== Raspberry Pi Bluetooth Speaker ===
See [[Raspberry_Pi_Bluetooth_Speaker#Bluetooth|Raspberry Pi Bluetooth Speaker]]
See [[Raspberry_Pi_Bluetooth_Speaker#Bluetooth|Raspberry Pi Bluetooth Speaker]]


== See Also ==
== See Also ==
* [[eudev]]
* [[:Category:Device_Manager|Device Managers]]
* [https://wiki.gentoo.org/wiki/Mdev Gentoo wiki Mdev]
* [https://wiki.gentoo.org/wiki/Mdev Gentoo wiki Mdev]
* [https://git.busybox.net/busybox/plain/docs/mdev.txt mdev doc]
* [https://git.busybox.net/busybox/plain/docs/mdev.txt mdev doc]
* [https://github.com/slashbeast/mdev-like-a-boss mdev like a boss]
[[Category:Device_Manager]]

Latest revision as of 04:40, 16 September 2025

mdev is the default device manager on Alpine Linux. It is provided by busybox as alternative to systemd's udev. mdev is not a drop in replacement for udev. See eudev for that instead. mdev lacks some features which makes it not recommended for a full blown desktop enviroment.

Installation

The easy way to setup mdev is throught the setup script. For custom installation see the manually section. Note that a manual installation is only recommended for advanced users.

Setup Script

The alpine-conf package privides setup-devd to easily install and setup device managers.

Install alpine-conf if it is not already installed.

# apk add alpine-conf

Setup mdev.

# setup-devd mdev

Manually

Mdev is provided by the busybox package which is pre installed on any alpine installation. To run mdev the OpenRC init scripts are required too. If it isn't already installed install it:

# apk add busybox-mdev-openrc

Note: If you already have a device manager installed you need to stop it before you start mdev.

Enable the mdev service.

# rc-update add mdev sysinit

# rc-update add hwdrivers sysinit

If you are not running in a chroot you will also want to start mdev.

# rc-service mdev start

# rc-service hwdrivers start

You might also want to take a look at libudev replacement if programms you want to use depend on udev.

Remove

Warning: Use Setup script to change device manager. Manual removal of a device manager without first setting up an alternative may cause unexpected issues.


First stop the service. This step can be skipped when you are running in a chroot.

# rc-service mdev stop

Then disable it.

# rc-update delete mdev sysinit

You might also want to uninstall the init scripts since they are not used anymore.

# apk del busybox-mdev-openrc

The mdev binary is part of the busybox package and therefor can't be uninstalled.

libudev replacement

libudev-zero provides udev apis but is independent from the device manager used. When installed it will make some udev reliant programms work with mdev. See What doesn't work.

Configuration

mdev reads /etc/mdev.conf and according to mdev documentation one can define a command to be executed per device definition.

Custom network interface name

The command nameif is used to change network interface name to set custom network interface name.

The file /etc/mdev.conf needs to be edited as follows:

Contents of /etc/mdev.conf

-SUBSYSTEM=net;DEVPATH=.*/net/.*;.* root:root 600 @/sbin/nameif -s

The above command tell mdev to call nameif for devices found in /sys/class/net/.

# ls -d -C -1 /sys/class/net/eth* /sys/class/net/eth1 /sys/class/net/eth2 /sys/class/net/eth3 /sys/class/net/eth4 /sys/class/net/eth5

To view hwaddr or mac address with interface name eth0, use the command

# cat /sys/class/net/eth0/address

The command nameif reads /etc/mactab by default. To set custom network interface name as dmz0 for hwaddr 90:e2:ba:04:28:c0, add an entry in the file /etc/mactab as follows:

Contents of /etc/mactab

dmz0 90:e2:ba:04:28:c0

Since /etc/mdev.conf is part of ramdisk, ramdisk rebuild is required. Issue the following command to configure:

# grep /etc/mdev.conf /etc/mkinitfs/features.d/*.files /etc/mkinitfs/features.d/base.files:/etc/mdev.conf

To rebuild ramdisk:

# mkinitfs $(ls /lib/modules/) ==> initramfs: creating /boot/initramfs-lts

To use renamed network interface without reboot, just call nameif while the network interface is down:

# nameif -s

USB Printer

See configure mdev for USB printers

Raspberry Pi Bluetooth Speaker

See Raspberry Pi Bluetooth Speaker

See Also