From ac5ba52862a31ae9da83b325fa832cdebb3b90a1 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 12 Oct 2016 19:40:32 +0200 Subject: [rootfs/hwstats] Use 66% RAM as /tmp tmpfs instead of 60G so we can detect and report when running out of memory --- .../data/opt/openslx/scripts/systemd-setup_partitions | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'remote/rootfs/rootfs-stage32/data/opt/openslx/scripts') diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions index 0c352241..c8e680f0 100755 --- a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions @@ -152,9 +152,13 @@ done mount -a -# Make huge tmpfs if nothing could be mounted for /tmp +# Make tmpfs if nothing could be mounted for /tmp +# 2016-10-12: Use a sane size of 66% which should be generous enough and prevent the machine from +# just crashing if RAM is too full. We previously hugely oversized since vmware wants at least as +# much free space as the VMs RAM; however, this requirement can be disabled with a vmx setting, +# which we're now doing. if [ "$HAVE_TEMP" = "no" ]; then - mount_temp -t tmpfs -o size=60G none + mount_temp -t tmpfs -o size=66% none slxlog "partition-temp" "Running /tmp on tmpfs only!" "/etc/disk.partition" fi if [ "$HAVE_SWAP" = "no" ]; then -- cgit v1.2.3-55-g7522 From 529bb1c4b20dc6264a0978b0130657c6f8b61425 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 17 Oct 2016 19:05:56 +0200 Subject: [rfs-stage32] Improve /etc/issue generator --- .../data/opt/openslx/scripts/openslx-create_issue | 44 ++++++++++++++++++---- .../rootfs/rootfs-stage32/templates/issue.template | 6 ++- 2 files changed, 41 insertions(+), 9 deletions(-) (limited to 'remote/rootfs/rootfs-stage32/data/opt/openslx/scripts') diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/openslx-create_issue b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/openslx-create_issue index 4d2de8b7..d3086176 100755 --- a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/openslx-create_issue +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/openslx-create_issue @@ -1,4 +1,5 @@ -#!/bin/ash +#!/bin/bash +# Needs bash for string manipulation # Copyright (c) 2013, 2014 - bwLehrpool Projekt # Copyright (c) 2012 - OpenSLX GmbH # @@ -14,11 +15,40 @@ ############################################################################# # Set greeting and add information about the booted system -len=$(expr length "$(cat /etc/hostname)") -while [ $len -le 56 ] ; do - space="$space " - len=$(($len + 1)) -done -sed "s/%space%/$space/g" /opt/openslx/etc/issue.template > /etc/issue +declare -rg INFILE=/opt/openslx/etc/issue.template +declare -rg TMPFILE=$(mktemp) +declare -rg OUTFILE=/etc/issue + +. /opt/openslx/config + +# Replace known variables and determine maximum line length +MAX=0 +while IFS='' read -r line || [ -n "$line" ]; do + line="${line/"%ip%"/"$SLX_PXE_CLIENT_IP"}" + line="${line/"%hostname%"/"$SLX_HOSTNAME"}" + len=${#line} + [ "$len" -gt "$MAX" ] && MAX=$len + echo "$line" +done < "$INFILE" > "$TMPFILE" + +# Fix up spacing for right-aligned text +while IFS='' read -r line || [ -n "$line" ]; do + tst=${line/"%space%"/} + if [ "$(( ${#line} - ${#tst} ))" -eq 7 ]; then + space= + while true; do + tst=${line/"%space%"/"$space"} + if [ "${#tst}" -ge "$MAX" ]; then + line="$tst" + break + fi + space=" $space" + done + fi + echo "$line" +done < "$TMPFILE" > "$OUTFILE" + +rm -f -- "$TMPFILE" + diff --git a/remote/rootfs/rootfs-stage32/templates/issue.template b/remote/rootfs/rootfs-stage32/templates/issue.template index a79797ad..adf1f38e 100644 --- a/remote/rootfs/rootfs-stage32/templates/issue.template +++ b/remote/rootfs/rootfs-stage32/templates/issue.template @@ -1,4 +1,5 @@ - WELCOME TO %space% \n (\l) +-- \l + WELCOME TO %space% %hostname% [%ip%] _____ ______ ______ __ __ _______ __ __ __ / _ | _ | ___| | | | | ____| | | | | | | | | | |_| | |_ | | | | |___ | | / / @@ -6,4 +7,5 @@ | |_| | | | |___| | | | ____| | |___ / / _____/|__| |______|__| |__| |_______|______|__| |__| - NG - %version% (c) + %version% %space% (c) + -- cgit v1.2.3-55-g7522 From 28438e02be61c27461e26fee4980e4db336b3458 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 17 Oct 2016 19:53:33 +0200 Subject: [rfs-stage32] Improve /etc/issue banner even more :-) --- .../data/opt/openslx/scripts/openslx-create_issue | 39 ++++++++++++++++++++-- .../rootfs/rootfs-stage32/templates/issue.template | 2 +- 2 files changed, 37 insertions(+), 4 deletions(-) (limited to 'remote/rootfs/rootfs-stage32/data/opt/openslx/scripts') diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/openslx-create_issue b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/openslx-create_issue index d3086176..c70e0356 100755 --- a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/openslx-create_issue +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/openslx-create_issue @@ -25,12 +25,45 @@ declare -rg OUTFILE=/etc/issue # Replace known variables and determine maximum line length MAX=0 while IFS='' read -r line || [ -n "$line" ]; do - line="${line/"%ip%"/"$SLX_PXE_CLIENT_IP"}" - line="${line/"%hostname%"/"$SLX_HOSTNAME"}" - len=${#line} + line="${line//"%ip%"/"$SLX_PXE_CLIENT_IP"}" + line="${line//"%hostname%"/"$SLX_HOSTNAME"}" + tst="${line//"%space%"/}" + len=${#tst} [ "$len" -gt "$MAX" ] && MAX=$len echo "$line" done < "$INFILE" > "$TMPFILE" +player=$(< /etc/vmware/config grep -m1 '^product.version' | awk -F= '{print $2}') +kernel=$(uname -r) +system="$(dmidecode -s system-manufacturer | grep -vP "unknown|filled|^#") $(dmidecode -s system-product-name | grep -vP "unknown|filled|^#")" +linkspeed=$(cat /sys/class/net/eth0/speed) +tmpstatus=$(grep -m1 ' /tmp ' /proc/mounts | awk '{print $3}') +if [ -z "$tmpstatus" ] || [ "$tmpstatus" = "tmpfs" ]; then + tmpstatus="RAMDISK" +else + tmpstatus="HDD" +fi +tmpstatus="$(df -P | grep -m1 ' /tmp$' | awk '{printf "%.1f", $2 / 1024 / 1024}')GiB ($tmpstatus)" + +cat >> "$TMPFILE" <> "$TMPFILE" +fi +if [ -n "$SLX_SHUTDOWN_SCHEDULE" ]; then + echo "Scheduled shutdown: %space% $SLX_SHUTDOWN_SCHEDULE" >> "$TMPFILE" +fi +if [ -n "$SLX_REBOOT_SCHEDULE" ]; then + echo "Scheduled reboot: %space% $SLX_REBOOT_SCHEDULE" >> "$TMPFILE" +fi +if [ -n "$player" ]; then + echo "VMware version: %space% ${player//'"'/}" >> "$TMPFILE" +fi + +echo "" >> "$TMPFILE" # Fix up spacing for right-aligned text while IFS='' read -r line || [ -n "$line" ]; do diff --git a/remote/rootfs/rootfs-stage32/templates/issue.template b/remote/rootfs/rootfs-stage32/templates/issue.template index adf1f38e..6e2b449e 100644 --- a/remote/rootfs/rootfs-stage32/templates/issue.template +++ b/remote/rootfs/rootfs-stage32/templates/issue.template @@ -1,4 +1,4 @@ --- \l + @ \l WELCOME TO %space% %hostname% [%ip%] _____ ______ ______ __ __ _______ __ __ __ / _ | _ | ___| | | | | ____| | | | | | -- cgit v1.2.3-55-g7522 From 27594b6b603b8d1a10c398c21b6a0c8958b5b477 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 20 Oct 2016 15:26:36 +0200 Subject: [rfs-stage32] Check for nvidia.ko first, then for whitelisted pciids We might have a supported onboard card AND a whitelisted nvidia card. Stage 3.1 will load the nvidia kernel modules all right, but then stage 3.2 sees the whitelisted onboard card, enables "force 3d" for vmware and skips the part where it will load the nvidia user space libs, resulting in an unusable client. Check for the nvidia kernel module first and only check for a supported onboard card if none was found to prevent this situation from occuring. --- .../data/opt/openslx/scripts/systemd-load_gfx_driver | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'remote/rootfs/rootfs-stage32/data/opt/openslx/scripts') diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-load_gfx_driver b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-load_gfx_driver index 3ca2f334..e6fd32cf 100755 --- a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-load_gfx_driver +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-load_gfx_driver @@ -7,13 +7,14 @@ if ! lspci -n > "$PCIFILE"; then exit 1 fi -if grep -q -E ' (8086:0102|8086:0152|8086:0162|8086:0412|8086:0416|1002:6779)( |$)' "$PCIFILE"; then - echo "i915 - enable 3D" - echo -e "# Written by load-gfx-driver\nSLX_VMWARE_3D=yes" >> "/opt/openslx/config" -elif lsmod | grep -q '^nvidia\s'; then +if lsmod | grep -q '^nvidia\s'; then # nvidia kernel module was loaded in stage31 - download libs + echo "Proprietary nvidia kernel drivers loaded - fetch user space libs" systemctl start setup-slx-addon@nvidia_libs & echo -e "# Written by load-gfx-driver\nSLX_VMWARE_3D=yes" >> "/opt/openslx/config" +elif grep -q -E ' (8086:0102|8086:0152|8086:0162|8086:0412|8086:0416|1002:6779)( |$)' "$PCIFILE"; then + echo "i915 - enable 3D" + echo -e "# Written by load-gfx-driver\nSLX_VMWARE_3D=yes" >> "/opt/openslx/config" fi exit 0 -- cgit v1.2.3-55-g7522 From 275cac52f82ccc0977e17ca097cec6cbae410702 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 28 Oct 2016 14:21:15 +0200 Subject: [rfs-stage32] Sanitize and refactor the (very) old setup-partitions script For example, just look at the actual partition id column for values like 44 45 46, instead of anywhere in the whole damn line!!! --- .../opt/openslx/scripts/systemd-setup_partitions | 175 ++++++++++++--------- 1 file changed, 98 insertions(+), 77 deletions(-) (limited to 'remote/rootfs/rootfs-stage32/data/opt/openslx/scripts') diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions index c8e680f0..4dc84828 100755 --- a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions @@ -15,53 +15,61 @@ ############################################################################# # Mount point for persistent scratch partition (type 45) -PERSISTENT="/opt/openslx/persistent" +MOUNT_POINT_45="/opt/openslx/persistent" +PARTITION_FILE="/run/openslx/partitions" +readonly MOUNT_POINT_45 PARTITION_FILE +mkdir -p "/run/openslx" # General formatter for the /tmp partition on a local harddisk -diskfm () { - mopt="" # Global var! +format_disk () { + MOUNT_OPTIONS_SET_BY_FORMAT_DISK="" # Global var! local target="$1" local fslist="xfs jfs ext3 ext2 ext4" local fs local path [ $# -ge 2 ] && fslist="$2" for fs in $fslist ; do - unset available - case $(cat /proc/filesystems) in - *${fs}*) available=yes;; - *) modprobe "${fs}" && available=yes;; - esac - if [ -n "${available}" ]; then - unset found - if which "mkfs.$fs" ; then - found=yes - case "mkfs.$fs" in - mkfs.xfs) - fopt="-f -b size=4k -s size=4k -l size=512b" # fastest formatting possible :) - mopt="-o noexec" - ;; - mkfs.ext2) - fopt="-Fq" - mopt="-o nocheck,noexec" - ;; - mkfs.ext3|mkfs.ext4) - fopt="-Fq" - mopt="-o noexec" - ;; - mkfs.reiserfs) - fopt="-f" - mopt="-o noexec" - ;; - mkfs.jfs) - fopt="-q" - mopt="-o noexec" - ;; - esac - mkfs.$fs ${fopt} "${target}" - fi - [ -n "$found" ] && break + if grep -q "\\b${fs}\\b" "/proc/filesystems"; then + # Filesystem already supported by running kernel + : + elif modprobe "${fs}"; then + # Filesystem module could be loaded and should be supported now + : + else + # Not supported, try next one + continue + fi + if which "mkfs.$fs" ; then + case "$fs" in + xfs) + fopt="-f -b size=4k -s size=4k -l size=512b" # fastest formatting possible :) + MOUNT_OPTIONS_SET_BY_FORMAT_DISK="-o noexec" + ;; + ext2) + fopt="-Fq" + MOUNT_OPTIONS_SET_BY_FORMAT_DISK="-o nocheck,noexec" + ;; + ext3|ext4) + fopt="-Fq" + MOUNT_OPTIONS_SET_BY_FORMAT_DISK="-o noexec" + ;; + reiserfs) + fopt="-f" + MOUNT_OPTIONS_SET_BY_FORMAT_DISK="-o noexec" + ;; + jfs) + fopt="-q" + MOUNT_OPTIONS_SET_BY_FORMAT_DISK="-o noexec" + ;; + *) + fopt= + MOUNT_OPTIONS_SET_BY_FORMAT_DISK= + ;; + esac + mkfs.$fs ${fopt} "${target}" && return 0 # Success! fi done + return 1 } mount_temp () { @@ -89,33 +97,42 @@ mount_temp_fallback () { return 0 } -fdisk -l | sed -n "/^\/dev\//p" > "/etc/disk.partition" +fdisk -l | grep '^/dev/' > "$PARTITION_FILE" -if [ ! -s "/etc/disk.partition" ]; then +if [ ! -s "$PARTITION_FILE" ]; then + udevadm trigger sleep 3 - fdisk -l | sed -n "/^\/dev\//p" > "/etc/disk.partition" + udevadm settle + fdisk -l | grep '^/dev/' > "$PARTITION_FILE" fi echo "Partitions:" -cat "/etc/disk.partition" +cat "$PARTITION_FILE" + +# Get all partitions with given id (list of /dev/sdXX) +get_all_with_id () { + [ -z "$1" ] && return + local ID=$1 + awk '{if (($2 == "*" && $6 == "'$ID'") || ($2 != "*" && $5 == "'$ID'")) print $1}' "$PARTITION_FILE" # watch out for non-spaced '$ID' +} # Check for standard swap partitions and make them available to the system HAVE_SWAP=no -for hdpartnr in $(sed -n -e "/ 82 /p" "/etc/disk.partition" | sed -e "s/[[:space:]].*//"); do - echo -e "$hdpartnr\tswap\t\tswap\t\tdefaults\t 0 0" >> "/etc/fstab" - swapon "$hdpartnr" -p 10 && HAVE_SWAP=yes # low priority, in case we have zram swap, prefer that) +for PART_DEV in $(get_all_with_id 82); do + echo -e "$PART_DEV\tswap\t\tswap\t\tdefaults\t 0 0" >> "/etc/fstab" + swapon "$PART_DEV" -p 10 && HAVE_SWAP=yes # low priority, in case we have zram swap, prefer that) done # We use special non assigned partition type (id44) for harddisk scratch # space, thus no normal filesystem will be incidentally deleted or # corrupted HAVE_TEMP=no -for hdpartnr in $(sed -n -e "/ 44 /p" "/etc/disk.partition" | sed -e "s/[[:space:]].*//"); do +for PART_DEV in $(get_all_with_id 44); do # check for supported filesystem and formatter - if diskfm "$hdpartnr"; then - # echo "$hdpartnr is mounted to /mnt/tmp at $(sysup)" >/tmp/tmpready - mount_temp "$mopt" "$hdpartnr" || continue - echo -e "${hdpartnr}\t/tmp\t\tauto\t\tnoexec\t 0 0" >> "/etc/fstab" + if format_disk "$PART_DEV"; then + # echo "$PART_DEV is mounted to /mnt/tmp at $(sysup)" >/tmp/tmpready + mount_temp "$MOUNT_OPTIONS_SET_BY_FORMAT_DISK" "$PART_DEV" || continue + echo -e "${PART_DEV}\t/tmp\t\tauto\t\tnoexec\t 0 0" >> "/etc/fstab" HAVE_TEMP=yes break else @@ -123,32 +140,36 @@ for hdpartnr in $(sed -n -e "/ 44 /p" "/etc/disk.partition" | sed -e "s/[[:space fi # Made this non-forking, systemd should handle it - 2013-05-28 done -# Put detected linux partitions (83) into /etc/fstab with "noauto", special -# partition 45 (persistent scratch) to /var/scratch and 46 to /var/openslx -HAVE_PERSISTENT=no -for partid in 83 45 46 ; do - for hdpartnr in $(sed -n -e "/ ${partid} /p" "/etc/disk.partition" | sed -e "s/[[:space:]].*//"); do - if [ "${partid}" -eq 83 ]; then - mkdir -p "/media/${hdpartnr#/dev/*}" - echo -e "${hdpartnr}\t/media/${hdpartnr#/dev/*}\tauto\t\tnoauto,noexec\t 0 0" >> "/etc/fstab" - elif [ "${partid}" -eq 45 -a "$HAVE_PERSISTENT" = "no" ]; then - mkdir -p "$PERSISTENT" - if ! mount -t auto -o noexec "${hdpartnr}" "$PERSISTENT"; then - diskfm "$hdpartnr" "jfs xfs ext3" || continue - mount -t auto -o noexec "${hdpartnr}" "$PERSISTENT" || continue - fi - HAVE_PERSISTENT=yes - echo -e "${hdpartnr}\t${PERSISTENT}\tauto\t\tnoauto,noexec\t\t 0 0" >> "/etc/fstab" - elif [ "${partid}" -eq 46 ]; then - mkdir -p "/media/${hdpartnr#/dev/*}" - #mount -t auto ${hdpartnr} /mnt/media/${hdpartnr#/dev/*} \n\ - #test -d /mnt/media/${hdpartnr#/dev/*}/home && \ - # ln -sf /media/${hdpartnr#/dev/*} /var/home - echo -e "${hdpartnr}\t/media/${hdpartnr#/dev/*}\tauto\t\tnoauto\t\t 0 0" >> "/etc/fstab" - fi - done +# Put detected linux partitions (83) into /etc/fstab with "noauto" +HAVE_PARTITION_45=no +for PART_DEV in $(get_all_with_id 83); do + mkdir -p "/media/${PART_DEV#/dev/*}" + echo -e "${PART_DEV}\t/media/${PART_DEV#/dev/*}\tauto\t\tnoauto,noexec\t 0 0" >> "/etc/fstab" done -[ "$HAVE_PERSISTENT" = "no" -a -d "$PERSISTENT" ] && rm -f "$PERSISTENT" + +# special partition 45 (persistent scratch) to $MOUNT_POINT_45 +for PART_DEV in $(get_all_with_id 45); do + mkdir -p "$MOUNT_POINT_45" + if ! mount -t auto -o noexec "${PART_DEV}" "$MOUNT_POINT_45"; then + format_disk "$PART_DEV" "ext4 xfs jfs ext3" || continue + mount -t auto -o noexec "${PART_DEV}" "$MOUNT_POINT_45" || continue + fi + echo -e "${PART_DEV}\t${MOUNT_POINT_45}\tauto\t\tnoauto,noexec\t\t 0 0" >> "/etc/fstab" + HAVE_PARTITION_45=yes + break +done + +# and 46 to /media/devXX +for PART_DEV in $(get_all_with_id 46); do + mkdir -p "/media/${PART_DEV#/dev/*}" + #mount -t auto ${PART_DEV} /mnt/media/${PART_DEV#/dev/*} \n\ + #test -d /mnt/media/${PART_DEV#/dev/*}/home && \ + # ln -sf /media/${PART_DEV#/dev/*} /var/home + echo -e "${PART_DEV}\t/media/${PART_DEV#/dev/*}\tauto\t\tnoauto\t\t 0 0" >> "/etc/fstab" +done +if [ "$HAVE_PARTITION_45" = "no" ] && [ -d "$MOUNT_POINT_45" ]; then + rm -f -- "$MOUNT_POINT_45" +fi mount -a @@ -158,13 +179,13 @@ mount -a # much free space as the VMs RAM; however, this requirement can be disabled with a vmx setting, # which we're now doing. if [ "$HAVE_TEMP" = "no" ]; then - mount_temp -t tmpfs -o size=66% none - slxlog "partition-temp" "Running /tmp on tmpfs only!" "/etc/disk.partition" + mount_temp -t tmpfs -o size=66% none + slxlog "partition-temp" "Running /tmp on tmpfs only!" "$PARTITION_FILE" fi if [ "$HAVE_SWAP" = "no" ]; then TOTAL_RAM=$(grep ^MemTotal /proc/meminfo | awk '{print $2}') if [ -n "$TOTAL_RAM" ] && [ "$TOTAL_RAM" -lt "3000000" ]; then - slxlog "partition-swap" "Have no (formatted) swap partition, using zram swap only!" "/etc/disk.partition" + slxlog "partition-swap" "Have no (formatted) swap partition, using zram swap only!" "$PARTITION_FILE" fi fi -- cgit v1.2.3-55-g7522