17.7. 鉴别客户端类型及使用

下面的脚本可以鉴别系统是半虚拟客户端、全虚拟客户端还是裸机主机。

  1. #!/bin/bash
  2. declare -i IS_HVM=0
  3. declare -i IS_PARA=0
  4. check_hvm()
  5. {
  6. IS_X86HVM="$(strings /proc/acpi/dsdt | grep int-xen)"
  7. if [ x"${IS_X86HVM}" != x ]; then
  8. echo "Guest type is full-virt x86hvm"
  9. IS_HVM=1
  10. fi
  11. }
  12. check_para()
  13. {
  14. if $(grep -q control_d /proc/xen/capabilities); then
  15. echo "Host is dom0"
  16. IS_PARA=1
  17. else
  18. echo "Guest is para-virt domU"
  19. IS_PARA=1
  20. fi
  21. }
  22. if [ -f /proc/acpi/dsdt ]; then
  23. check_hvm
  24. fi
  25. if [ ${IS_HVM} -eq 0 ]; then
  26. if [ -f /proc/xen/capabilities ] ; then
  27. check_para
  28. fi
  29. fi
  30. if [ ${IS_HVM} -eq 0 -a ${IS_PARA} -eq 0 ]; then
  31. echo "Baremetal platform"
  32. fi

检查主机

要检查主机请使用 virsh capabilites 命令。