qubes-hcl-report 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. #!/bin/bash
  2. # The Qubes OS Project, http://www.qubes-os.org
  3. #
  4. # Copyright (C) 2013 Laszlo Zrubecz <mail@zrubi.hu>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. VERSION=2.5
  20. COPY2VM="dom0"
  21. SUPPORT_FILES=0
  22. XL_DMESG_PREFIX_REGEX='^(XEN) \(\[[^]]*\] \)\?'
  23. while [ $# -gt 0 ]; do
  24. case "$1" in
  25. -s |--support)
  26. SUPPORT_FILES=1
  27. ;;
  28. -* | -h | --help)
  29. echo -e "qubes-hcl-report v$VERSION"
  30. echo ""
  31. echo "This tool is used to gather basic hardware information for the Qubes HCL (Hardware Compatibility List)"
  32. echo "and copy the results to the given AppVM for the easy contribution."
  33. echo ""
  34. echo -e "Usage:\tqubes-hcl-report [OPTIONS] [<AppVM Name>]"
  35. echo -e "Options are:"
  36. echo -e "\t-h, --help\tDisplay this help text and exit."
  37. echo -e "\t-s, --support\tGenerate more detailed HCL Support Files"
  38. echo -e "\t\t\tWARNING: The HCL Support Files may contain numerous hardware details, including serial numbers."
  39. echo -e "\t\t\tIf, for privacy or security reasons, you do not wish to make this information public, "
  40. echo -e "\t\t\tplease do not send the .cpio.gz file to the public mailing list."
  41. echo ""
  42. echo -e "\t<AppVM Name>\tCopy the results to the given AppVM. The default is to keep it in dom0"
  43. echo ""
  44. exit
  45. ;;
  46. *)
  47. /usr/bin/qvm-check -q $1
  48. if [[ $? -eq 0 ]]
  49. then
  50. COPY2VM="$1"
  51. else
  52. echo -e "ERROR:\tAppVM with the name '$1' does not exist in the system!"
  53. exit 1
  54. fi
  55. ;;
  56. esac
  57. shift
  58. done
  59. DATE=`date +%Y%m%d-%H%M%S`
  60. TEMP_DIR=`mktemp --tmpdir -d HCL.XXXXXXXXXX`
  61. cat /etc/qubes-release > $TEMP_DIR/qubes-release
  62. cat /proc/cpuinfo > $TEMP_DIR/cpuinfo
  63. lspci -nnvk > $TEMP_DIR/lspci
  64. cat /proc/scsi/scsi > $TEMP_DIR/scsi
  65. sudo dmidecode > $TEMP_DIR/dmidecode
  66. xl info > $TEMP_DIR/xl-info
  67. xl dmesg > $TEMP_DIR/xl-dmesg
  68. if cat $TEMP_DIR/xl-dmesg | grep "$XL_DMESG_PREFIX_REGEX"'Xen version ' > /dev/null; then
  69. XL_DMESG_INCOMPLETE=no
  70. else
  71. XL_DMESG_INCOMPLETE=yes
  72. echo -e 'WARNING: "xl dmesg" is incomplete. Some information are missing. Please reboot and try again.\n'
  73. fi
  74. BRAND=`cat $TEMP_DIR/dmidecode |grep -A9 "System Information" |grep "Manufacturer:" |cut -d ' ' -f2-`
  75. PRODUCT=`cat $TEMP_DIR/dmidecode |grep -A9 "System Information" |grep "Product Name:" |cut -d ' ' -f3-`
  76. TYPE=`cat $TEMP_DIR/dmidecode |grep -A9 "Chassis Information" |grep Type |cut -d ' ' -f2- |tr '[:upper:]' '[:lower:]'`
  77. if [[ $BRAND =~ "O.E.M" ]]
  78. then
  79. BRAND=`cat $TEMP_DIR/dmidecode |grep -A9 "Base Board Information" |grep "Manufacturer:" |cut -d ' ' -f2-`
  80. PRODUCT=`cat $TEMP_DIR/dmidecode |grep -A9 "Base Board Information" |grep "Product Name:" |cut -d ' ' -f3-`
  81. fi
  82. KERNEL=`uname -r |cut -d '.' -f-3`
  83. CPU=`cat $TEMP_DIR/cpuinfo |grep "model name" |sort -u |cut -d ' ' -f3- |sed -e "s/[[:space:]]*/\ /"`
  84. CHIPSET=`cat $TEMP_DIR/lspci |grep "00:00.0.*Host bridge" |cut -d ':' -f3- |sed -e "s/[[:space:]]*/\ /"`
  85. VGA=`cat $TEMP_DIR/lspci |grep "VGA\|Display" |cut -d ':' -f3- |sed -e "s/^[[:space:]]*/\ /"`
  86. NET=`cat $TEMP_DIR/lspci |lspci |grep "Network\|Ethernet" |cut -d ':' -f3- |sed -e "s/^[[:space:]]*/\ /"`
  87. SCSI=`cat $TEMP_DIR/scsi |grep Model |cut -d ':' -f3-|sed -e "s/^[[:space:]]*/\ /"`
  88. RAM=`cat $TEMP_DIR/xl-info |grep total_memory |cut -d ':' -f2 |tr -d ' '`
  89. BIOS=`cat $TEMP_DIR/dmidecode |grep -A9 "BIOS Information" |grep "Version" |cut -d ' ' -f2-`
  90. XEN_MAJOR=`cat $TEMP_DIR/xl-info |grep xen_major |cut -d: -f2 |tr -d ' '`
  91. XEN_MINOR=`cat $TEMP_DIR/xl-info |grep xen_minor |cut -d: -f2 |tr -d ' '`
  92. XEN_EXTRA=`cat $TEMP_DIR/xl-info |grep xen_extra |cut -d: -f2 |tr -d ' '`
  93. QUBES=`cat $TEMP_DIR/qubes-release |cut -d '(' -f2 |cut -d ')' -f1`
  94. XL_VTX=`cat $TEMP_DIR/xl-info |grep xen_caps | grep hvm`
  95. XL_VTD=`cat $TEMP_DIR/xl-info |grep virt_caps |grep hvm_directio`
  96. XL_HAP=`cat $TEMP_DIR/xl-dmesg |grep "$XL_DMESG_PREFIX_REGEX"'HVM: Hardware Assisted Paging (HAP) detected\( but disabled\)\?$'`
  97. PCRS=`find /sys/devices/ -name pcrs`
  98. FILENAME="Qubes-HCL-${BRAND//[^[:alnum:]]/_}-${PRODUCT//[^[:alnum:]]/_}-$DATE"
  99. if [[ $XL_VTX ]]
  100. then
  101. VTX="Active"
  102. HVM="yes"
  103. else
  104. VTX="Not active"
  105. HVM="no"
  106. fi
  107. if [[ $XL_VTD ]]
  108. then
  109. VTD="Active"
  110. IOMMU="yes"
  111. else
  112. VTD="Not active"
  113. IOMMU="no"
  114. fi
  115. if [ $XL_DMESG_INCOMPLETE = yes ]; then
  116. HAP=""
  117. HAP_VERBOSE='Unknown ("xl dmesg" incomplete)'
  118. elif [ -n "$XL_HAP" ]; then
  119. HAP="yes"
  120. HAP_VERBOSE="Yes"
  121. if [[ "$XL_HAP" =~ "disabled" ]]; then
  122. HAP_VERBOSE="Yes (disabled)"
  123. fi
  124. else
  125. HAP="no"
  126. HAP_VERBOSE="No"
  127. fi
  128. if [[ $PCRS ]]
  129. then
  130. # try tu run tcsd and: grep the logs, try get version info.
  131. TPM="Device present"
  132. else
  133. TPM="Device not found"
  134. TPM_s="unknown"
  135. fi
  136. cat /etc/qubes-release
  137. echo
  138. echo -e "Brand:\t\t$BRAND"
  139. echo -e "Model:\t\t$PRODUCT"
  140. echo -e "BIOS:\t\t$BIOS\n"
  141. echo -e "Xen:\t\t$XEN_MAJOR.$XEN_MINOR$XEN_EXTRA"
  142. echo -e "Kernel:\t\t$KERNEL\n"
  143. echo -e "RAM:\t\t$RAM Mb\n"
  144. echo -e "CPU:\n$CPU"
  145. echo -e "Chipset:\n$CHIPSET"
  146. echo -e "VGA:\n${VGA}\n"
  147. echo -e "Net:\n$NET\n"
  148. echo -e "SCSI:\n$SCSI\n"
  149. echo -e "HVM:\t\t$VTX"
  150. echo -e "I/O MMU:\t$VTD"
  151. echo -e "HAP/SLAT:\t$HAP_VERBOSE"
  152. echo -e "TPM:\t\t$TPM"
  153. echo
  154. echo -e "---
  155. layout:
  156. 'hcl'
  157. type:
  158. '$TYPE'
  159. hvm:
  160. '$HVM'
  161. iommu:
  162. '$IOMMU'
  163. slat:
  164. '$HAP'
  165. tpm:
  166. '$TPM_s'
  167. brand: |
  168. $BRAND
  169. model: |
  170. $PRODUCT
  171. bios: |
  172. $BIOS
  173. cpu: |
  174. $CPU
  175. cpu-short: |
  176. FIXME
  177. chipset: |
  178. $CHIPSET
  179. chipset-short: |
  180. FIXME
  181. gpu: |
  182. $VGA
  183. gpu-short: |
  184. FIXME
  185. network: |
  186. $NET
  187. memory: |
  188. $RAM
  189. scsi: |
  190. $SCSI
  191. versions:
  192. - works:
  193. 'FIXME:yes|no|partial'
  194. qubes: |
  195. $QUBES
  196. xen: |
  197. $XEN_MAJOR.$XEN_MINOR$XEN_EXTRA
  198. kernel: |
  199. $KERNEL
  200. remark: |
  201. FIXME
  202. credit: |
  203. FIXAUTHOR
  204. link: |
  205. FIXLINK
  206. ---
  207. " >> "$HOME/$FILENAME.yml"
  208. if [[ "$SUPPORT_FILES" == 1 ]]
  209. then
  210. # cpio
  211. cd $TEMP_DIR
  212. find -print0 | cpio --quiet -o -H crc --null | gzip > "$HOME/$FILENAME.cpio.gz"
  213. cd
  214. fi
  215. # Destination VM check
  216. if [[ "$COPY2VM" != "dom0" ]]
  217. then
  218. # Copy to VM
  219. qvm-start -q $COPY2VM 2> /dev/null
  220. if [[ -f "$HOME/$FILENAME.cpio.gz" ]]
  221. then
  222. cat "$HOME/$FILENAME.cpio.gz" | qvm-run -a -q --pass-io $COPY2VM "cat > \"/home/user/$FILENAME.cpio.gz\""
  223. fi
  224. if [[ -f "$HOME/$FILENAME.yml" ]]
  225. then
  226. cat "$HOME/$FILENAME.yml" | qvm-run -a -q --pass-io $COPY2VM "cat > \"/home/user/$FILENAME.yml\""
  227. fi
  228. fi
  229. echo -e "Qubes HCL Files are copied to: '$COPY2VM'"
  230. echo -e "\t$FILENAME.yml\t\t- HCL Info"
  231. if [[ "$SUPPORT_FILES" == 1 ]]
  232. then
  233. echo -e "\t$FILENAME.cpio.gz\t- HCL Support Files"
  234. fi
  235. echo
  236. # cleanup
  237. if [[ -d $TEMP_DIR ]]
  238. then
  239. rm -rf $TEMP_DIR
  240. fi