populating /dev from /sys

Under development: PCMCIA, wireless, etc.
Message
Author
Ibidem
Posts: 549
Joined: Wed 26 May 2010, 03:31
Location: State of Jefferson

#21 Post by Ibidem »

There are uevent files that don't contain all variables.
But it seems this is duplicating what mdev does in C already.

http://lists.busybox.net/pipermail/ucli ... hment.diff
The mknod patch for uclibc.

A char device is any device read as a stream (byte at a time); a block device is read block at a time (usu. 512-1024 bytes); usually this means block device == disk, char device == tty or similar.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#22 Post by Karl Godt »

Here you are :

Code: Select all

#!/bin/ash

eval `env`
[ "$ACTION" = remove ] && SUFFIX=rem || SUFFIX=add
echo "---------- $@ --------------
`env`

`dmesg|tail`
">> "$HOME/hotplug.${SUFFIX}.log"
Modded the code a tiny bit. Hope you don't mind.
Kernel is Drake Puppy 0.3
# uname -r
2.6.39
BB is
# busybox |head -n1
BusyBox v1.17.2 (2011-05-01 08:45:38 GMT-8) multi-call binary.
Attachments
hotplug.log.d.tar.bz2
two folders : add and remove. hope i have removed in correct reverse order.
(8.45 KiB) Downloaded 419 times

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#23 Post by Karl Godt »

Karl Godt wrote:
as a start Very Happy
YEP, hundreds of xmessages can be annoying , but to detect single events by mount or kill, it is quite useful .

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#24 Post by Iguleder »

What about devtmpfs? Newer udev versions (AFAIK, 17x and above) require this feature and udev no longer creates device nodes.

The kernel already has that information (major, minor numbers and device names), so why don't you just let it create those device nodes on its own? :idea:

Sounds more efficient and smaller (in terms of binary size) to me. Just mount a devtmpfs file system and you're done - this can be done from the initramfs and it is guaranteed that /dev will be populated correctly.
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#25 Post by Karl Godt »

Must say that I have enabled that in some kernels and all of a sudden the USB Modem disconnected and reconnected with ttyUSB0 becomming ttyUSB1 .

But have encountered that too on standard configurations afterwards .

Devtmpfs kernel feature can be enabled without automatically letting the kernel mounting it .
This lead to empty /dev directory at shutdown.
Normal kernels had no nodes there afterwards .
Tiny point to watch out for in full installations .

Otherwise devtmpfs is OK for me.

udev-140 works for me . Dunno what's that hype all about upgrade .

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#26 Post by Iguleder »

Karl Godt wrote:Devtmpfs kernel feature can be enabled without automatically letting the kernel mounting it .
This lead to empty /dev directory at shutdown.
You described both the problem and the solution here ... just mount that devtmpfs from the init script! :evil:
Karl Godt wrote:Normal kernels had no nodes there afterwards .
Tiny point to watch out for in full installations .
I see no difference between full installations, frugal ones or any other hypothetical installation. The init script stays the same, just mount devtmpfs before doing things specific to the installation type used.
Karl Godt wrote:udev-140 works for me . Dunno what's that hype all about upgrade .
Windows 1.0 works great on my brand new UEFI, 64-bit ARMv8 laptop. I run it inside VirtualBox, on top of Xen, inside QEMU, inside Bochs, in a Fedora chroot. NOT

EDIT: forgot to mention - devtmpfs is pretty standard. If you don't have it in your kernel, that's probably because you insist on using an ancient kernel, so that's your problem already. You're trying to force things to work, because you decided not to have the clean solution isn't available. 21st century versions of X, recent versions of udev and Wayland and more stuff won't work on such a kernel - if you solve this problem, I guess figuring out some dirty hack for creating device nodes won't be an issue for you :lol:
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#27 Post by jamesbond »

