Sunday, June 12, 2005
Old article, but I saw it only a few minutes ago... it's worth a look: click here! To have a laugh, obviously! ROTFLMAO!!!
Tuesday, June 07, 2005
Using udev
After solving the problem with usb devices as explained in the previous post, now I'm going to talk about udev. As depicted from kernel.org
Following the guide from Slacky.it I managed to configure my usb devices (two pendrives and a digital camera), and also setting the automount (autounmount) when devices are plugged (unplugged).
Requirements:
Follow the instructions of the guide to prepare the kernel and install udev.
Now the udev configuration: let's go to the udev configuration directory /etc/udev and open udev.conf with a text editor, for example
Set the udev_rules and udev_root variables, changing the corresponding lines, as follows
Now we have to define the rules for our devices. To do it we need to know some additional informations about our devices, something to identify them. Plug then a device, with dmesg find out what's the node it's linked to (let's say it's /dev/sda) and with the utility udevinfo we can find informations about the device. Type
(if your device is linked to node /dev/uba then replace sda with uba).
This is the output of udevinfo when I plug in my pendrive:
I wrote only the part using the ehci_hcd driver, because I know that my pendrive uses that one. Now I have to find ``identifiers'' for my device, in order to write its own rule. I used the SYSFS{device} and SYSFS{vendor} identifiers, I think they are common to the most of the pendrives (but it works and for me it's enough ^_^).
Now we can write the rule for it. Open the /etc/udev/udev.rules file with an editor and type the rule (all in a line)
pendrive is the name assigned to this device, and, when the device is plugged, the node /udev/pendrive will be created.
Now we have to edit our /etc/fstab, adding the line to define the mount point of the device:
That's it! Once the pendrive is plugged it's possible to mount it in the usual way
It would be even nicer if the camera would be automounted when plugged in. Udev allows to do that, too! When a device named ``dev0'' is plugged, udev looks into the directory /etc/dev.d/dev0/ looking for executable *.dev files and executes them. For the pendrive I can write the /etc/dev.d/pendrive/automount.dev file:
Then
and now, when the pendrive is plugged, it's automatically mounted on /mnt/pendrive and, when unplugged, it's automatically unmounted.
It works fine for me, hope the same for you. :)
References:
udev allows Linux users to have a dynamic /dev directory and it provides the ability to have persistent device names
Following the guide from Slacky.it I managed to configure my usb devices (two pendrives and a digital camera), and also setting the automount (autounmount) when devices are plugged (unplugged).
Requirements:
- a Linux distribution (obviously) :)
- kernel 2.6.x
- hotplug
- udev
Follow the instructions of the guide to prepare the kernel and install udev.
Now the udev configuration: let's go to the udev configuration directory /etc/udev and open udev.conf with a text editor, for example
# vi udev.conf
Set the udev_rules and udev_root variables, changing the corresponding lines, as follows
udev_rules="/etc/udev/udev.rules"
udev_root="/udev/"
Now we have to define the rules for our devices. To do it we need to know some additional informations about our devices, something to identify them. Plug then a device, with dmesg find out what's the node it's linked to (let's say it's /dev/sda) and with the utility udevinfo we can find informations about the device. Type
udevinfo -a -p /sys/block/sda
(if your device is linked to node /dev/uba then replace sda with uba).
This is the output of udevinfo when I plug in my pendrive:
udevinfo starts with the device the node belongs to and then walks up the
device chain, to print for every device found, all possibly useful attributes
in the udev key format.
Only attributes within one device section may be used together in one rule,
to match the device for which the node will be created.
...
looking at the device chain at '/sys/devices/pci0000:00/0000:00:10.3':
BUS="pci"
ID="0000:00:10.3"
DRIVER="ehci_hcd"
SYSFS{class}="0x0c0320"
SYSFS{detach_state}="0"
SYSFS{device}="0x3104"
SYSFS{irq}="11"
SYSFS{local_cpus}="1"
SYSFS{subsystem_device}="0x0033"
SYSFS{subsystem_vendor}="0x1025"
SYSFS{vendor}="0x1106"
...
I wrote only the part using the ehci_hcd driver, because I know that my pendrive uses that one. Now I have to find ``identifiers'' for my device, in order to write its own rule. I used the SYSFS{device} and SYSFS{vendor} identifiers, I think they are common to the most of the pendrives (but it works and for me it's enough ^_^).
Now we can write the rule for it. Open the /etc/udev/udev.rules file with an editor and type the rule (all in a line)
BUS="pci", SYSFS{vendor}="0x1106", SYSFS{device}="0x3104", NAME="pendrive"pendrive is the name assigned to this device, and, when the device is plugged, the node /udev/pendrive will be created.
Now we have to edit our /etc/fstab, adding the line to define the mount point of the device:
/udev/pendrive /mnt/pendrive vfat noauto,sync,user,umask=0000 0 0
That's it! Once the pendrive is plugged it's possible to mount it in the usual way
$ mount /mnt/pendrive
It would be even nicer if the camera would be automounted when plugged in. Udev allows to do that, too! When a device named ``dev0'' is plugged, udev looks into the directory /etc/dev.d/dev0/ looking for executable *.dev files and executes them. For the pendrive I can write the /etc/dev.d/pendrive/automount.dev file:
#!/bin/bash
if [ "$ACTION" == "add" ] ; then
logger -t dev.d "Mounting pendrive"
mkdir /mnt/pendrive
/bin/mount /mnt/pendrive
fi
if [ "$ACTION" == "remove" ] ; then
logger -t dev.d "Unmounting pendrive"
/bin/umount /mnt/pendrive
rmdir /mnt/pendrive
fi
Then
# chmod +x /etc/dev.d/pendrive/automount.dev
and now, when the pendrive is plugged, it's automatically mounted on /mnt/pendrive and, when unplugged, it's automatically unmounted.
It works fine for me, hope the same for you. :)
References:
- guide on Slacky.it (italian)
- other guide (english) thanks webkiller71
Monday, June 06, 2005
USB on Kernel 2.6.10
My brand new DERI-Korea pendrive finally works on my slack running kernel 2.6.10. It was so frustrating to have a 512 MB pendrive and not being able to use it, so, after a lot of googling, I found something I can call a ``solution'': boot the 2.6.10 kernel appending ``pci=noacpi'' string or edit lilo.conf adding the line
in the section relative to kernel 2.6.10 and then issue a `lilo -v`.
It worked for me and for my pendrive, now I can't try with my other usb devices (an mp3-player pendrive and a camera), I hope it won't give more troubles.
append="pci=noacpi"
in the section relative to kernel 2.6.10 and then issue a `lilo -v`.
It worked for me and for my pendrive, now I can't try with my other usb devices (an mp3-player pendrive and a camera), I hope it won't give more troubles.
