check-device.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. check_device()
  2. {
  3. LVM=0
  4. # checking if the disk is used
  5. if [ ! -e ${DEVICE} ] ; then
  6. fatal ${NOTEX_E} "${DEVICE} does not exist"
  7. fi
  8. if [ ! -b ${DEVICE} ] ; then
  9. fatal ${NOTBLK_E} "${DEVICE} is not a block file"
  10. fi
  11. MAJOR=$(echo $(mountpoint --devno "${DEVICE}") | awk -F: '{print $1}')
  12. MINOR=$(echo $(mountpoint --devno "${DEVICE}") | awk -F: '{print $2}')
  13. if [ $MAJOR -ne 254 ] && [ $MAJOR -ne 8 ] || [ $(($MINOR % 16)) -ne 0 ]; then
  14. fatal ${WRONGBLK_E} "${DEVICE} is not a regular disk"
  15. fi
  16. if grep --quiet "${DEVICE}" /proc/mounts ; then
  17. fatal ${ISMOUNT_E} "${DEVICE} is mounted"
  18. fi
  19. if grep --quiet "${DEVICE}" /proc/swaps ; then
  20. fatal ${ISSWAP_E} "${DEVICE} is udes as swap"
  21. fi
  22. if pvs | grep --quiet "${DEVICE}" ; then
  23. # check if the device has a open (e.g. mounted) lv
  24. if [ $(lvs --noheadings --select vg_name="$(pvs --noheadings --select pv_name=~"${DEVICE}" -o vg_name)" --select lv_device_open!=0 | wc -l) -ne 0 ] ; then
  25. fatal ${LVMUSED_E} "${DEVICE} is part of a used lvm volume"
  26. fi
  27. if [ $(vgs --noheadings --select pv_name=~"${DEVICE}" -o pv_count | uniq) -gt $(vgs --noheadings --select pv_name=~"${DEVICE}" | wc -l) ] ; then
  28. fatal ${LVMPV_E} "${DEVICE} is part of a lvm volume group shared with other physical volumes"
  29. fi
  30. LVM=1
  31. fi
  32. }