probepart_init 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/sh
  2. #Barry Kauler www.puppylinux.com
  3. #LGPL 2007 Puppy Linux www.puppylinux.com
  4. #17 june 2007
  5. #v3.93 10 dec 2007 BK: updated for 2.6.24 kernel, no /dev/hd*
  6. #v3.97 handle /dev/hd also for retro kernels.
  7. #v3.97 25feb2008 BK: guess_fstype does not work when testing 'makebootfat', use fdisk.
  8. #v4.01 19may2008 BK: bugfix for 2.6.25.4, ram entries in /proc/partitions.
  9. #100912 no longer supporting /proc/ide.
  10. #101127 debug output.
  11. #110125,110126 brought back /proc/ide /dev/hd* support.
  12. #111109 replace guess_fstype with blkid (note, blkid very slow, not preferred).
  13. #120602 kernel 3.2.18 major deviance from earlier kernels, /proc/partitions (and /sys/block) now shows /dev/sr0 when no disk.
  14. # new situation, getting duplicate /dev/sr0 so need 'sort -u'.
  15. #130127 related to 120602, also screen sr0-9 out of /proc/partitions -- this may fix some problems, see main 'probepart'.
  16. #130128 support 'udf' f.s. also see main 'probepart'.
  17. #***this one runs in initrd, very slightly different from the main one.***
  18. SUNITS="$1" #allowed params are '-k' or '-m'.
  19. OUTPUT=""
  20. ##devices that have partitions...
  21. #([^k] is to eliminate mmcblk0 device -- allow mmcblk0p1 etc) v4.01 bugfix eliminate ram... 110126
  22. #130127 [^kr][0-9] screens out sr0-9... (note, unfortunately will also screen out sdr0-9)
  23. PARTITIONS="`grep -E '^ .*[^kr][0-9]$' /proc/partitions | tr -s ' ' | cut -f 4-5 -d ' ' | grep -vE ' loop| ram'`"
  24. echo "PARTITIONS=${PARTITIONS}" > /tmp/probepart.log #101127
  25. PARTNAMES="`echo "$PARTITIONS" | cut -f 2 -d ' '`" #120602
  26. #101127 for comparison, log this... 110125 restore hd...
  27. SYSBLOCKSUB="`ls -1 /sys/block/*/ | grep -E '^hd|^scd|^sd|^mmc|^sr' | tr '\n' ' '`"
  28. echo "SYSBLOCKSUB=${SYSBLOCKSUB}" >> /tmp/probepart.log #101127
  29. #all disk devices...
  30. ALLDRVS="`ls -1 /sys/block | grep -E '^scd|^sd|^mmc|^sr'`"
  31. [ -e /proc/ide ] && ALLDRVS="${ALLDRVS}
  32. `ls -1 /proc/ide | grep '^hd'`" #110125 120602
  33. echo "ALLDRVS=${ALLDRVS}" >> /tmp/probepart.log #101127 for debugging.
  34. #all drives and partitions... 120602 sort... crap busybox sort does not support -V
  35. ALLDEVS="`echo "${PARTNAMES}
  36. ${ALLDRVS}" | sort -u | tr '\n' ' '`"
  37. for ONEDEV in $ALLDEVS
  38. do
  39. MEDIATYPE="" #130128
  40. FSTYPE="unknown"
  41. DPATTERN=' '${ONEDEV}'$'
  42. SIZE=`echo "$PARTITIONS" | grep "$DPATTERN" | cut -f 1 -d ' '`
  43. DEVICE="`echo "$PARTITIONS" | grep "$DPATTERN" | cut -f 2 -d ' '`"
  44. echo "ONEDEV=${ONEDEV} SIZE=${SIZE} DEVICE=${DEVICE}" >> /tmp/probepart.log #101127 for debugging.
  45. if [ ! $SIZE ];then
  46. [ "`echo "$PARTITIONS" | grep "$ONEDEV"`" != "" ] && continue
  47. #must be a device without partitions...
  48. SIZE=0
  49. DEVICE="$ONEDEV"
  50. case $DEVICE in
  51. hd*)
  52. [ "`cat /proc/ide/$DEVICE/media`" = "cdrom" ] && MEDIATYPE="optical" #130128
  53. ;;
  54. scd*|sr*) #usb,sata,scsi cd/dvd drive.
  55. MEDIATYPE="optical" #130128
  56. ;;
  57. esac
  58. if [ "$MEDIATYPE" != "optical" ];then #130128
  59. #for hd* or sd* superfloppy, determine size...
  60. BSIZE=`disktype /dev/$DEVICE 2>/dev/null | grep '^Block device' | cut -f 2 -d '(' | cut -f 1 -d ' '`
  61. [ $BSIZE ] && SIZE=$(($BSIZE/1024)) #KB
  62. fi
  63. fi
  64. if [ -f /bin/guess_fstype ];then
  65. FSTYPE="`guess_fstype /dev/$DEVICE 2>/dev/null`"
  66. else
  67. #111109 replace guess_fstype with blkid (note, blkid very slow, not preferred)...
  68. #130526 Karl Godt reported this o/p from blkid, breaks parsing:
  69. # /dev/sdb1: UUID="5a126d47-065d-4eb6-baf9-dd7701bfe71a" TYPE="ext4" LABEL="boot"
  70. FSTYPE="`blkid /dev/$DEVICE 2>/dev/null | grep -o ' TYPE=".*"' | cut -f 2 -d '"'`" #'geany 130526
  71. [ `echo "$FSTYPE" | wc -l` -gt 1 ] && FSTYPE="unknown" #blkid may fallback to returning all partitions.
  72. [ ! "$FSTYPE" ] && FSTYPE="unknown" #paranoid precaution.
  73. fi
  74. echo " SIZE=${SIZE} FSTYPE=${FSTYPE}" >> /tmp/probepart.log #101127 for debugging.
  75. #v3.97 guess_fstype fails sometimes...
  76. #(using makebootfat to setup a USB-FLOPPY/-HDD/-ZIP combined bootable FAT drive).
  77. xFSTYPE=''
  78. if [ "$FSTYPE" = "unknown" ];then
  79. fsPATTERN='^/dev/'"$DEVICE"' '
  80. xDEVICE="`echo -n "$DEVICE" | sed -e 's/[0-9]*$//'`" #"${DEVICE/[0-9]/}" #remove partition number.
  81. xFSTYPE="`fdisk -l /dev/$xDEVICE 2>/dev/null | grep "$fsPATTERN" | head -n 1 | grep -o -E 'FAT12$|FAT16$|FAT32$'`"
  82. [ "$xFSTYPE" != "" ] && FSTYPE='vfat'
  83. fi
  84. [ "$FSTYPE" = "unknown" ] && FSTYPE="none"
  85. [ "$SUNITS" = "" ] && SIZE=$(($SIZE*2)) #512 byte blocks.
  86. [ "$SUNITS" = '-m' ] && SIZE=$(($SIZE/1024)) #MB
  87. echo "/dev/$DEVICE|$FSTYPE|$SIZE"
  88. echo " /dev/$DEVICE|$FSTYPE|$SIZE" >> /tmp/probepart.log #101127
  89. done
  90. ###END###