From bf3f6c105aa7fe9247ad707267f26623724d2a65 Mon Sep 17 00:00:00 2001 From: Lars Beckers <lars.beckers@rwth-aachen.de> Date: Thu, 8 Jan 2015 18:57:50 +0059 Subject: [PATCH] updated lipnsa Tried to resolve #308 using dmidecode instead of sysfs, which is now only fallback. But we likely still need to apply some sanity checks on the resulting lipstats as dmidecode itself is also not unaffected by faulty hardware. Also some other small changes. lsusb ist not yet disabled. Still trying to find a way to gather that information somehow. Signed-off-by: Lars Beckers <lars.beckers@rwth-aachen.de> --- initrd_hooks/lipnsa.hook.sh | 189 +++++++++++++++++++++++++++--------- 1 file changed, 141 insertions(+), 48 deletions(-) diff --git a/initrd_hooks/lipnsa.hook.sh b/initrd_hooks/lipnsa.hook.sh index b5714d7..b857d16 100644 --- a/initrd_hooks/lipnsa.hook.sh +++ b/initrd_hooks/lipnsa.hook.sh @@ -24,13 +24,14 @@ LIPSTATS="${LIPSTICK}/lipstats" if [ $# -gt 0 ]; then echo "collects system information, i.e. hardware and what the kernel thinks about it" echo "called as liphook before leaving initramfs" - echo "usage: lipnsa.sh" + echo "usage: lipnsa.sh [lipstick directory]" echo "" echo "requires proc and sysfs to be mounted" echo "append 'fnord' to your kernel cmdline to disable this tool" - echo "data is saved to ${LIPSTATS}/dmi-product-uuid/kernel-boot-id/" + echo "data is saved to ${LIPSTATS}/product-uuid/kernel-boot-id/" echo "${LIPSTICK} is remounted rw in the process, remounted ro at the end" - echo "if there is no dmi-product-uuid available a kernel-random-uuid will be used" + echo "considering the product-uuid we generally trust what dmidecode says" + echo "if it's unavailable we may use a fallback instead (sysfs, random by kernel)" echo "some commands are processed outside the initramfs, in a chroot using the prepared system" echo "" echo "currently lipnsa.sh collects the following:" @@ -68,11 +69,50 @@ fi log_success_msg "This is lipnsa.sh -- collecting your data for a better world" -UUID=`cat /sys/class/dmi/id/product_uuid` +# mounts for chrooted commands +# actually lsblk, lscpu and dmidecode work without chroot +# but i think it is more sane to not depend on that +TARGETMOUNTS=1 +mount -t proc proc ${TARGET}/proc if [ $? != 0 ]; then - log_warning_msg "> dmi system-uuid is unavailable, using random uuid" - UUID=`cat /proc/sys/kernel/random/uuid` + log_warning_msg "> could not mount proc on the target, this might produce wrong results" + TARGETMOUNTS=0 fi +mount -t sysfs sysfs ${TARGET}/sys +if [ $? != 0 ]; then + log_warning_msg "> could not mount sysfs on the target, this might produce wrong results" + TARGETMOUNTS=0 +fi + +UUID="unavailable" +UUID_SOURCE="dmidecode" +if [ $TARGETMOUNTS -gt 0 ]; then + UUID=`chroot ${TARGET} dmidecode --string system-uuid` + if [ $? != 0 ]; then + log_warning_msg "> dmidecode was unable to retrieve the system-uuid from chroot, trying without chroot" + else + UUID_SOURCE="dmidecode-chroot" + fi +fi + +if [ $UUID_SOURCE == "dmidecode" ]; then + UUID=`dmidecode --string system-uuid` + if [ $? != 0 ]; then + log_warning_msg "> dmidecode was unable to retrieve the system-uuid, trying sysfs dmi product_uuid" + UUID_SOURCE="sysfs" + UUID=`cat /sys/class/dmi/id/product_uuid` + if [ $? != 0 ]; then + log_warning_msg "> sysfs dmi product_uuid is unavailable, using random uuid" + UUID=`cat /proc/sys/kernel/random/uuid` + if [ $? != 0 ]; then + UUID_SOURCE="unavailable" + else + UUID_SOURCE="random" + fi + fi + fi +fi + BOOTID=`cat /proc/sys/kernel/random/boot_id` log_success_msg "> using ${UUID}/${BOOTID}" @@ -85,6 +125,20 @@ if [ $? != 0 ]; then fi log_success_msg "> remounted lipstick rw, created directory" +echo ${UUID_SOURCE} > "${DIR}/uuid_source" 2>&1 +if [ $? != 0 ]; then + log_failure_msg "> could not save uuid source" +else + log_success_msg "> saved uuid source" +fi + +echo ${TARGETMOUNTS} > "${DIR}/targetmounts" 2>&1 +if [ $? != 0 ]; then + log_failure_msg "> could not save usage of target mounts" +else + log_success_msg "> saved usage of target mounts" +fi + date +%s > "${DIR}/timestamp" 2>&1 if [ $? != 0 ]; then log_failure_msg "> could not save timestamp" @@ -168,68 +222,107 @@ else log_success_msg "> saved the partition list" fi -# chrooted commands -# actually lsblk, lscpu and dmidecode work without chroot -# but i think it is more sane to not depend on that -mount -t proc proc ${TARGET}/proc -if [ $? != 0 ]; then - log_warning_msg "> could not mount proc on the target, this might produce false results" -fi -mount -t sysfs sysfs ${TARGET}/sys -if [ $? != 0 ]; then - log_warning_msg "> could not mount sysfs on the target, this might produce false results" -fi - -chroot ${TARGET} lspci -mm > "${DIR}/lspci" 2>&1 -if [ $? != 0 ]; then - log_failure_msg "> could not save listing of pci devices" +if [ $TARGETMOUNTS -gt 0 ]; then + chroot ${TARGET} lspci -mm > "${DIR}/lspci" 2>&1 + if [ $? != 0 ]; then + log_failure_msg "> could not save listing of pci devices" + else + log_success_msg "> saved listing of pci devices" + fi else - log_success_msg "> saved listing of pci devices" + log_warning_msg "> not trying to gather pci devices due to unavailable mounts" fi -chroot ${TARGET} lsblk > "${DIR}/lsblk" 2>&1 -if [ $? != 0 ]; then - log_failure_msg "> could not save listing of block devices" +TRY_UNCHROOTED=0 +if [ $TARGETMOUNTS -gt 0 ]; then + chroot ${TARGET} lsblk > "${DIR}/lsblk" 2>&1 + if [ $? != 0 ]; then + log_warning_msg "> listing of block devices unsuccessful, trying without chroot" + TRY_UNCHROOTED=1 + else + log_success_msg "> saved listing of block devices" + fi else - log_success_msg "> saved listing of block devices" + TRY_UNCHROOTED=1 +fi +if [ $TRY_UNCHROOTED -gt 0 ]; then + lsblk >> "${DIR}/lsblk" 2>&1 + if [ $? != 0 ]; then + log_failure_msg "> could not save listing of block devices" + else + log_success_msg "> saved listing of block devices" + fi fi -chroot ${TARGET} lscpu > "${DIR}/lscpu" 2>&1 -if [ $? != 0 ]; then - log_failure_msg "> could not save listing of cpus" +TRY_UNCHROOTED=0 +if [ $TARGETMOUNTS -gt 0 ]; then + chroot ${TARGET} lscpu > "${DIR}/lscpu" 2>&1 + if [ $? != 0 ]; then + log_warning_msg "> listing of cpus unsuccessful, trying without chroot" + TRY_UNCHROOTED=1 + else + log_success_msg "> saved listing of cpus" + fi else - log_success_msg "> saved listing of cpus" + TRY_UNCHROOTED=1 +fi +if [ $TRY_UNCHROOTED -gt 0 ]; then + lscpu >> "${DIR}/lscpu" 2>&1 + if [ $? != 0 ]; then + log_failure_msg "> could not save listing of cpus" + else + log_success_msg "> saved listing of cpus" + fi fi -chroot ${TARGET} dmidecode > "${DIR}/dmidecode" 2>&1 -if [ $? != 0 ]; then - log_failure_msg "> could not save decoded dmi table" +TRY_UNCHROOTED=0 +if [ $TARGETMOUNTS -gt 0 ]; then + chroot ${TARGET} dmidecode > "${DIR}/dmidecode" 2>&1 + if [ $? != 0 ]; then + log_warning_msg "> unable to retrieve decoded dmi table, trying without chroot" + TRY_UNCHROOTED=1 + else + log_success_msg "> saved decoded dmi table" + fi else - log_success_msg "> saved decoded dmi table" + TRY_UNCHROOTED=1 +fi +if [ $TRY_UNCHROOTED -gt 0 ]; then + dmidecode >> "${DIR}/dmidecode" 2>&1 + if [ $? != 0 ]; then + log_failure_msg "> could not save decoded dmi table" + else + log_success_msg "> saved decoded dmi table" + fi fi -chroot ${TARGET} lsusb > "${DIR}/lsusb" 2>&1 -if [ $? != 0 ]; then - grep "unable to initialize libusb: -99" "${DIR}/lsusb" +if [ $TARGETMOUNTS -gt 0 ]; then + chroot ${TARGET} lsusb > "${DIR}/lsusb" 2>&1 if [ $? != 0 ]; then - log_failure_msg "> could not save listing of usb devices" + grep "unable to initialize libusb: -99" "${DIR}/lsusb" + if [ $? != 0 ]; then + log_failure_msg "> could not save listing of usb devices" + else + echo "no usb controller found" > "${DIR}/lsusb" 2>&1 + log_success_msg "> saved listing of usb devices" + fi else - echo "no usb controller found" > "${DIR}/lsusb" 2>&1 log_success_msg "> saved listing of usb devices" fi else - log_success_msg "> saved listing of usb devices" + log_warning_msg "> not trying to gather usb devices due to unavailable mounts" fi -umount ${TARGET}/sys -if [ $? != 0 ]; then - log_warning_msg "> could not unmount sysfs on the target, this might cause some trouble" -fi -umount ${TARGET}/proc -if [ $? != 0 ]; then - log_warning_msg "> could not unmount proc on the target, this might cause some trouble" +if [ $TARGETMOUNTS -gt 0 ]; then + umount ${TARGET}/sys + if [ $? != 0 ] && [ $TARGETMOUNTS -gt 0 ]; then + log_warning_msg "> could not unmount sysfs on the target, this might cause some trouble" + fi + umount ${TARGET}/proc + if [ $? != 0 ] && [ $TARGETMOUNTS -gt 0 ]; then + log_warning_msg "> could not unmount proc on the target, this might cause some trouble" + fi fi -# chrooted commands sync if [ $? != 0 ]; then -- GitLab