diff options
5 files changed, 83 insertions, 34 deletions
diff --git a/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx b/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx index 93287af8..546750b9 100755 --- a/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx +++ b/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx @@ -20,12 +20,12 @@ . /opt/openslx/config RESOLV_CONF="/etc/resolv.conf" -THIS_RESOLV="/run/udhcpc/${interface}.resolv" +THIS_RESOLV="/run/dhcpc/${interface}.resolv" rebuild_resolv_conf () { # Maybe make this smarter some time, if anyone is using client's that are on multiple networks at once etc... # This is a little braindead but should work most of the time - sort -u /run/udhcpc/*.resolv > "$RESOLV_CONF" 2> /dev/null + sort -u /run/dhcpc/*.resolv > "$RESOLV_CONF" 2> /dev/null } escape_search() { @@ -58,7 +58,7 @@ fi case "$1" in bound|renew) check_env "$1" - mkdir -p "/run/udhcpc" + mkdir -p "/run/dhcpc" # Set address on interface ip addr add "$ip/$(ipcalc -s -p $ip $subnet|sed s/.*=//)" dev "$interface" # Set default route, if given @@ -96,7 +96,7 @@ case "$1" in sed -i "s/^\(SLX_PXE_CLIENT_IP=\).*$/\1'$ip'/" /opt/openslx/config # Only if network is not ready yet - if [ ! -e "/run/udhcpc/network-ready" ]; then + if [ ! -e "/run/dhcpc/network-ready" ]; then # Update hostname if [ -z "$dns_host" ]; then # fallback to what the dhcp told us @@ -130,7 +130,7 @@ case "$1" in fi # Update /etc/issue for proper spacing /opt/openslx/scripts/openslx-create_issue - touch "/run/udhcpc/network-ready" + touch "/run/dhcpc/network-ready" # Mark network target as reached systemctl start network.target & fi # end "network not ready yet" @@ -158,16 +158,16 @@ case "$1" in sed -i -r '/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s*$/d' /etc/hosts # "dns ready" target - if [ -n "$dns" ] && [ ! -e "/run/udhcpc/dns-ready" ]; then - touch "/run/udhcpc/dns-ready" + if [ -n "$dns" ] && [ ! -e "/run/dhcpc/dns-ready" ]; then + touch "/run/dhcpc/dns-ready" # Write to openslx-config echo "# Config written by openslx-dhcp-script (2)" >> /opt/openslx/config echo "SLX_DNS='$dns'" >> /opt/openslx/config systemctl start network-dns.target & fi # "default route exists" target - if [ -n "$router" ] && [ ! -e "/run/udhcpc/routing-ready" ]; then - touch "/run/udhcpc/routing-ready" + if [ -n "$router" ] && [ ! -e "/run/dhcpc/routing-ready" ]; then + touch "/run/dhcpc/routing-ready" # Write to openslx-config echo "# Config written by openslx-dhcp-script (3)" >> /opt/openslx/config echo "SLX_DNS='$dns'" >> /opt/openslx/config diff --git a/remote/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/zram-swap.service b/remote/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/zram-swap.service new file mode 120000 index 00000000..c1754b11 --- /dev/null +++ b/remote/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/zram-swap.service @@ -0,0 +1 @@ +../zram-swap.service
\ No newline at end of file diff --git a/remote/rootfs/rootfs-stage32/data/etc/systemd/system/zram-swap.service b/remote/rootfs/rootfs-stage32/data/etc/systemd/system/zram-swap.service new file mode 100644 index 00000000..a458b380 --- /dev/null +++ b/remote/rootfs/rootfs-stage32/data/etc/systemd/system/zram-swap.service @@ -0,0 +1,10 @@ +[Unit] +Description=Setup zram swap partitions +DefaultDependencies=no +Wants=swap.target +Before=swap.target + +[Service] +Type=oneshot +ExecStart=/opt/openslx/scripts/systemd-zram_swap +RemainAfterExit=yes 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 362e8f14..ca7317d4 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 @@ -37,7 +37,7 @@ diskfm () { found=yes case "mkfs.$fs" in mkfs.xfs) - fopt="-f" + fopt="-f -b size=4k -s size=4k -l size=512b" # fastest formatting possible :) mopt="-o noexec" ;; mkfs.ext2) @@ -109,7 +109,7 @@ cat "/etc/disk.partition" 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 + swapon "$hdpartnr" -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 @@ -167,27 +167,5 @@ if [ "$HAVE_SWAP" = "no" ]; then slxlog "partition-swap" "Have no (formatted) swap partition, using zram swap only!" "/etc/disk.partition" fi -# Add zram swap -[ "$(uname -r)" == "3.8.13.8-openslx" ] && exit 0 -CPUS=$(grep -c -E "^processor.*[0-9]+$" /proc/cpuinfo) -if [ -z "$CPUS" ]; then - echo "ERROR: Could not determine CPU core count" -else - [ "$CPUS" -gt "16" ] && CPUS=16 # zram can only handle up to 32 devices, the system can apparently even just handle 29 swap partitions, so use a reasonable upper limit - if ! modprobe zram "num_devices=$CPUS"; then - echo "ERROR: Could not load zram module" - else - TOTAL=$(grep ^MemTotal /proc/meminfo | awk '{print $2}') - USE=$(( $TOTAL / ( 2 * $CPUS ) )) - echo "Have $CPUS cores, $TOTAL kb mem, use $USE kb zram swap per core" - USE=$(( $USE * 1024 )) - DEV=0 - while [ "$DEV" -lt "$CPUS" ]; do - echo "$USE" > "/sys/block/zram${DEV}/disksize" - mkswap "/dev/zram${DEV}" - swapon "/dev/zram${DEV}" -p 1000 - DEV=$(( $DEV + 1 )) - done - fi -fi +exit 0 diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-zram_swap b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-zram_swap new file mode 100755 index 00000000..f8bd5682 --- /dev/null +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-zram_swap @@ -0,0 +1,60 @@ +#!/bin/ash +# Copyright (c) 2013 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your feedback to feedback@openslx.org +# +# General information about OpenSLX can be found under http://openslx.org +# +# Local hard disk autodetection script for OpenSLX linux stateless clients, +# detecting swap and special partitions + +############################################################################# + + +# Add zram swap +# Some older ubuntu kernels had a problem here, see https://bugs.launchpad.net/ubuntu/+source/linux-lts-raring/+bug/1217189 +# So make sure you're up to date + +make_swap () { + [ $# -ne 2 ] && echo "make_swap: Wrong parameter count $#" && exit 1 + local USE="$1" + local DEV="$2" + echo "$USE" > "/sys/block/zram${DEV}/disksize" + mkswap "/dev/zram${DEV}" + swapon "/dev/zram${DEV}" -p 1000 # high priority (in case we have hdd swap 0x82, prefer zram) +} + +CPUS=$(grep -c -E "^processor.*[0-9]+$" "/proc/cpuinfo") +if [ -z "$CPUS" ]; then + echo "ERROR: Could not determine CPU core count" + exit 1 +fi + +[ "$CPUS" -gt "16" ] && CPUS=16 # zram can only handle up to 32 devices, the system can apparently even just handle 29 swap partitions, so use a reasonable upper limit +if ! modprobe zram "num_devices=$CPUS"; then + echo "ERROR: Could not load zram module" + exit 1 +fi + +TOTAL=$(grep ^MemTotal /proc/meminfo | awk '{print $2}') +USE=$(( $TOTAL / ( 2 * $CPUS ) )) +echo "Have $CPUS cores, $TOTAL kb mem, use $USE kb zram swap per core" +USE=$(( $USE * 1024 )) +DEV=0 +while [ "$DEV" -lt "$CPUS" ]; do + make_swap "$USE" "$DEV" & + LAST=$! + DEV=$(( $DEV + 1 )) +done + +# Wait, so we don't trigger swap.target too early +while kill -0 "$LAST"; do + usleep 100000 +done + +exit 0 + |