probedisk_init

Under development: PCMCIA, wireless, etc.
Post Reply
Message
Author
User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

probedisk_init

#1 Post by Karl Godt »

Puppy has gor a probepart_init for the initrd.gz bu no probedisk_init .

While I am at writing a search logic for the init , I came to the conclusion, that the PMEDIA filter is really weird, and could need a better understandable one .

Any mistakes I have made ?

Code: Select all

#!/bin/sh
# Karl Reimer Godt April 2013

ERR=/dev/null ##change if required

ALLDRIVES=`ls -1 /sys/block | grep -vE 'ram|loop|mtd|md'`
for drive in $ALLDRIVES ; do
[ -f /sys/block/$drive/removable ] && read REMOVABLE </sys/block/$drive/removable
case $drive in
sd*)
[ "$REMOVABLE" = 0 ] && KIND=IntSata || KIND=ExtSata ;;
sr*)
[ "$REMOVABLE" = 1 ] && KIND=CdDvd || KIND=unknown   ;;
fd*)
[ "$REMOVABLE" = 1 ] && KIND=Floppy || KIND=unknown  ;;
hd*)
[ "$REMOVABLE" = 0 ] && KIND=IntIde || KIND=IdeCd    ;;
scd*)
[ "$REMOVABLE" = 1 ] && KIND=ScsiCd || KIND=unknown   ;;
mmc*)
[ "$REMOVABLE" = 1 ] && KIND=Card || KIND=unknown   ;;
esac
[ -f /sys/block/$drive/device/vendor ] && read VEND </sys/block/$drive/device/vendor
[ -f /sys/block/$drive/device/model ] && read MODL </sys/block/$drive/device/model
[ "$VEND" ] || VEND=Unknown
[ "$MODL" ] || MODL=Unknown
PARTS=`ls -1 /sys/block/$drive/$drive[0-9]* 2>$ERR | grep -o -e '[0-9]*' |tr '\n' ' '`
echo "$drive|$KIND|$VEND $MODL|$PARTS"
done
Output should be like this :
sda|IntSata|ATA ST500DM002-1BD14|1 2 3 4 5 6 7 8 9
sdb|IntSata|ATA ST3250310AS|1 10 11 2 3 4 5 6 7 8 9
sdc|ExtSata|Mass Storage Device|1 2 3 5 6
sr0|CdDvd|PLDS DVD-ROM DH-16D3S|
sr1|CdDvd|HL-DT-ST DVD-RAM GH10L|
sr2|CdDvd|TSSTcorp CDDVDW SE-208AB|
Version 2 :

Code: Select all

#!/bin/ash
# Karl Reimer Godt May, 2013
# Thanks to jamesbond, R-S-H, Ted Dog, vovchick.
# Different probedisk attempt to be used in
# the init script of the Puppy Linux initrd.gz

for p in $*
do
P=${p//-/}
case $P in
everything) EVERYTHING=YES;;
esac
done

if_then(){
if [ "$PMEDIA" = usb ] ; then
[ "$REMOVABLE" = 1 ] && PMEDIA=$1 || PMEDIA=$2
else
[ "$REMOVABLE" = 1 ] && PMEDIA=$3 || PMEDIA=$4
fi;		 }

ERR=/dev/null ##change if required ie ERR=/dev/stderr
QUIET='-q'    ##change if required ie QUIET=''

alias ls='busybox ls'
alias sed='busybox sed'
alias grep='busybox grep'
alias readlink='busybox readlink'

for block_device in `ls -1d /sys/block/*` ; do
[ "$EVERYTHING" ] || { echo "$block_device" | grep $QUIET -E 'md|mtd|ram|loop|nbd' && continue; }
#RESET EVERYTHING
REMOVABLE='';VEND='';MODL='';MAMI='';PMEDIA='';SIZE=''

[ -f $block_device/removable ] && read REMOVABLE <$block_device/removable
READLINK=`readlink -f "$block_device"`
TNR=`echo "$READLINK" | grep -o -m1 -e '/target[0-9]*:' | tr -d '[[:alpha:][:punct:]]'`
echo "$READLINK" | grep $QUIET 'usb' && { REMOVABLE=1; PMEDIA=usb; }

