WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: by-id  (Read 4151 times)

Offline wysiwyg

  • Sr. Member
  • ****
  • Posts: 266
by-id
« on: January 24, 2015, 06:14:47 PM »
Good afternoon everyone!  I was working on an extension for TC that utilizes the /dev/disk/by-id directory, but was troubled to see that TC does not appear to create these files.  I quickly looked at another distro and copied the following two lines into a remastered boot image:

ENV{DEVTYPE}=="disk", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}"
ENV{DEVTYPE}=="partition", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}-part%n"

However, I can't seem to get this directory structure to populate.  Any thoughts on how I can accomplish this?

Thanks,
Dave

Offline CentralWare

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 764
Re: by-id
« Reply #1 on: January 24, 2015, 08:16:35 PM »
simple way to get labels:

Code: [Select]
blkid | grep -v loop

This will give you most anything you need pertaining to each device (label, uuid, format, etc.)
the "grep" portion simply disregards any extensions you might have loaded

Offline wysiwyg

  • Sr. Member
  • ****
  • Posts: 266
Re: by-id
« Reply #2 on: January 24, 2015, 08:49:22 PM »
Thanks for the response centralware.  I use the by-id filenames to display a list to the user so they can identify which disk/partition they want to interact with.  The filenames generated by the udev rule provide an easy way to do this.  I don't think the blkid output is going to work as well.  Any other thoughts?

Thanks,
Dave

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: by-id
« Reply #3 on: January 24, 2015, 09:04:14 PM »
Did you install the udev extensions?

Offline wysiwyg

  • Sr. Member
  • ****
  • Posts: 266
Re: by-id
« Reply #4 on: January 24, 2015, 10:19:12 PM »
Did you install the udev extensions?


Yes, udev is installed.  Everything works as normal, I just can't get the script to populate the /dev/disk/by-id directory.

Dave

Offline CentralWare

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 764
Re: by-id
« Reply #5 on: January 24, 2015, 10:54:05 PM »
Dave@:

I'm not certain as to whether or not this will help; it sounds as though you may have something in play for another distribution, but if it's on the building block, the following will give you all of the details you should need regardless of what brand hdd you have (serial numbers in particular come in a variety of descriptors from SerialNo to Serial Number and so forth, thus should be tended to by this script.)

Code: [Select]
#!/bin/sh
blkid | grep -v /dev/loop >/tmp/.blkid
while read line
do
    dev=`echo "$line" | awk -F: '{print $1}'`; raw=${dev:5}
    lbl=`echo "$line" | awk -F "LABEL=\"" '{print $2}' | awk -F "\"" '{print $1}'`
    uid=`echo "$line" | awk -F "UUID=\"" '{print $2}' | awk -F "\"" '{print $1}'`
    typ=`echo "$line" | awk -F "TYPE=\"" '{print $2}' | awk -F "\"" '{print $1}'`
    ser=`hdparm $dev -i 2>/dev/null | grep Serial | awk -F "Serial" '{print $2}' | awk -F= '{print $2}'`
    ser=${ser// /}; #Remove space(s) if any

    if [ ! "${raw:0:4}" == "zram" ]; then
echo "DEV: $dev"
echo "RAW: $raw"
echo "LBL: $lbl"
echo "TYP: $typ"
echo "UID: $uid"
echo "SER: $ser"
echo
    fi
done < /tmp/.blkid
rm -f /tmp/.blkid

DEV = /dev/sd##
RAW = DEV without /dev/
LBL = Drive (Partition) Label
TYP = Format Type
SER = Serial Number


Note: This does not require any extensions to be loaded.  The only thing I didn't include would be the pci/usb hardware source (ie: pci-xx-xx) which I'm guessing since this is end-user specific, will not be needed.

If you needed to know whether a device is removable, simply read /sys/block/[PARENT]/removable where 0=internal, 1+=removable and PARENT = sda if the DEV was sda1

Hope this helps!

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14815
Re: by-id
« Reply #6 on: January 24, 2015, 11:54:40 PM »
There's a thread on this somewhere - I seem to remember that the full udev rules are required to populate /dev/disk/by-id, whereas the ones in core are edited for size.

Offline wysiwyg

  • Sr. Member
  • ****
  • Posts: 266
Re: by-id
« Reply #7 on: January 26, 2015, 09:43:57 AM »
@centralware thanks for all that info!  I can certainly use it in other parts of projects though!  Unfortunately for this project, the by-id info is more suitable.

@Juanito where would I find the 'full udev' rule for this?

Thanks,
Dave

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14815
Re: by-id
« Reply #8 on: January 26, 2015, 09:46:29 AM »

Offline wysiwyg

  • Sr. Member
  • ****
  • Posts: 266
Re: by-id
« Reply #9 on: January 26, 2015, 10:47:27 AM »
@Juanito thanks for the link!  I added the desired rule to TC and remastered, but now when I boot up I get:

udev[258]: failed to execute '/lib/udev/ata_id' 'ata_id --export /dev/sda': No such file or directory

udev[259]: failed to execute '/lib/udev/ata_id' 'ata_id --export /dev/sr0': No such file or directory

udev[279]: failed to execute '/lib/udev/scsi_id' 'scsi_id --export --whitelisted -d /dev/sda': No such file or directory

udev[311]: failed to execute '/lib/udev/scsi_id' 'scsi_id --export --whitelisted -d /dev/sr0': No such file or directory


I can see the /dev/sda* files and it appears that the /dev/disk/by-* files are being created, but still not populated...

Dave

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14815
Re: by-id
« Reply #10 on: January 26, 2015, 11:08:33 AM »
'looks like you need the udev-extra extension

Offline wysiwyg

  • Sr. Member
  • ****
  • Posts: 266
Re: by-id
« Reply #11 on: January 26, 2015, 11:18:13 AM »
Looks like x86_64 doesn't have that package for either 6.x or 5.x.

Dave

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14815
Re: by-id
« Reply #12 on: January 26, 2015, 11:33:23 AM »
indeed - I'll try to have a look at this in the next couple of days.

Offline wysiwyg

  • Sr. Member
  • ****
  • Posts: 266
Re: by-id
« Reply #13 on: January 26, 2015, 11:38:01 AM »
Thanks Juanito!

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14815
Re: by-id
« Reply #14 on: January 27, 2015, 11:26:18 AM »
udev-extra posted in tc.6.x x86_64 repo