qubes-hcl-report 7.4 KB

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