case ${block_device##*/} in
sd*)   if_then usbflash usbhd ataflash atahd ;;
sr*)   if_then usbcd unknowncd atacd unknowncd ;;
fd*)   if_then usbfd unknownfd genericfd unknownfd ;;
hd*)   if_then usbidecd usbidehd idecd idehd ;;
scd*)  if_then usbscsicd unknownscsi scsicd unknownscsi ;;
mmc*)  if_then usbflashcard unknownusbflash cardflash cardflash ;;
loop*) if_then usbloopd usbloopd loopd loopd ;;
ram*)  if_then usbramd usbramd ramd ramd ;;
md*)   if_then usbraidhd usbraidhd raidhd raidhd ;;
mtd*)  if_then usbrawflash usbrawflash rawflash rawflash ;;
nbd*)  if_then usbnethd unknownusbnetd nethd unknownnet ;;
*)     if_then removableusb fixedusb removable fixed ;;
esac
[ -f $block_device/device/vendor ] && read VEND <$block_device/device/vendor
[ -f $block_device/device/model ] && read MODL <$block_device/device/model
[ -f $block_device/size ] && read SIZE <$block_device/size
SIZE=$(( (SIZE*8*512) / (8*1000*1000) ))  ##change to 1024 if you want
[ "$VEND" ] || VEND=Unknown
[ "$MODL" ] || MODL=Unknown
if [ "$EVERYTHING" ] ; then
[ -f $block_device/dev ] && read MAMI <$block_device/dev
PARTS=`ls -1 $block_device/${block_device##*/}[0-9]* 2>$ERR | grep -o -e '[0-9]*' |tr '\n' ' '`
 if [ "`echo "${block_device}" | grep -E '/sd|/sr'`" ] ; then
 echo
 echo "$block_device|$SIZE MB|$PMEDIA|$MAMI|$VEND $MODL|$PARTS"
 grep -A2 -w "scsi$TNR" /proc/scsi/scsi 2>$ERR
 sed -n "/.*scsi$TNR/,/QUIRKS/p" /proc/scsi/usb-storage/$TNR 2>$ERR
  if [ "`echo "${block_device}" | grep '/sr'`" ] ; then
  INFO=`sed 's% %_%g' /proc/sys/dev/cdrom/info`
  LINE=`echo "$INFO" | grep -m1 -w "${block_device##*/}"`
  c=0;for item in $LINE ; do c=$((c+1)) ; [ "$item" = "${block_device##*/}" ] && break ; done
  echo "$INFO" | tr '\t' ' ' | tr -s ' ' | cut -f1,$c -d ' '
  fi
 else
 echo "$block_device|$SIZE MB|$PMEDIA|$MAMI|$VEND $MODL|$PARTS"
 fi
else
echo "${block_device##*/}|$SIZE|$PMEDIA|$VEND $MODL"
fi

done
Last edited by Karl Godt on Wed 08 May 2013, 22:03, edited 1 time in total.

R-S-H
Posts: 487
Joined: Mon 18 Feb 2013, 12:47

#2 Post by R-S-H »

Output in LazY MacPup 1.2.5:

Code: Select all

