2 # Filename: grml-hwinfo
3 # Purpose: get hardware information
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
8 # Notice: Some ideas have been taken from
9 # http://club.black.co.at/david/hwdb/infodump
10 # by David Schmitt <david@schmitt.edv-bus.at>
11 ################################################################################
16 [ -n "$WORKING_DIR" -a -d "$WORKING_DIR" ] || WORKING_DIR=$(pwd)
19 TIMESTAMP='+%F--%H-%M-%S-%Z'
20 DATE="$(date $TIMESTAMP)"
25 while getopts "hdf" args; do
27 h) echo "$PN - collect hardware information
29 This tool collects information of the hardware this tool is being executed
30 on. It can be executed as normal user to collect some basic information or
31 with root permissions to collect as much information as possible. By
32 default, a file named grml-hwinfo-TIMESTAMP.tar.bz2 storing all collected
33 information will be created in the current working directory. Alternatively,
34 you can have it create a directory with all information.
38 -h : Display this help
39 -f : Create grml-hwinfo-TIMESTAMP.tar.bz2
40 -d : Create grml-hwinfo-TIMESTAMP/
42 -df : Create both, the directory and the file
49 GENERATE_DIRECTORY='1'
52 f) # generating file; default behaviour
59 # Generate output/temporary directory name & path, and output file path
61 OUTDIRNAME="grml-hwinfo-${DATE}"
62 OUTDIR="${WORKING_DIR}/${OUTDIRNAME}"
63 mkdir "${OUTDIR}" || { echo 'Directory "'${OUTDIR}'" already exists, aborting.'>&2 ; exit 1; }
65 if [ -n "$GENERATE_FILE" ] ; then
66 OUTFILE_="${OUTDIR}.tar.bz2"
67 [ -e "${OUTFILE_}" ] && { echo 'File "'${OUTFILE_}'" already exists, aborting.'>&2 ; rm -r "${OUTDIR}"; exit 1; }
72 if [ "$(id -u)" != "0" ] ; then
74 echo "Notice: you are running $PN without root permissions. Not all information will be collected."
78 # check whether a binary is available and executable
81 echo 'Usage: exectest <binary>'>&2
84 test -e "$(which $1)" && return 0 || return 1
88 # echo a list of all disks and their size
89 # taken from http://cvs.debian.org/fai/lib/disk-info
91 local isdisk major minor blocks device suffix
92 while read major minor blocks device suffix; do
95 [ -f /proc/ide/$device/media ] && grep -q cdrom /proc/ide/$device/media && isdisk=0
96 [ "$isdisk" -eq 1 ] && echo "$device $blocks"
101 # print only every second entry; used by disk_info
104 if [ "$i" -eq 0 ]; then
114 # the variable holds a space separated list of devices and their block size
115 device_size=`grep -E ' cciss/c.d.$| ida/c.d.$| rd/c.d.$| hd.$| sd.$|/disc$' /proc/partitions | diskandsize`
116 # a list of all local disks, without size
117 disklist=`list_disks $device_size`
120 echo "Running grml-hwinfo ${VERSION} - collecting hardware information."
122 cd "${OUTDIR}" || exit 1
125 [ -n "$GENERATE_FILE" ] && echo "Output file: $OUTFILE"
126 [ -n "$GENERATE_DIRECTORY" ] && echo "Output directory: $OUTDIR"
127 echo "This might take a few seconds/minutes. Please be patient..."
131 if [ -r /etc/grml_version ] ; then
132 cat /etc/grml_version > grml_version
134 if [ -r /etc/debian_version ] ; then
135 cat /etc/debian_version > debian_version
140 [ -f /proc/scsi/scsi ] && cat /proc/scsi/scsi > scsi
141 (lspci; lspci -n) | sort > lspci
142 [ -r /proc/bus/pnp ] && lspnp > lspnp
143 [ -r /proc/bus/usb ] && lsusb > lsusb
144 cat /proc/partitions > partitions
145 find /proc/ide/ -name geometry -exec grep . {} \; > proc_ide 2>/dev/null
146 df -h > df 2>/dev/null
147 for i in free lsmod mount lsdev ; do
148 exectest $i && $i > $i
152 for i in cpuinfo interrupts cmdline devices dma fb iomem ioports \
153 mdstat meminfo modules mtrr pci version ; do
154 [ -r /proc/$i ] && cat /proc/$i > proc_$i
156 exectest sysdump && sysdump > sysdump 2>sysdump.error
157 # for sysnet in `find /proc/sys/net/*/ -type f | grep -v flush`; do cat $sysnet >> sysnet ; done
163 exectest discover && discover -v --type-summary --enable-bus all > discover 2> discover.2
164 exectest hwinfo && hwinfo log=hwinfo
165 exectest x86info && x86info > x86info 2>x86info.2
168 exectest ifconfig && ifconfig -v -a > ifconfig
169 exectest ip && ip route show > ip_route
170 exectest ip && ip link show > ip_link
171 exectest route && route -n > route
174 if exectest dpkg ; then
175 dpkg --get-selections > dpkg_get_selections
176 COLUMNS=300 dpkg --list > dpkg_list
177 COLUMNS=1000 dpkg -l linux-image-$UNAME | grep linux-image-$UNAME | tr -s ' ' > running_kernel
181 exectest laptop-detect && laptop-detect >/dev/null 2>/dev/null && echo "0" > laptop_detected
182 exectest acpi_available && acpi_available && cat /proc/acpi/info > acpi_info
183 exectest acpi && acpi > acpi 2> acpi.error && acpi -v > acpi.version
184 [ -r /proc/apm/ ] && apm > apm
187 if [ -r /proc/config.gz ] ; then
188 zcat /proc/config.gz > kernelconfig
190 [ -r /boot/config-$UNAME ] && cat /boot/config-$UNAME > kernelconfig
194 if [ -n "${DISPLAY}" ] ; then
195 exectest xviddetect && xviddetect > xviddetect
196 exectest xvidtune && xvidtune -show > xdivtune
197 exectest xrandr && xrandr > xrandr
198 exectest xdpyinfo && xdpyinfo > xdpyinfo
199 X -version > x_version 2>&1
202 for i in Xorg.0.log Xorg.7.log Xorg.8.log XFree86.0.log XFree86.7.log XFree86.8.log dmesg ; do
203 cp /var/log/$i log_$i 2>/dev/null
206 cp /etc/X11/xorg.conf xorg.conf 2>/dev/null
207 cp /etc/modules modules 2>/dev/null
208 cp /etc/X11/XF86Config-4 XF86Config-4 2>/dev/null
211 # sysinfo -class device -level all
214 if [ -n "$NOTROOT" ] ; then
215 echo "not running as root" > root
217 echo "running as root" > root
219 exectest sfdisk && sfdisk -d > sfdisk 2>sfdisk.error
220 exectest ddcprobe && ddcprobe > ddcprobe
221 exectest dmidecode && dmidecode > dmidecode
223 exectest dconf && dconf -o dconf
225 if [ -x /usr/share/doc/lm-sensors/examples/eeprom/decode-dimms.pl ] ; then
226 /usr/share/doc/lm-sensors/examples/eeprom/decode-dimms.pl > decode-dimms 2>decode-dimms.error
229 for disk in $disklist; do
230 exectest smartctl && echo "smartctl -a /dev/$disk :\n" >> smartctl && smartctl -a /dev/$disk >> smartctl && echo "\n\n" >> smartctl
231 exectest hdparm && echo "hdparm -iv /dev/$disk :\n" >> hdparm && hdparm -iv /dev/$disk >> hdparm && echo "\n\n" >> hdparm
232 exectest fdisk && echo "fdisk -lu /dev/$disk :\n" >> fdisk && fdisk -lu /dev/$disk >> fdisk 2>>fdisk.error && echo "\n\n" >> fdisk
233 exectest parted && echo "parted -s /dev/$disk :\n" >> parted && parted -s /dev/$disk print >> parted && echo "\n\n" >> parted
234 LC_ALL=C file -s /dev/$disk?* | grep -v ": empty" >> file_disk
244 if [ -n "$GENERATE_FILE" ] ; then
245 tar jcf "${OUTFILE}" "${OUTDIRNAME}"
246 [ -r "$OUTFILE" ] && echo "$OUTFILE ("$(ls -ahl "$OUTFILE" | awk '{print $5}')") has been generated."
249 # remove (temporary) output directory if needed, else keep it, as it doubles
250 # as the real output directory.
251 if [ -z "$GENERATE_DIRECTORY" ] ; then
254 [ -r "${OUTDIR}" ] && echo "${OUTDIR} has been generated."
259 ## END OF FILE##################################################################