Iguleder wrote:What about devtmpfs?
If I read correctly technosaurus wants to do this inside his lxc container (or chroot jail, or whatever), and probably creating the nodes also in a controlled manner (not just for all devices).
If it is for the main system I agree we should all switch to devtmpfs.
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#28 Post by Iguleder »

jamesbond wrote:... (not just for all devices).
Why not?
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#29 Post by Karl Godt »

udev-140 works with kernel 3.5 - NO FEAR !

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#30 Post by Iguleder »

Of course it does - it creates all device nodes on its own (e.g if a device node is not there already, it creates it).

Once you upgrade udev (to something more recent than 2009, to make it possible to use a modern graphics stack), it won't.
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#31 Post by jamesbond »

Iguleder wrote:
jamesbond wrote:... (not just for all devices).
Why not?
Well I don't speak for him, but the dev nodes you create inside lxc container (glorified chroot jail actually) depends on what you want to run inside it (for security reasons) :D
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#32 Post by Iguleder »

I don't see how this improves security. You're still using the same kernel as the host - that's the main weakness of jails, compared to virtualization.

For example, if you want to ruin the first hard drive (in 99% of cases, that's sda1) from inside the chroot environment, just create the device node with mknod (by the way, you don't even need /sys to know the major and minor numbers, since their constant).
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#33 Post by jamesbond »

that's the main weakness of jails, compared to virtualization
Agreed. But security is always trade-off. It depends on your needs. Even full virtualisation (KVM / Xen and the like) can be broken into if one is desperate enough. By the way mknod doesn't work as non-root so once you enter the jail and drop privileges you can't just make new nodes.

Anyway, we are distracting from the original topic. We can carry on the discussion in a new thread if you wish.
If technosaurus wants to continue exploring ways of creating device nodes from /sys then so be it :D
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#34 Post by Karl Godt »

Mine looks now as:

Code: Select all

#!/bin/ash

exec 1>>/tmp/photplug.log 2>&1

eval `env`

[ "$ACTION" = add ] || exit

[ "$MODALIAS" ] && {
        [ -f /tmp/hotplug.modules ] || modprobe -c >/tmp/hotplug.modules
        MODS=`grep "^alias $MODALIAS" /tmp/hotplug.modules |awk '{print $3}' | sort -u`
        #OPTS=`grep "^options $MODALIAS" /tmp/hotplug.modules |cut -f3- -d' '`
        for m in $MODS ;do
        OPTS=`grep -m1 "^options $m" /tmp/hotplug.modules |cut -f3- -d' '`
        modprobe -b -v $m $OPTS
        done
        exit
}

[ "$MAJOR" -a "$MINOR" -a "$DEVNAME" -a "$SUBSYSTEM" ] && {

sed -n '/Block devices:/,$ p' /proc/devices | grep "$SUBSYSTEM" | awk '{print $1}' | grep -w "$MAJOR" && {
        [ -e /dev/$DEVNAME ] && exit
        DEV="/${DEVNAME}"
        mkdir -p "/dev/${DEV%/*}"
        mknod /dev/$DEVNAME b $MAJOR $MINOR
        exit $? ; }

sed -n '/Character devices:/,/Block devices:/p' /proc/devices | grep "$SUBSYSTEM" | awk '{print $1}' | grep -w "$MAJOR" && {
        [ -e /dev/$DEVNAME ] && exit
        DEV="/${DEVNAME}"
        mkdir -p "/dev/${DEV%/*}"
        mknod /dev/$DEVNAME c $MAJOR $MINOR
        exit $? ; }
}
Nice replacement for /sbin/pup_event_backend* files . :D Have to test it though .

Could need help for the much to long lines

Code: Select all

sed -n '/Character devices:/,/Block devices:/p' /proc/devices | grep "$SUBSYSTEM" | awk '{print $1}' | grep -w "$MAJOR"
I guess that can be done by awk alone .. :?:
Last edited by Karl Godt on Fri 17 May 2013, 12:13, edited 1 time in total.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#35 Post by Karl Godt »