sda|IntSata|ATA WDC WD1600AVJB-6|1 2 
sdb|IntSata|ATA WDC WD1600AAJB-2|1 2 3 
sdc|IntSata|ATA Maxtor 6E040L0|1 2 3 4 
sdd|IntSata|ST500LM0 11 HM501II|1 2 3 
sde|ExtSata|HUAWEI SD Storage|
sr0|CdDvd|HL-DT-ST DVDRAM GH24NS90|
sr1|CdDvd|HUAWEI Mass Storage|
[b][url=http://lazy-puppy.weebly.com]LazY Puppy Home
The new LazY Puppy Information Centre[/url][/b]

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#3 Post by vovchik »

Dear Karl,

Here is what I get in Lucid:

Code: Select all

fd0|Floppy|Unknown Unknown|
sda|IntSata|ATA Maxtor 6B250R0|1 10 2 3 5 6 7 8 9 
sdb|ExtSata|Generic USB SD Reader|
sdc|ExtSata|Generic USB CF Reader|
sdd|ExtSata|Generic USB SM Reader|
sde|ExtSata|Generic USB MS Reader|
sdf|ExtSata|Unknown USB DISK 2.0|
sdg|ExtSata|JetFlash Transcend 4GB|
sdh|IntSata|Hitachi HDT721010SLA360|1 2 5 6 7 8 
sr0|CdDvd|Optiarc DVD RW AD-7241S|
sr1|CdDvd|HL-DT-ST RW/DVD GCC-4482B|
All OK, except that the IntSata|Hitachi is actually an ExtSata :(

With kind regards,
vovchik

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

#4 Post by Karl Godt »

Thanks to both testers !

vovchick,
hmm have two external usb harddrives, will dig out the PC from underneath the table and attach them to check .

A first potential source of error is that the REMOVABLE variable does not get reset each time ,
so if the file /sys/block/$drive/removable does not exist , the REMOVABLE value of the last device would be used .
The former sdg in your case would have passed REMOVABLE=1 to sdh which it did not as it seems .

Expect some answers in a few hours, since I will to have check for different kernels , too .

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

#5 Post by Karl Godt »

Yep, seems that the kernel assumes these usb-hdd as normal hdd - which they are in an enclosure and connected by usb .

One solution I could think of would be

Code: Select all

QUIET='-q'
readlink -e $drive | grep $QUIET 'usb' && KIND=ExtSata || KIND=IntSata
Other but kernel will drop support for /proc/bus/usb as far as I know :

Code: Select all

grep "$VEND" /proc/bus/usb/devices | grep "$MODL"
which would roughly work for
sdd|IntSata|HitachiG ST|1 10 2 3 5 6 7 8 9
as
P: Vendor=4971 ProdID=1014 Rev= 0.00
S: Manufacturer=HitachiGST
S: Product=Touro Mobile 3.0

but not for
sde|IntSata|ST1000LM 024 HN-M101MBB|1 10 11 12 13 14 15 16 17 18 19 2 20 21 22 23 3 4 5 6 7 8 9
- shows as
P: Vendor=174c ProdID=55aa Rev= 1.00
S: Manufacturer=MEDION
S: Product=MEDION HDDrive-n-GO

[ tested kernel 3.4.9 with these usb hdd attached before powering on the pc ]

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

#6 Post by Karl Godt »

Booted kernel 2.6.30 and also here : For everything related to usb-hdd I could not find a file that would indicate a removable feature to them , neither in /proc/scsi/[scsi|sg/*|usb-storage/*] or anywhere in /sys .

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#7 Post by vovchik »

Dear Karl,

I think we might just have to live with this little oddity :) Thanks for investigating.

With kind regards,
vovchik

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

#8 Post by jamesbond »

Don't give up too early.

You can observe where the /sys/block/sda symlink is pointing to.
If the path contains "usb" in it then it is likely to be on the USB bus - which means it is an external drive.

"readlink /sys/block/sda" will tell you what you need to know (replace "sda" with the drive you want to check).
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
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

#9 Post by Ted Dog »

Code: Select all

nbd0||Unknown Unknown|
nbd1||Unknown Unknown|
nbd10||Unknown Unknown|
nbd11||Unknown Unknown|
nbd12||Unknown Unknown|
nbd13||Unknown Unknown|
nbd14||Unknown Unknown|
nbd15||Unknown Unknown|
nbd2||Unknown Unknown|
nbd3||Unknown Unknown|
nbd4||Unknown Unknown|
nbd5||Unknown Unknown|
nbd6||Unknown Unknown|
nbd7||Unknown Unknown|
nbd8||Unknown Unknown|
nbd9||Unknown Unknown|
sda|IntSata|ATA ST2000DL003-9VT1|1 2 
sdb|IntSata|ATA WDC WD7500BPVT-2|1 2 
sdc|IntSata|ATA ST3250312AS|
sdd|IntSata|ATA ST95005620AS|1 2 3 4 5 
sr0|CdDvd|HL-DT-ST BD-RE  WH12LS39|
sr1|CdDvd|Optiarc DVD RW AD-7270H|
sr2|CdDvd|HP DVD Writer 555r|
moved USB drive to main computer not seen on USB hub
nbd0||Unknown Unknown|
nbd1||Unknown Unknown|
nbd10||Unknown Unknown|
nbd11||Unknown Unknown|
nbd12||Unknown Unknown|
nbd13||Unknown Unknown|
nbd14||Unknown Unknown|
nbd15||Unknown Unknown|
nbd2||Unknown Unknown|
nbd3||Unknown Unknown|
nbd4||Unknown Unknown|
nbd5||Unknown Unknown|
nbd6||Unknown Unknown|
nbd7||Unknown Unknown|
nbd8||Unknown Unknown|
nbd9||Unknown Unknown|
sda|IntSata|ATA ST2000DL003-9VT1|1 2 
sdb|IntSata|ATA WDC WD7500BPVT-2|1 2 
sdc|IntSata|ATA ST3250312AS|
sdd|IntSata|ATA ST95005620AS|1 2 3 4 5 
sde|IntSata|Seagate FreeAgent GoFlex|
sr0|CdDvd|HL-DT-ST BD-RE  WH12LS39|
sr1|CdDvd|Optiarc DVD RW AD-7270H|
sr2|CdDvd|HP DVD Writer 555r|
sde and sr2 are USB

from fatdog64v620

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

#10 Post by Karl Godt »

Thanks .. Probably need to purchase a router . Gooling for "nbd0" gave me first hit :
Network block device
:)
No experience with these .. but have enabled nbd.ko as I run modprobe -l | grep nbd .
I remember compiling Grub_1 / Trusted_Grub http://sourceforge.net/projects/trusted ... rce=navbar chocked on two drivers for the pxegrub but I have /usr/local/lib/grub/i386-pc/nbgrub ( trusted-grub ) ?

User avatar
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

#11 Post by Ted Dog »

It's a server machine, and has different setup over a desktop machine, I got it at deep discount. It came with windows server setup disks but could not be setup using those. Setup disks lack the lan card drivers for the newer hardware and windows requires a call home to finish installing. But puppylinux never had a problem with it. The lack of a sound card was unexpected.

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

#12 Post by Karl Godt »

So I have written something "InsaneInTheBrain " :

Code: Select all

#!/bin/ash
# Karl Reimer Godt May, 2013
# Thanks to jamesbond, R-S-H, Ted Dog, vovchick.
# Different probedisk attempt to be used in
# the init script of the Puppy Linux initrd.gz
# Since the actually used PMEDIA values are
# cd, usb and [hd|flash|zip] , it is uncertain about how to
# use them except for the cd parameter .
# There could be a dozen USB non-cd drives attached and four internal
# ones ... and vice-versa (|:---D )..

for p in $*
do
P=${p//-/}
case $P in
everything) EVERYTHING=YES;;
esac
done

ERR=/dev/null ##change if required ie ERR=/dev/stderr
QUIET='-q'    ##change if required ie QUIET=''

for block_device in `ls -1d /sys/block/*` ; do
[ "$EVERYTHING" ] || { echo "$block_device" | grep $QUIET -E 'md|mtd|ram|loop|nbd' && continue; }
#RESET EVERYTHING
REMOVABLE='';VEND='';MODL='';MAMI='';PMEDIA='';SIZE=''

[ -f $block_device/removable ] && read REMOVABLE <$block_device/removable
READLINK=`readlink -f "$block_device"`
TNR=`echo "$READLINK" | grep -o -m1 -e '/target[0-9]*:' | tr -d '[[:alpha:][:punct:]]'`
echo "$READLINK" | grep $QUIET 'usb' && { REMOVABLE=1; PMEDIA=usb; }

case ${block_device##*/} in
sd*)
[ "$REMOVABLE" = 0 ] && KIND='IntSata atahd' || KIND='ExtSata usbflash'
[ "$REMOVABLE" = 0 ] && PMEDIA=hd || PMEDIA=usb
;;
sr*)
[ "$REMOVABLE" = 1 ] && KIND='CdDvd atacd' || KIND='Unknown cd'
PMEDIA=cd
;;
fd*)
[ "$REMOVABLE" = 1 ] && KIND=Floppy || KIND='Unknown floppy'
PMEDIA=zip
;;
hd*)
[ "$REMOVABLE" = 0 ] && KIND='IntIde idehd' || KIND='IdeCd idecd'
PMEDIA=hd
;;
scd*)
[ "$REMOVABLE" = 1 ] && KIND='ScsiCd scsicd' || KIND='Unknown scsi'
PMEDIA=cd
;;
mmc*)
[ "$REMOVABLE" = 1 ] && KIND='Card usbflash' || KIND='Unknown ataflash'
[ "$REMOVABLE" = 1 ] && PMEDIA=usb|| PMEDIA=hd
;;
loop*)
[ "$REMOVABLE" = 1 ] && KIND=ExtLoop || KIND=IntLoop
PMEDIA='NotYetImplemented'
;;
ram*)
[ "$REMOVABLE" = 1 ] && KIND=ExtRam || KIND=IntRam
PMEDIA='NotYetImplemented'
;;
md*)
[ "$REMOVABLE" = 1 ] && KIND=ExtRaid || KIND=IntRaid
PMEDIA='NotYetImplemented'
;;
mtd*)
[ "$REMOVABLE" = 1 ] && KIND=ExtRawFlash || KIND=IntRawFlash
[ "$PMEDIA" ] || PMEDIA=hd
;;
nbd*)
[ "$REMOVABLE" = 1 ] && KIND=ExtNet || KIND=IntNet
PMEDIA='NotYetImplemented'
;;
*)
[ "$REMOVABLE" = 1 ] && KIND=ExtDevice || KIND=IntDevice
PMEDIA='NotYetImplemented'
;;
esac
[ -f $block_device/device/vendor ] && read VEND <$block_device/device/vendor
[ -f $block_device/device/model ] && read MODL <$block_device/device/model
[ -f $block_device/dev ] && read MAMI <$block_device/dev
[ -f $block_device/size ] && read SIZE <$block_device/size
SIZE=$(( (SIZE*8*512) / (8*1000*1000) ))
[ "$VEND" ] || VEND=Unknown
[ "$MODL" ] || MODL=Unknown
if [ "$EVERYTHING" ] ; then
PARTS=`ls -1 $block_device/${block_device##*/}[0-9]* 2>$ERR | grep -o -e '[0-9]*' |tr '\n' ' '`
 if [ "`echo "${block_device}" | grep -E '/sd|/sr'`" ] ; then
 echo
 echo "$block_device|$SIZE MB|$PMEDIA|$MAMI|$KIND|$VEND $MODL|$PARTS"
 grep -A2 -w "scsi$TNR" /proc/scsi/scsi 2>$ERR
 sed -n "/.*scsi$TNR/,/QUIRKS/p" /proc/scsi/usb-storage/$TNR 2>$ERR
 if [ "`echo "${block_device}" | grep '/sr'`" ] ; then
 INFO=`sed 's% %_%g' /proc/sys/dev/cdrom/info`
 LINE=`echo "$INFO" | grep -m1 -w "${block_device##*/}"`
 c=0;for item in $LINE ; do c=$((c+1)) ; [ "$item" = "${block_device##*/}" ] && break ; done
 echo "$INFO" | tr '\t' ' ' | tr -s ' ' |cut -f1,$c -d ' '
 fi
 else
 echo "$block_device|$SIZE MB|$PMEDIA|$MAMI|$KIND|$VEND $MODL|$PARTS"
 fi
