check-device.sh 950 B

123456789101112131415161718192021222324252627
  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. if grep --quiet "${DEVICE}" /proc/mounts ; then
  12. fatal ${ISMOUNT_E} "${DEVICE} is mounted"
  13. fi
  14. if grep --quiet "${DEVICE}" /proc/swaps ; then
  15. fatal ${ISSWAP_E} "${DEVICE} is udes as swap"
  16. fi
  17. if pvs | grep --quiet "${DEVICE}" ; then
  18. 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
  19. fatal ${LVMUSED_E} "${DEVICE} is part of a used lvm volume"
  20. fi
  21. if [ $(vgs --noheadings --select pv_name=~"${DEVICE}" -o pv_count | uniq) -gt $(vgs --noheadings --select pv_name=~"${DEVICE}" | wc -l) ] ; then
  22. fatal ${LVMPV_E} "${DEVICE} is part of a lvm volume group shared with other physical volumes"
  23. fi
  24. LVM=1
  25. fi
  26. }