fs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. # skip root disk here, will be handled in /etc/init.d/fs
  3. rootdisk=$(readlink /dev/root)
  4. if [ "x${rootdisk}" = "x${MDEV}" ];then
  5. exit 0
  6. fi
  7. uuid=$(blkid /dev/${MDEV} | sed -n '/^.*UUID="\([^"]*\)".*$/s//\1/p')
  8. if [ -z $uuid ];then
  9. fs=$(grep "^/dev/${MDEV}[[:blank:]]" /etc/fstab | awk '{ print $3 }')
  10. mnt=$(grep "^/dev/${MDEV}[[:blank:]]" /etc/fstab | awk '{ print $2 }')
  11. disk="${MDEV}"
  12. else
  13. fs=$(grep "^/dev/${MDEV}[[:blank:]]\|^UUID=$uuid" /etc/fstab | awk '{ print $3 }')
  14. mnt=$(grep "^/dev/${MDEV}[[:blank:]]\|^UUID=$uuid" /etc/fstab | awk '{ print $2 }')
  15. disk="${MDEV} (${uuid})"
  16. fi
  17. if [ -z $fs ];then
  18. logger -t mdev "Disk $disk not registered in /etc/fstab"
  19. exit 0
  20. fi
  21. procfs=$fs
  22. if [ $fs = "ntfs-3g" ];then
  23. procfs=fuse
  24. fi
  25. # check if already mounted via /etc/init.d/fs
  26. adk_check() {
  27. mount | grep "${MDEV}[[:blank:]]"
  28. if [ $? -eq 0 ];then
  29. logger -t mdev "Filesystem on ${MDEV} already mounted"
  30. exit 0
  31. fi
  32. }
  33. # filesystem check
  34. adk_fsck() {
  35. [ -x /usr/sbin/fsck.$fs ] && {
  36. logger -t mdev "Checking $fs filesystem on ${MDEV}"
  37. fsck -p ${MDEV} >/dev/null
  38. }
  39. }
  40. # mount filesystem
  41. adk_mount() {
  42. mkdir -p $mnt >/dev/null 2>&1
  43. grep $procfs /proc/filesystems >/dev/null 2>&1
  44. if [ $? -eq 0 ];then
  45. logger -t mdev "Mounting $disk to $mnt"
  46. mount $mnt 2>> /tmp/mount.err
  47. if [ $? -ne 0 ]; then
  48. logger -t mdev "Mounting $disk failed with $?"
  49. fi
  50. else
  51. logger -t mdev "Required filesystem $procfs not available"
  52. fi
  53. }
  54. case "${ACTION}" in
  55. add)
  56. logger -t mdev "Device ${MDEV} added to the system"
  57. adk_check
  58. adk_fsck
  59. adk_mount
  60. ;;
  61. esac
  62. exit 0