else
echo "${block_device##*/}|$SIZE|$PMEDIA|$VEND $MODL"
fi

done
Output should look like
# time probedisk_init2
sda|500107|hd|ATA ST500DM002-1BD14
sdb|250000|hd|ATA ST3250310AS
sdc|1000204|usb|ST1000LM 024 HN-M101MBB
sdd|4097|usb|Intenso Rainbow Line
sr0|1073|cd|PLDS DVD-ROM DH-16D3S
sr1|1073|cd|HL-DT-ST DVD-RAM GH10L
sr2|1073|cd|TSSTcorp CDDVDW SE-208AB

real 0m0.309s
user 0m0.192s
sys 0m0.048s
and with the "everything" option
[ .. SNIP .. ]
/sys/block/ram9|14 MB|NotYetImplemented|1:9|IntRam|Unknown Unknown|

/sys/block/sda|500107 MB|hd|8:0|IntSata atahd|ATA ST500DM002-1BD14|1 2 3 4 5 6 7 8 9
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: ATA Model: ST500DM002-1BD14 Rev: KC45
Type: Direct-Access ANSI SCSI revision: 05

[ .. SNIP .. ]
/sys/block/sr2|1073 MB|cd|11:2|CdDvd atacd|TSSTcorp CDDVDW SE-208AB|
Host: scsi8 Channel: 00 Id: 00 Lun: 00
Vendor: TSSTcorp Model: CDDVDW SE-208AB Rev: TS03
Type: CD-ROM ANSI SCSI revision: 00
Host scsi8: usb-storage
Vendor: MediaTek Inc
Product: MT1806
Serial Number: R8KN6GAC7016QS
Protocol: 8020i
Transport: Bulk
Quirks:
CD-ROM_information,_Id:_cdrom.c_3.20_2003/12/17

drive_name: sr2
drive_speed: 24
drive_#_of_slots: 1
Can_close_tray: 1
Can_open_tray: 1
Can_lock_tray: 1
Can_change_speed: 1
Can_select_disk: 0
Can_read_multisession: 1
Can_read_MCN: 1
Reports_media_changed: 1
Can_play_audio: 1
Can_write_CD-R: 1
Can_write_CD-RW: 1
Can_read_DVD: 1
Can_write_DVD-R: 1
Can_write_DVD-RAM: 1
Can_read_MRW: 1
Can_write_MRW: 1
Can_write_RAM: 1

real 0m2.214s
user 0m1.004s
sys 0m0.216s
:?:

Post Reply