Skip to content

Instantly share code, notes, and snippets.

@jirutka
Last active March 16, 2021 18:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jirutka/9496300 to your computer and use it in GitHub Desktop.
Save jirutka/9496300 to your computer and use it in GitHub Desktop.
Configuration of mdev (minimalistic Device Manager from Busybox) for a server system, where udev is really not necessary.

How to replace udev with mdev on Gentoo

  1. Ensure that you haven’t installed any package that needs udev:

     equery depends udev
    
  2. Disable USE udev in /etc/portage/make.conf.

  3. Enable USE mdev for busybox (and disable pam, it supposedly doesn’t work with static well):

     echo 'sys-apps/busybox static mdev -pam' >> /etc/portage/package.use
    
  4. Reemerge busybox:

     emerge -av busybox
    
  5. Copy configuration /etc/mdev.conf (see mdev.conf).

  6. Add mdev to runlevel sysinit:

     rc-update add mdev sysinit
    
  7. Remove udev* init scripts from runlevels:

     rc-update del udev sysinit
     rc-update del udev-mount sysinit
     rc-update del udev-postmount
    
  8. Finally unmerge udev:

     emerge --unmerge -a sys-fs/udev virtual/udev sys-fs/udev-init-scripts
    
  9. Mask udev:

     echo -e "# we're using mdev from busybox instead\nsys-fs/udev" >> /etc/portage/package.mask/udev
    
  10. Reboot and hope that everything will be okay. :)

Rename network interfaces

If you want to rename network interfaces (e.g. lan1 instead of eth1), then create file /etc/mactab with pair of an interface name and a Ethernet MAC address on each line. For example:

# Allow busybox's "nameif" to rename downed interfaces on the basis of their
# MAC addresses.
wan0  12:34:56:78:9a:bc
lan0  12:34:56:78:9a:de

This file is read by busybox’s nameif during mdev initialization (see line 55 in mdev.conf). Read man nameif for more information.

Note: Desired interface names should be different than eth[0-9] (nameif can’t swap names).

 

Thanks to Stuart for his article https://blog.stuart.shelton.me/archives/891.

#
# mdev.conf for a server system
#
# Provide user, group, and mode information for devices. If a regex matches
# the device name provided by sysfs, use the appropriate user:group and mode
# instead of the default 0:0 660.
#
# Syntax:
# [-]devicename_regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
# [-]$ENVVAR=regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
# [-]@maj,min[-min2] user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
#
# [-]: do not stop on this match, continue reading mdev.conf
# =: move, >: move and create a symlink
# !: do not create device node
# @|$|*: run cmd if $ACTION=remove, @cmd if $ACTION=add, *cmd in all cases
# support module loading on hotplug
$MODALIAS=.* root:root 660 @/sbin/modprobe "$MODALIAS"
# null may already exist; therefore ownership has to be changed with command
null root:root 666 @/bin/chmod 666 $MDEV
zero root:root 666
full root:root 666
random root:root 444
urandom root:root 444
grsec root:root 622
kmem root:kmem 640
kmsg root:root 640
mem root:kmem 640
# console may already exist; therefore ownership has to be changed with command
console root:tty 600 @/bin/chmod 600 $MDEV
ptmx root:tty 666
pty.* root:tty 660
-cpu.* root:root 755 @/bin/mkdir -pm 755 cpu ; /bin/rm $MDEV
cpu([0-9]+) root:root 444 =cpu/%1/cpuid
# terminal devices
tty root:tty 666
tty[0-9]+ root:tty 660
vcsa?[0-9]* root:tty 660
ttyS[0-9]+ root:uucp 660
# block devices
ram([0-9]+) root:disk 660 >rd/%1
loop([0-9]+) root:disk 660 >loop/%1
sd[a-z].* root:disk 660 */lib/mdev/usbdisk_link
vd[a-z][0-9]* root:disk 660
md[0-9]+ root:disk 660 @/bin/mkdir -pm 755 md ; /bin/ln -sf ../$MDEV md/${MDEV/md}
# net devices
-net/.* root:root 600 @/sbin/nameif -s
net/tun[0-9]* root:root 600
net/tap[0-9]* root:root 600
# usb printers
usb/lp[0-9]* root:lp 660
# misc stuff
rtc0 root:root 600 @/bin/ln -sf $MDEV rtc
fuse root:root 666
#kvm root:kvm 660
# input stuff
event[0-9]+ root:root 640 =input/
mice root:root 640 =input/
mouse[0-9] root:root 640 =input/
ts[0-9] root:root 600 =input/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment