blkid 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. #!/bin/sh
  2. # this script depends on /sbin/blkid from the util-linux package
  3. # usage: blkid <device> <fs_type>
  4. # <device> may be any device that should be checked.
  5. # if no <fs_type> is given, the check fails if no valid filesystem is found.
  6. # if <fs_type> is given, the check fails when no filesystem type <fs_type>
  7. # is found on the device. if <fs_type> is 'none', the check fails if any
  8. # know filesystem is found.
  9. if test ! -x "/sbin/blkid"; then
  10. echo " - WARNING: blkid from util-linux is not available, impossible to run checks."
  11. exit 1
  12. fi
  13. dev="$1"
  14. fs="$2"
  15. blkid="$(/sbin/blkid -o value -s TYPE -p -- "$dev")"
  16. # blkid output is empty if $dev has an unknown filesystem
  17. if [ -z "$blkid" ] && [ -z "$fs" ]; then
  18. echo " - The device $dev does not contain a known filesystem."
  19. exit 1
  20. elif [ -n "$blkid" ] && [ "$fs" = "none" ]; then
  21. echo " - The device $dev contains a filesystem type $blkid."
  22. exit 1
  23. elif [ -n "$fs" ] && [ "$blkid" != "$fs" ]; then
  24. echo " - The device $dev does not contain a filesystem type $fs."
  25. exit 1
  26. fi