Above wasn't loading any modules .

This now worked >

Code: Select all

[ "$MODALIAS" ] && {
        LIST=`modprobe -b -D "$MODALIAS" | sed 's%.*\(/.*\)\.k.*%\1%'`
        for m in $LIST ; do
        modprobe -b -v "${m##*/}"
        done
        
}
Have sound and everything :P

If it is faster and less load , time will tell . Am running a Puppy-4.3 without /etc/modprobe.d .

2.6.30.9-i586-dpup005-Celeron2G and it's name comes from being compiled on a dpup by iguleder :D

Adjustment to rc.sysinit >

Code: Select all

if [ -x /sbin/photplug ] ; then
echo '/sbin/photplug' >/proc/sys/kernel/hotplug
#v405 udevd calls /sbin/pup_event_backend_modprobe, which needs this...#my intention is for puppy to work with either of these...
elif [ -x /sbin/udevd ];then  ##changed -f to -x

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#36 Post by Karl Godt »

Today had no sound.
What was wrong ?
My grep for SUBSYSTEM grep MAJOR does not work when
14 sound
116 alsa
are set in /proc/devices.
SUBSYSTEM passed by the kernel for MAJOR 116 is sound not alsa.
working fix looks as

Code: Select all

[ "$SUBSYSTEM" = sound ] && GPATTERN='alsa|sound' || GPATTERN="$SUBSYSTEM"
sed -n '/Character devices:/,/Block devices:/p' /proc/devices | grep -E "$GPATTERN" | awk '{print $1}' | grep -w "$MAJOR" && {
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#37 Post by Karl Godt »

Old kernels have no DEVNAME ..
modprobe -D is short for --show-depends but there a several BUGs in the common modprobe.c getopt line :

Code: Select all

 while ((opt = getopt_long(argc, argv, "VvqLnsd:C:h:S:o:DRrclt:aiIbf", options, NULL)) != -1){ /* h: has to be rearranged ':' meaning has to follow an argument */
/sbin/modprobe-3.11.1 | -3.12 compiled suppressing warnings is what I am using.
modprobe -D also sometimes shows the install lines .

Working code :

Code: Select all

#!/bin/ash

exec 1>>/tmp/photplug.log 2>&1
alias sed='busybox sed'
alias grep='busybox grep'
#alias awk='busybox awk' ##awk: applet not found

#eval `env`  ##/sbin/photplug: eval: line 1: =/bin/busybox_1.18.3_STATIC_upx9_648KB: not found
env
[ "$ACTION" = add ] || exit
echo $MODALIAS
[ "$MODALIAS" ] && {
        #eval `modprobe -b -D "$MODALIAS"| grep -vE '^install|^blacklist|^options'`
        #exit
        LIST=`modprobe -b -D "$MODALIAS" | grep -vE '^install|^blacklist|^options' | sed 's%.*\(/.*\)\.k.*%\1%'`
        for m in $LIST ; do
        modprobe -b -v "${m##*/}"
        done
        
}

[ "$MAJOR" -a "$MINOR" -a "$SUBSYSTEM" ] && { [ "$DEVNAME" -o "$DEVPATH" ] && {

[ "$DEVNAME" ] || DEVNAME="${SUBSYSTEM}/${DEVPATH##*/}"

sed -n '/Block devices:/,$ p' /proc/devices | grep "$SUBSYSTEM" | awk '{print $1}' | grep -w "$MAJOR" && {
        [ -e /dev/$DEVNAME ] && exit
        DEV="/${DEVNAME}"
        mkdir -p "/dev/${DEV%/*}"
        mknod /dev/$DEVNAME b $MAJOR $MINOR
        exit $? ; }
        
[ "$SUBSYSTEM" = sound ] && GPATTERN='alsa|sound' || GPATTERN="$SUBSYSTEM"
sed -n '/Character devices:/,/Block devices:/p' /proc/devices | grep -E "$GPATTERN" | awk '{print $1}' | grep -w "$MAJOR" && {
        [ -e /dev/$DEVNAME ] && exit
        DEV="/${DEVNAME}"
        mkdir -p "/dev/${DEV%/*}"
        mknod /dev/$DEVNAME c $MAJOR $MINOR
        exit $? ; }
 }
}
Load is double than before :? :
Attachments
xload_after.jpg
desktop start
(7.44 KiB) Downloaded 1107 times

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#38 Post by Karl Godt »

myself wrote:Load is double than before Confused :
Found the problem : rc.network tries to configure something on my new current machine and running it from rxvt the load climbs up from 0 to 2 :evil:

Have disabled rc.network and now it's fine :D .

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

Firmware loading

#39 Post by Karl Godt »

Had first troubles with
02:00.0 Network controller: Ralink corp. RT5390 Wireless 802.11n 1T/1R PCIe
that needs rt2860.bin firmware
( not sure about the current state of my /usr/share/misc/pci.ids file )

Code: Select all

test "$FIRMWARE" && {
echo -n 1 > /sys/$DEVPATH/loading

FIRMWAREBIN=`ls /lib/firmware/$FIRMWARE`
test "$FIRMWAREBIN" || FIRMWAREBIN=`ls /lib/firmware/*/$FIRMWARE`
test "$FIRMWAREBIN" || exit 1
test -f "$FIRMWAREBIN" || exit 1
echo "FIRMWAREBIN='$FIRMWAREBIN'"

cat "$FIRMWAREBIN" > /sys/$DEVPATH/data
if [ $? = 0 ]; then
    #echo -n  1 > /sys/$DEVPATH/loading
    #echo -n -1 > /sys/$DEVPATH/loading
    echo 0 >/sys/$DEVPATH/loading
else
echo "ERROR loading '$FIRMWAREBIN'"
fi
}
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#40 Post by technosaurus »

here are some more functions that may be useful for hotplugging:

Code: Select all

moddir=/lib/modules/`uname -r`

loadmod(){ #$1=topdir $2=module name
	[ -f $1/$2.ko ] && insmod $1/$2.ko && return
	for x in $1/*;do
		[ -d $x ] && loadmod $x $2;
	done
}
#loadmod $moddir $1

loaddeps(){
	[ "$1" ] || return
	while read mod deps; do
		case $mod in
			*/$1.ko:)for x in $deps; do [ "$x" ] && insmod $moddir/$x;done;;
		esac
	done < $moddir/modules.dep
}

loadfirmware(){
	[ "$FIRMWARE" ] || return
	echo 1 > "/sys/$DEVPATH/loading"
	fwdir=/lib/modules
	[ -f "$fwdir/$FIRMWARE" ] && cat "$fwdir/$FIRMWARE" > "/sys/$DEVPATH/data" && \
	echo 0 > "/sys/$DEVPATH/loading" &
	[ ! -f "$fwdir/$FIRMWARE" ] && echo -1 > "/sys/$DEVPATH/loading" && return 1
}

#MODALIAS='pci:v000014E4d00004301sv*sd*bc*sc*i*'
loadmodfromalias(){
	[ ! "$MODALIAS" ] && [ ! "$1" ] && return
	[ ! "$MODALIAS" ] && MODALIAS="$1"
	while read dummy alias module; do
		[ "$MODALIAS" == "$alias" ] && loaddeps $module && loadmod $moddir $module && return
	done < $moddir/modules.alias
	[ "$1" ] 
}
note: my functions use insmod to load modules instead of the simpler modprobe ... insmod can be implemented in <5 lines of c
note2: it does not yet handle missing modules, my recommendation would be that if the module does not exist, to use the package manager to download and install it, but we don't split up our modules like that (yet)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

Post Reply