check-device.sh 943 B

1234567891011121314151617181920212223242526
  1. check_device()
  2. {
  3. # checking if the disk is used
  4. if [ ! -e ${DEVICE} ] ; then
  5. fatal ${NOTEX_E} "${DEVICE} does not exist"
  6. fi
  7. if [ ! -b ${DEVICE} ] ; then
  8. fatal ${NOTBLK_E} "${DEVICE} is not a block file"
  9. fi
  10. if grep --quiet "${DEVICE}" /proc/mounts ; then
  11. fatal ${ISMOUNT_E} "${DEVICE} is mounted"
  12. fi
  13. if grep --quiet "${DEVICE}" /proc/swaps ; then
  14. fatal ${ISSWAP_E} "${DEVICE} is udes as swap"
  15. fi
  16. if pvs | grep --quiet "${DEVICE}" ; then
  17. 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
  18. fatal ${LVMUSED_E} "${DEVICE} is part of a used lvm volume"
  19. fi
  20. if [ $(vgs --noheadings --select pv_name=~"${DEVICE}" -o pv_count | uniq) -gt $(vgs --noheadings --select pv_name=~"${DEVICE}" | wc -l) ] ; then
  21. fatal ${LVMPV_E} "${DEVICE} is part of a lvm volume group shared with other physical volumes"
  22. fi
  23. LVM=1
  24. fi
  25. }