qubes-hcl-report 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. USB=`lspci|grep USB|wc -l`
  90. BIOS=`cat $TEMP_DIR/dmidecode |grep -A9 "BIOS Information" |grep "Version" |cut -d ' ' -f2-`
  91. XEN_MAJOR=`cat $TEMP_DIR/xl-info |grep xen_major |cut -d: -f2 |tr -d ' '`
  92. XEN_MINOR=`cat $TEMP_DIR/xl-info |grep xen_minor |cut -d: -f2 |tr -d ' '`
  93. XEN_EXTRA=`cat $TEMP_DIR/xl-info |grep xen_extra |cut -d: -f2 |tr -d ' '`
  94. QUBES=`cat $TEMP_DIR/qubes-release |cut -d '(' -f2 |cut -d ')' -f1`
  95. XL_VTX=`cat $TEMP_DIR/xl-info |grep xen_caps | grep hvm`
  96. XL_VTD=`cat $TEMP_DIR/xl-info |grep virt_caps |grep hvm_directio`
  97. XL_HAP=`cat $TEMP_DIR/xl-dmesg |grep "$XL_DMESG_PREFIX_REGEX"'HVM: Hardware Assisted Paging (HAP) detected\( but disabled\)\?$'`
  98. PCRS=`find /sys/devices/ -name pcrs`
  99. XL_REMAP=`cat $TEMP_DIR/xl-dmesg |grep "$XL_DMESG_PREFIX_REGEX"'Intel VT-d Interrupt Remapping enabled'`
  100. FILENAME="Qubes-HCL-${BRAND//[^[:alnum:]]/_}-${PRODUCT//[^[:alnum:]]/_}-$DATE"
  101. if [[ $XL_VTX ]]
  102. then
  103. VTX="Active"
  104. HVM="yes"
  105. else
  106. VTX="Not active"
  107. HVM="no"
  108. fi
  109. if [[ $XL_VTD ]]
  110. then
  111. VTD="Active"
  112. IOMMU="yes"
  113. else
  114. VTD="Not active"
  115. IOMMU="no"
  116. fi
  117. if [ $XL_DMESG_INCOMPLETE = yes ]; then
  118. HAP=""
  119. HAP_VERBOSE='Unknown ("xl dmesg" incomplete)'
  120. elif [ -n "$XL_HAP" ]; then
  121. HAP="yes"
  122. HAP_VERBOSE="Yes"
  123. if [[ "$XL_HAP" =~ "disabled" ]]; then
  124. HAP_VERBOSE="Yes (disabled)"
  125. fi
  126. else
  127. HAP="no"
  128. HAP_VERBOSE="No"
  129. fi
  130. if [[ $PCRS ]]
  131. then
  132. # try tu run tcsd and: grep the logs, try get version info.
  133. TPM="Device present"
  134. else
  135. TPM="Device not found"
  136. TPM_s="unknown"
  137. fi
  138. if [[ $XL_REMAP ]]
  139. then
  140. REMAP="yes"
  141. else
  142. REMAP="no"
  143. fi
  144. cat /etc/qubes-release
  145. echo
  146. echo -e "Brand:\t\t$BRAND"
  147. echo -e "Model:\t\t$PRODUCT"
  148. echo -e "BIOS:\t\t$BIOS\n"
  149. echo -e "Xen:\t\t$XEN_MAJOR.$XEN_MINOR$XEN_EXTRA"
  150. echo -e "Kernel:\t\t$KERNEL\n"
  151. echo -e "RAM:\t\t$RAM Mb\n"
  152. echo -e "CPU:\n$CPU"
  153. echo -e "Chipset:\n$CHIPSET"
  154. echo -e "VGA:\n${VGA}\n"
  155. echo -e "Net:\n$NET\n"
  156. echo -e "SCSI:\n$SCSI\n"
  157. echo -e "HVM:\t\t$VTX"
  158. echo -e "I/O MMU:\t$VTD"
  159. echo -e "HAP/SLAT:\t$HAP_VERBOSE"
  160. echo -e "TPM:\t\t$TPM"
  161. echo -e "Remapping:\t$REMAP"
  162. echo
  163. echo -e "---
  164. layout:
  165. 'hcl'
  166. type:
  167. '$TYPE'
  168. hvm:
  169. '$HVM'
  170. iommu:
  171. '$IOMMU'
  172. slat:
  173. '$HAP'
  174. tpm:
  175. '$TPM_s'
  176. remap:
  177. '$REMAP'
  178. brand: |
  179. $BRAND
  180. model: |
  181. $PRODUCT
  182. bios: |
  183. $BIOS
  184. cpu: |
  185. $CPU
  186. cpu-short: |
  187. FIXME
  188. chipset: |
  189. $CHIPSET
  190. chipset-short: |
  191. FIXME
  192. gpu: |
  193. $VGA
  194. gpu-short: |
  195. FIXME
  196. network: |
  197. $NET
  198. memory: |
  199. $RAM
  200. scsi: |
  201. $SCSI
  202. usb: |
  203. $USB
  204. versions:
  205. - works:
  206. 'FIXME:yes|no|partial'
  207. qubes: |
  208. $QUBES
  209. xen: |
  210. $XEN_MAJOR.$XEN_MINOR$XEN_EXTRA
  211. kernel: |
  212. $KERNEL
  213. remark: |
  214. FIXME
  215. credit: |
  216. FIXAUTHOR
  217. link: |
  218. FIXLINK
  219. ---
  220. " >> "$HOME/$FILENAME.yml"
  221. if [[ "$SUPPORT_FILES" == 1 ]]
  222. then
  223. # cpio
  224. cd $TEMP_DIR
  225. find -print0 | cpio --quiet -o -H crc --null | gzip > "$HOME/$FILENAME.cpio.gz"
  226. cd
  227. fi
  228. # Destination VM check
  229. if [[ "$COPY2VM" != "dom0" ]]
  230. then
  231. # Copy to VM
  232. qvm-start -q $COPY2VM 2> /dev/null
  233. if [[ -f "$HOME/$FILENAME.cpio.gz" ]]
  234. then
  235. cat "$HOME/$FILENAME.cpio.gz" | qvm-run -a -q --pass-io $COPY2VM "cat > \"/home/user/$FILENAME.cpio.gz\""
  236. fi
  237. if [[ -f "$HOME/$FILENAME.yml" ]]
  238. then
  239. cat "$HOME/$FILENAME.yml" | qvm-run -a -q --pass-io $COPY2VM "cat > \"/home/user/$FILENAME.yml\""
  240. fi
  241. fi
  242. echo -e "Qubes HCL Files are copied to: '$COPY2VM'"
  243. echo -e "\t$FILENAME.yml\t\t- HCL Info"
  244. if [[ "$SUPPORT_FILES" == 1 ]]
  245. then
  246. echo -e "\t$FILENAME.cpio.gz\t- HCL Support Files"
  247. fi
  248. echo
  249. # cleanup
  250. if [[ -d $TEMP_DIR ]]
  251. then
  252. rm -rf $TEMP_DIR
  253. fi