summaryrefslogtreecommitdiffstats
path: root/core/rootfs
diff options
context:
space:
mode:
authorSimon Rettberg2021-07-22 10:48:06 +0200
committerSimon Rettberg2021-07-22 10:48:06 +0200
commiteeda5aaff24e0f1ac7be43e9b6c180c77aae0bad (patch)
treece3b7e087ecbe9d81a28262793db2a5d8f0fe8b1 /core/rootfs
parent[system-uuid] Add two more bad UUIDs (diff)
downloadmltk-eeda5aaff24e0f1ac7be43e9b6c180c77aae0bad.tar.gz
mltk-eeda5aaff24e0f1ac7be43e9b6c180c77aae0bad.tar.xz
mltk-eeda5aaff24e0f1ac7be43e9b6c180c77aae0bad.zip
[disk-partitions] New module, modularize partition setup
Diffstat (limited to 'core/rootfs')
-rw-r--r--core/rootfs/rootfs-stage32/data/etc/systemd/system/mount-stage4.service11
-rw-r--r--core/rootfs/rootfs-stage32/data/etc/systemd/system/setup-temp.service (renamed from core/rootfs/rootfs-stage32/data/etc/systemd/system/setup-partitions.service)4
l---------core/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/setup-partitions.service1
l---------core/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/setup-temp.service1
-rw-r--r--core/rootfs/rootfs-stage32/data/etc/systemd/system/tmp.target5
-rwxr-xr-xcore/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-mount_stage470
-rwxr-xr-xcore/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions327
-rw-r--r--core/rootfs/rootfs-stage32/module.conf1
8 files changed, 4 insertions, 416 deletions
diff --git a/core/rootfs/rootfs-stage32/data/etc/systemd/system/mount-stage4.service b/core/rootfs/rootfs-stage32/data/etc/systemd/system/mount-stage4.service
deleted file mode 100644
index 7f8b54a8..00000000
--- a/core/rootfs/rootfs-stage32/data/etc/systemd/system/mount-stage4.service
+++ /dev/null
@@ -1,11 +0,0 @@
-[Unit]
-Description=Mount Openslx Stage 4
-DefaultDependencies=no
-Wants=setup-dnbd3.service stage4.target
-After=setup-dnbd3.service
-Before=stage4.target
-
-[Service]
-Type=oneshot
-RemainAfterExit=yes
-ExecStart=/opt/openslx/scripts/systemd-mount_stage4
diff --git a/core/rootfs/rootfs-stage32/data/etc/systemd/system/setup-partitions.service b/core/rootfs/rootfs-stage32/data/etc/systemd/system/setup-temp.service
index e6095302..36bd9c2a 100644
--- a/core/rootfs/rootfs-stage32/data/etc/systemd/system/setup-partitions.service
+++ b/core/rootfs/rootfs-stage32/data/etc/systemd/system/setup-temp.service
@@ -1,5 +1,5 @@
[Unit]
-Description=Setup local disk partitions (tmp, swap)
+Description=Setup ID 44 /tmp
DefaultDependencies=no
Before=basic.target tmp.target
After=systemd-udev-settle.service systemd-udevd.service
@@ -7,5 +7,5 @@ Wants=tmp.target systemd-udevd.service
[Service]
Type=oneshot
-ExecStart=/opt/openslx/scripts/systemd-setup_partitions
+ExecStart=/opt/openslx/scripts/systemd-setup_partitions --tmp
RemainAfterExit=yes
diff --git a/core/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/setup-partitions.service b/core/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/setup-partitions.service
deleted file mode 120000
index af2957f8..00000000
--- a/core/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/setup-partitions.service
+++ /dev/null
@@ -1 +0,0 @@
-../setup-partitions.service \ No newline at end of file
diff --git a/core/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/setup-temp.service b/core/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/setup-temp.service
new file mode 120000
index 00000000..f7f080b5
--- /dev/null
+++ b/core/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/setup-temp.service
@@ -0,0 +1 @@
+../setup-temp.service \ No newline at end of file
diff --git a/core/rootfs/rootfs-stage32/data/etc/systemd/system/tmp.target b/core/rootfs/rootfs-stage32/data/etc/systemd/system/tmp.target
deleted file mode 100644
index a8c3eab2..00000000
--- a/core/rootfs/rootfs-stage32/data/etc/systemd/system/tmp.target
+++ /dev/null
@@ -1,5 +0,0 @@
-[Unit]
-Description=/tmp has been mounted
-Wants=setup-partitions.service
-After=setup-partitions.service
-
diff --git a/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-mount_stage4 b/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-mount_stage4
deleted file mode 100755
index 201e7a26..00000000
--- a/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-mount_stage4
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/bin/bash
-# Needs full bash
-
-. /opt/openslx/config
-
-[ -z "${SLX_STAGE4}" ] && { echo "SLX_STAGE4 is not set in /opt/openslx/config." && exit 1; }
-
-MOUNTPOINT="/opt/openslx/mnt/stage4"
-mkdir -p "$MOUNTPOINT"
-
-if [[ "$SLX_STAGE4" == dnbd3* ]]; then
- # dnbd3 it is
- if [ -z "${SLX_DNBD3_SERVERS}${SLX_DNBD3_PRIO_SERVERS}" ]; then
- slxlog --echo "mount-stage4" "dnbd3 stage4 configured, but SLX_DNBD3(_PRIO)_SERVERS empty or not set in /opt/openslx/config."
- exit 1
- fi
- # Determine revision
- if [ -z "$SLX_STAGE4_RID" ] || echo "$SLX_STAGE4_RID" | grep -v -q -E "^[0-9]+$"; then
- SLX_STAGE4_RID="0"
- fi
- # Randomize list
- SERVERS=$(for SERVER in $SLX_DNBD3_SERVERS; do echo "$RANDOM $SERVER"; done | sort -u | sed -r 's/^[0-9]+ //')
- IMAGE=$(echo $SLX_STAGE4 | awk '{printf $2}')
- [ -e /var/run/dnbd3.socket ] || sleep 2 # Ugly, service should only start when dnbd3 daemon is up and running
- RET=1337
- for SRV in $SLX_DNBD3_PRIO_SERVERS $SERVERS; do
- echo "Requesting $IMAGE from $SRV"
- dnbd3=$(dnbd3-client -h "$SRV" -i "$IMAGE" -r "$SLX_STAGE4_RID")
- RET=$?
- [ "$RET" -eq "0" ] && break
- echo "... didn't work ($RET)"
- sleep 1
- done
- if [ "$RET" -ne "0" ]; then
- slxlog --echo "mount-stage4" "Could not get stage4 via dnbd3 ($IMAGE : $SLX_STAGE4_RID) ($SLX_DNBD3_PRIO_SERVERS / $SERVERS)"
- exit $RET
- fi
- echo "Mounting $dnbd3 to $MOUNTPOINT"
- if ! mount -t squashfs -o ro "$dnbd3" "$MOUNTPOINT"; then
- slxlog --echo "mount-stage4" "Could not mount stage4 from '$dnbd3' to '$MOUNTPOINT' ($SRV, $IMAGE)"
- exit 1
- fi
-else
- # Try nfs
- echo "Mounting ${SLX_STAGE4} to $MOUNTPOINT"
- if ! mount -t nfs -o ro,async,nolock,vers=3 "$SLX_STAGE4" "$MOUNTPOINT"; then
- slxlog --echo "mount-stage4" "Could not mount stage4 from '$SLX_STAGE4' to '$MOUNTPOINT'"
- exit 1
- fi
-fi
-
-echo "Appending $MOUNTPOINT to /"
-if mount -o "remount,append:$MOUNTPOINT=ro" /; then
-
- # addons can trigger ldconfig, hence
- # make sure no ldconfig is running before copying the real ld cache
- while ps aux|grep -v grep|grep -q ldconfig; do
- sleep 1
- done
- cp -r "${MOUNTPOINT}/"etc/ld.* /etc/ || echo "Could not really copy full blown ldconfig from stage4 to live system"
-else
- slxlog --echo "mount-stage4" "Could not append mounted stage4 at '$MOUNTPOINT' to aufs at /"
- exit 1
-fi
-
-# dbus reload needed eg. for gnome etc. and perhaps other service files which stage4 needs:
-systemctl reload dbus.service
-
-exit 0
-
diff --git a/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions b/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions
deleted file mode 100755
index 62242373..00000000
--- a/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions
+++ /dev/null
@@ -1,327 +0,0 @@
-#!/bin/bash
-# Arrays etc and $(( )) with big numbers
-# -----------------------------------------------------------------------------
-#
-# Copyright (c) 2018 bwLehrpool-Projektteam
-#
-# This program/file is free software distributed under the GPL version 2.
-# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
-#
-# If you have any feedback please consult https://bwlehrpool.de and
-# send your feedback to support@bwlehrpool.de.
-#
-# General information about bwLehrpool can be found at https://bwlehrpool.de
-#
-# -----------------------------------------------------------------------------
-#
-# Local hard disk autodetection script for OpenSLX linux stateless clients,
-# detecting swap and special partitions
-
-#############################################################################
-
-# Mount point for persistent scratch partition (type 45)
-MOUNT_POINT_45="/opt/openslx/persistent"
-PARTITION_FILE="/run/openslx/partitions"
-readonly MOUNT_POINT_45 PARTITION_FILE
-mkdir -p "/run/openslx"
-
-. /opt/openslx/config
-. /opt/openslx/bin/slx-tools
-
-declare -a TMPFILES
-gettmp () {
- local vn file
- for vn in "$@"; do
- file=$(mktemp -p /run/openslx) # since we fiddle around with /tmp in this script
- declare -g "${vn}=${file}"
- TMPFILES+=("$file")
- done
-}
-delalltmp () {
- rm -f -- "${TMPFILES[@]}"
-}
-trap delalltmp EXIT
-
-# get_mount_options <fstype> <varname>
-get_mount_options () {
- case "$1" in
- ext2)
- declare -ag "${2}=(-o nocheck)"
- ;;
- ext4)
- declare -ag "${2}=(-o 'errors=remount-ro,data=ordered,relatime,quota')"
- ;;
- *)
- declare -ag "${2}=()"
- esac
-}
-
-# General formatter for the /tmp partition on a local harddisk
-format_disk () {
- declare -ag MOUNT_OPTIONS_SET_BY_FORMAT_DISK=() # Global var!
- local target="$1"
- local fslist="xfs jfs ext3 ext2 ext4"
- local fs
- declare -a fopt
- [ $# -ge 2 ] && fslist="$2"
- for fs in $fslist ; do
- 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
- reiserfs)
- fopt=("-f")
- ;;
- xfs)
- fopt=("-f" "-K")
- ;;
- ext2|ext3)
- fopt=("-F")
- ;;
- ext4)
- fopt=(-F -b 4096 -O "extent,huge_file,flex_bg,metadata_csum,64bit,dir_nlink,extra_isize,quota" -E "nodiscard,quotatype=usrquota:prjquota" -I 256)
- ;;
- jfs)
- fopt=()
- ;;
- *)
- fopt=()
- ;;
- esac
- get_mount_options "$fs" MOUNT_OPTIONS_SET_BY_FORMAT_DISK
- "mkfs.$fs" "${fopt[@]}" "${target}" && return 0 # Success!
- fi
- done
- return 1
-}
-
-mount_temp () {
- local PRE=$(pwd)
- if ! cd /tmp; then
- mount_temp_fallback "$@"
- return $?
- fi
- mount "$@" /tmp || return 1
- chmod a+rwxt /tmp
- # Move stuff from working directory, which is old /tmp, to new /tmp just mounted
- mv ./* ./.[!.]* ./..?* /tmp/ 2> /dev/null
- local OLD=$(LANG=C ls -alh | grep -v -E ' \.\.?$' | grep -v '^total')
- [ -n "$OLD" ] && echo -- "Leftovers:" && echo -- "$OLD"
- cd "$PRE" || true
-}
-
-mount_temp_fallback () {
- mkdir -p /tmptmp
- mv /tmp/* /tmp/.* /tmptmp/ 2> /dev/null
- mount "$@" /tmp || return 1
- chmod a+rwxt /tmp
- mv /tmptmp/* /tmptmp/.* /tmp/
- rmdir /tmptmp
- return 0
-}
-
-wait_for_udev () {
- local upid ctr hdd
- hdd=
- if [ "x$1" = "x--hdd" ]; then
- hdd=true
- shift
- fi
- ctr=$(( "$1" * 10 ))
- if ! [ "$ctr" -gt 0 ]; then # Negation to catch NaN
- ctr=1
- fi
- udevadm trigger &
- usleep 20000 # 20ms
- udevadm settle &> /dev/null & # --timeout doesn't work reliably, sometimes the process just hangs
- upid=$!
- while [ "$ctr" -gt 0 ]; do
- [ -n "$hdd" ] && has_hdd && break
- [ -z "$hdd" ] && ! [ -d "/proc/$upid" ] && break
- usleep 100000 # 100ms
- ctr=$(( ctr - 1 ))
- done
- if [ -d "/proc/$upid" ]; then
- kill -9 "$upid" &> /dev/null &
- fi
-}
-
-has_hdd () {
- [ -n "$( ls -U -1 /dev/disk/by-path/ )" ]
-}
-
-wait_for_udev 2
-
-if ! has_hdd; then
- wait_for_udev --hdd 4
-fi
-
-shopt -s extglob
-for disk in /dev/disk/by-path/!(*-part*|*-usb-*); do
- [ -L "$disk" ] || continue
- fdisk -l "$( readlink -f "$disk" )"
-done > "$PARTITION_FILE"
-shopt -u extglob
-if ! [ -s "$PARTITION_FILE" ]; then
- echo "none" > "$PARTITION_FILE"
-fi
-echo "Partitions:"
-cat "$PARTITION_FILE"
-
-# Check for standard swap partitions and make them available to the system
-HAVE_SWAP=no
-for PART_DEV in $(dev_find_partitions "82" "0657fd6d-a4ab-43c4-84e5-0933c84b4f4f"); do
- if swapon "$PART_DEV" -p 10; then
- HAVE_SWAP=yes # low priority, in case we have zram swap, prefer that)
- echo -e "$PART_DEV\tswap\t\tswap\t\tdefaults\t 0 0" >> "/etc/fstab"
- fi
-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 PART_DEV in $(dev_find_partitions "44" "87f86132-ff94-4987-b250-444444444444"); do
- # check for supported filesystem and formatter
- if format_disk "$PART_DEV"; then
- 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
- echo "formatting failed for some reason"
- fi # Made this non-forking, systemd should handle it - 2013-05-28
-done
-
-# Put detected linux partitions (83) into /etc/fstab with "noauto"
-for PART_DEV in $(dev_find_partitions 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
-
-# special partition 45 (persistent scratch) to $MOUNT_POINT_45
-HAVE_PARTITION_45=no
-get_mount_options "ext4" mopts
-# try all the ID45 partitions until one succeeds, from large to small
-for PART_DEV in $(dev_find_partitions "45" "87f86132-ff94-4987-b250-454545454545"); do
- mkdir -p "$MOUNT_POINT_45"
- # Let's see if this is an ext4 partition and if so, whether it has the proper size
- # Any fixing should happen first
- gettmp "logfile"
- COUNT=0
- while true; do
- [ "$COUNT" -ge 4 ] && break
- let COUNT++
- fsck.ext4 -y "$PART_DEV" &> "$logfile"
- RET=$?
- if [ "$(( RET & 7 ))" = 4 ]; then
- slxlog "partition-45-fsck" "Error fixing file system errors on ID45 partition" "$logfile"
- break
- fi
- [ "$(( RET & 3 ))" != 1 ] && break
- done
- # awk script to take block count and block size from dumpe2fs output and multiply them to get byte size
- fs_size=$(dumpe2fs -h "$PART_DEV" | awk -F: 'BEGIN{a=0;b=0}{if ($1 == "Block count") a=$2; if($1 == "Block size") b=$2;}END{ if (a>0 && b>0) print a*b}')
- echo "$PART_DEV has ext4 fs of size $fs_size"
- if [ -n "$fs_size" ] && [ "$fs_size" -gt 1000000 ]; then
- # It's ext4, see if partition size was changed offline
- dev_size=$(blockdev --getsize64 "$PART_DEV")
- echo "$PART_DEV has actual size of $dev_size"
- if [ -n "$dev_size" ] && [ "$dev_size" -gt 1000000 ]; then
- # somewhat sane, see what to do
- dev_mb=$(( dev_size / 1024 / 1024 ))
- fs_mb=$(( fs_size / 1024 / 1024 ))
- echo "Dev: $dev_mb, fs: $fs_mb"
- if [ "$(( fs_mb + 100 ))" -lt "$dev_mb" ]; then
- # dev size plus 100MB is still smaller than reported fs size -- resize fs
- gettmp "logfile"
- fsck.ext4 -f -y "$PART_DEV" &> "$logfile"
- if resize2fs "$PART_DEV" &>> "$logfile"; then
- slxlog "partition-45-resize-ok" "Resized partition $PART_DEV from $fs_mb MiB to $dev_mb MiB" "$logfile"
- else
- slxlog "partition-45-resize-fail" "Could not enlarge file system size of $PART_DEV from $fs_mb MiB to $dev_mb MiB" "$logfile"
- dd if=/dev/zero of="$PART_DEV" bs=1M count=1 &>/dev/null
- fi
- elif [ "$dev_size" -lt "$fs_size" ]; then
- # partition is smaller than expected by fs -- killall
- slxlog "partition-45-shrink" "$PART_DEV has ext4 file system which is $fs_mb MiB, but partition size is only $dev_mb MiB. Will wipe partition to be safe..."
- dd if=/dev/zero of="$PART_DEV" bs=1M count=1 &>/dev/null
- fi
- fi
- fi
- # try to mount
- if ! mount -v -t ext4 "${mopts[@]}" "${PART_DEV}" "$MOUNT_POINT_45"; then
- # failed, try to format
- gettmp "logfile"
- if ! format_disk "$PART_DEV" "ext4" &> "$logfile"; then
- slxlog "partition-45-format" "Cannot format $PART_DEV with ext4" "$logfile"
- continue
- fi
- gettmp "logfile"
- if ! mount -v -t ext4 "${mopts[@]}" "${PART_DEV}" "$MOUNT_POINT_45" &> "$logfile"; then
- slxlog "partition-45-newmount" "Cannot mount $PART_DEV with ext4 right after formatting" "$logfile"
- continue
- fi
- fi
- # Mount success -- clean up lost+found
- find "${MOUNT_POINT_45}/slx_lost+found" -mindepth 1 -maxdepth 1 -mtime +90 -type d -exec rm -rf -- {} \;
- if [ -d "${MOUNT_POINT_45}/lost+found" ]; then
- touch "${MOUNT_POINT_45}/lost+found"
- mkdir -p "${MOUNT_POINT_45}/slx_lost+found"
- mv -f -- "${MOUNT_POINT_45}/lost+found" "${MOUNT_POINT_45}/slx_lost+found/$(date +%s)_$$-$RANDOM"
- fi
- chmod 0700 "${MOUNT_POINT_45}/slx_lost+found"
- chown 0:0 "${MOUNT_POINT_45}/slx_lost+found"
- # fstab entry
- echo -e "${PART_DEV}\t${MOUNT_POINT_45}\tauto\t\tnoauto\t\t 0 0" >> "/etc/fstab"
- HAVE_PARTITION_45=yes
- break # success, done
-done
-
-# and 46 to /media/devXX
-for PART_DEV in $(dev_find_partitions "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
-
-# finally, prepare the data subdir on persistent part
-if [ "$HAVE_PARTITION_45" = "yes" ]; then
- mkdir -p "$MOUNT_POINT_45/data"
- chown root:root "$MOUNT_POINT_45" "$MOUNT_POINT_45/data"
- chmod a+rwxt "$MOUNT_POINT_45/data"
-elif [ -d "$MOUNT_POINT_45" ]; then
- rm -f -- "$MOUNT_POINT_45"
-fi
-
-mount -a
-
-# 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=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!" "$PARTITION_FILE"
- fi
-fi
-
-[ -n "$SLX_SPLASH" ] && splashtool --icon "/opt/openslx/icons/active/??-hdd.ppm"
-exit 0
-
diff --git a/core/rootfs/rootfs-stage32/module.conf b/core/rootfs/rootfs-stage32/module.conf
index f875a1eb..86090dc2 100644
--- a/core/rootfs/rootfs-stage32/module.conf
+++ b/core/rootfs/rootfs-stage32/module.conf
@@ -3,6 +3,7 @@ REQUIRED_MODULES="
kernel
vmware-version-check
slxlog
+ disk-partitions
"
REQUIRED_BINARIES="
bash