summaryrefslogtreecommitdiffstats
path: root/core/modules/gdisk/data/inc/prepare_localhd.functions
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/gdisk/data/inc/prepare_localhd.functions')
-rwxr-xr-xcore/modules/gdisk/data/inc/prepare_localhd.functions163
1 files changed, 163 insertions, 0 deletions
diff --git a/core/modules/gdisk/data/inc/prepare_localhd.functions b/core/modules/gdisk/data/inc/prepare_localhd.functions
new file mode 100755
index 00000000..45075ab0
--- /dev/null
+++ b/core/modules/gdisk/data/inc/prepare_localhd.functions
@@ -0,0 +1,163 @@
+#!/bin/ash
+# Copyright (c) 2014 - 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 special GPT partitions
+
+#############################################################################
+
+# Patition IDs
+# Prefix for all paritions is 0FC63DAF-8483-4772-8E79-9999999999
+# Suffix:
+# 44: non-persistent scratch partition
+# 45: persistent partiton
+# 46: non-persistent openslx partition for config, overlayfs and qcow images
+
+# We use special non assigned partition type for harddisk scratch
+# space, thus no normal filesystem will be incidentally deleted or
+# corrupted
+
+# Set disks to none
+ID44=
+ID45=
+ID46=
+
+# General formatter for the /tmp partition on a local harddisk
+diskfm () {
+ mopt="" # Global var!
+ local target="$1"
+ local fslist="xfs jfs 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" >/dev/null; then
+ found=yes
+ case "mkfs.$fs" in
+ mkfs.xfs)
+ fopt="-fq"
+ ;;
+ mkfs.jfs)
+ fopt="-q"
+ ;;
+ mkfs.ext4)
+ fopt="-Fq"
+ ;;
+ esac
+ mkfs.$fs ${fopt} "${target}"
+ fi
+ [ -n "$found" ] && break
+ fi
+ done
+}
+
+# function format_pid ()
+# Formats partition with id 44, 45, 46
+# expects id as parameter
+# usage: format_pid [44|45|46]
+format_pid () {
+ local fmtpid=$1
+ local target
+ case $fmtpid in
+ 44)
+ target=$ID44
+ ;;
+ 45)
+ target=$ID45
+ ;;
+ 46)
+ target=$ID46
+ ;;
+ esac
+ if echo $target | grep -q '/dev/disk/'
+ then
+ # check for supported filesystem and formatter
+ diskfm $target
+ else
+ echo "Could not format partition ID $fmtpid"
+ fi
+}
+
+# function mount_pid ()
+# Mounts partition with id 44, 45, 46
+# expects id and mountpoint as parameter
+# usage: mount_pid [44|45|46] $MNT
+mount_pid () {
+ local mntpid=$1
+ local target=$2
+ local source
+ if [ "x$2" = "x" ]
+ then
+ echo "No mountpoint specified dummy!"
+ else
+ case $mntpid in
+ 44)
+ source=$ID44
+ ;;
+ 45)
+ source=$ID45
+ ;;
+ 46)
+ source=$ID46
+ ;;
+ esac
+ mkdir -p $target
+ if busybox mount -t auto "$source" "$target"
+ then
+ [ "x$mntpid}" = "x44" ] && chmod a+rwxt $target
+ if echo "$target" | grep -Eq "^mnt/|^/mnt/"
+ then
+ fstabtarget=$(echo $target | sed -re "s/[/]{0,1}mnt//")
+ echo -e "$source\t$fstabtarget\tauto\tnoexec\t0 0" \
+ >>/mnt/etc/fstab
+ fi
+ else
+ echo "Could not mount partition ID $mntpid"
+ fi
+ fi
+}
+
+# Get partition types
+hdisks=$(ls /dev/disk/by-path/*-part[0-9]* \
+ | sed -re "s,(.*)-part[0-9]*,\1," \
+ | sort -u)
+
+if echo $hdisks | grep -q '/dev/disk/'
+ then
+ for hd in $(echo $hdisks)
+ do
+ upartid=$(sgdisk -p $hd 2>/dev/null | awk '$6~/FFFF/ {print $1}')
+ for upt in $(echo $upartid)
+ do
+ echo "${hd}-part${upt} $(sgdisk -i $upt $hd)" \
+ | awk '$5 ~ /0FC63DAF-8483-4772-8E79-[0]{10}4[4-6]/ \
+ {print $5 "=" $1}' \
+ | sed -re "s,0FC63DAF-8483-4772-8E79-[0]{10},ID," \
+ >> /etc/hdisks.conf
+ done
+ done
+ if [ -r /etc/hdisks.conf ]
+ then
+ . /etc/hdisks.conf
+ echo -e "Partitions found:\n$(cat /etc/hdisks.conf | cut -d'=' -f1)"
+ else
+ echo "No pratition IDs 44, 45 or 46 found"
+ fi
+
+fi
+