summaryrefslogtreecommitdiffstats
path: root/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions
diff options
context:
space:
mode:
Diffstat (limited to 'remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions')
-rwxr-xr-xremote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions185
1 files changed, 128 insertions, 57 deletions
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 f9640589..8fc7535c 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
@@ -14,8 +14,8 @@
#############################################################################
-# Mount point for persistent scratch partition (type 45)
-PERSISTENT="/opt/openslx/persistent"
+# read global OpenSLX config
+. /opt/openslx/config || { echo "Could not source config!"; exit 23; }
# General formatter for the /tmp partition on a local harddisk
diskfm () {
@@ -57,7 +57,8 @@ diskfm () {
mopt="-o noexec"
;;
esac
- mkfs.$fs ${fopt} "${target}"
+ echo "formatting ${target} with $fs..."
+ mkfs.$fs ${fopt} "${target}" > /dev/null 2>&1
fi
[ -n "$found" ] && break
fi
@@ -73,7 +74,7 @@ mount_temp () {
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
+ mv ./* ./.[!.]* ./..?* /tmp/ > /dev/null 2>&1
local OLD=$(LANG=C ls -alh | grep -v -E ' \.\.?$' | grep -v '^total')
[ -n "$OLD" ] && echo -- "Leftovers:" && echo -- "$OLD"
cd "$PRE"
@@ -81,7 +82,7 @@ mount_temp () {
mount_temp_fallback () {
mkdir -p /tmptmp
- mv /tmp/* /tmp/.* /tmptmp/ 2> /dev/null
+ mv /tmp/* /tmp/.* /tmptmp/ > /dev/null 2>&1
mount $@ /tmp || return 1
chmod a+rwxt /tmp
mv /tmptmp/* /tmptmp/.* /tmp/
@@ -89,72 +90,142 @@ mount_temp_fallback () {
return 0
}
-fdisk -l | sed -n "/^\/dev\//p" > "/etc/disk.partition"
+mount_partition () {
+ local mountpoint="$1"
+ local partition="$2"
-echo "Partitions:"
-cat "/etc/disk.partition"
-
-# 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)
-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
- # 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"
- HAVE_TEMP=yes
- break
+ mkdir -p "$mountpoint"
+ if ! blkid -s TYPE | grep "${partition}" ; then
+ echo "No fs found for ${partition}, formating..."
+ diskfm "$partition" "jfs xfs ext3" || return $?
+ mount -t auto -o noexec "$partition" "$mountpoint" || return $?
else
- echo "formatting failed for some reason"
- fi # Made this non-forking, systemd should handle it - 2013-05-28
-done
+ if ! mount -t auto -o noexec "$partition" "$mountpoint" ; then
+ echo "Mount of $partition on $mountpoint failed with code $?, trying fsck..."
+ fsck "$partition" || return $?
+ mount -t auto -o noexec "$partition" "$mountpoint" || return $?
+ fi
+ fi
+ echo "${partition}\t${mountpoint}\tauto\t\tnoauto,noexec\t\t 0 0" >> "/etc/fstab"
+}
-# 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"
+read_partitions () {
+ # create the /etc/disk.partition file with all the partitions and respective id's (MSDOS and GPT)
+ echo "PARTITION - ID" > "/etc/disk.partition"
+ for hd in $(cat /proc/partitions | tr -s ' ' | cut -d ' ' -f5 | grep -o -e "[a-z]*$"); do
+ echo -n "$hd (" >> "/etc/disk.partition"
+ sfdisk -d /dev/$hd 2>&1 | grep 'GPT' > /dev/null
+ if [ $? -eq 1 ]; then
+ echo "MSDOS)" >> "/etc/disk.partition"
+ fdisk /dev/$hd -l | sed -n "/^\/dev\//p" | tr -d '*' | tr -s ' ' | cut -d ' ' -f1,5 >> "/etc/disk.partition"
+ else
+ echo "GPT)" >> "/etc/disk.partition"
+ for part in $(cat /proc/partitions | tr -s ' ' | cut -d ' ' -f5 | grep -o -e "$hd[0-9][0-9]*$"); do
+ LINE="/dev/$part "
+ LINE=${LINE}$(sgdisk /dev/$hd -i ${part:3} | grep 'GUID code' | cut -d ' ' -f4)
+ echo $LINE >> "/etc/disk.partition"
+ done
fi
done
+
+ echo "Partitions:"
+ cat "/etc/disk.partition"
+ echo "------------------------------------------------------"
+}
+
+# default partitions, if not specifies in config (note: size is irrelevant for setup_partitions)
+if [ -z "${SLX_PARTITION_TABLE}" ]; then
+ SLX_PARTITION_TABLE='
+ 44,10G,/tmp
+ 45,10G,/var/scratch
+ 82,4G'
+fi
+
+read_partitions
+
+for PARTITION in $SLX_PARTITION_TABLE; do
+ IFS=,
+ set $PARTITION
+ id=$1
+ shift
+ size=$1
+ shift
+ mountpoint="$1"
+ shift
+ options="$*"
+ unset IFS
+
+ case $id in
+ 44)
+ HAVE_TEMP="no"
+ TMP_SIZE=$size
+ for tmppart in $(grep -e "44$\|44000000-0000-0000-0000-000000000000$" /etc/disk.partition | cut -d ' ' -f1); do
+ echo "tmp partition found, formatting and mounting..."
+ if diskfm "$tmppart"; then
+ # echo "$tmppart is mounted to /mnt/tmp at $(sysup)" >/tmp/tmpready
+ mount_temp "$mopt" "$tmppart" || continue
+ echo "${tmppart}\t/tmp\t\tauto\t\tnoexec\t 0 0" >> "/etc/fstab"
+ HAVE_TEMP="yes"
+ echo "$tmppart mounted on /tmp"
+ else
+ echo "formatting tmp partition failed for some reason"
+ fi # Made this non-forking, systemd should handle it - 2013-05-28
+ done
+ ;;
+ 46)
+ for openslxpart in $(grep -e "46$\|46000000-0000-0000-0000-000000000000$" /etc/disk.partition | cut -d ' ' -f1); do
+ mkdir -p "/media/${openslxpart#/dev/*}"
+ #mount -t auto ${openslxpart} /mnt/media/${openslxpart#/dev/*} \n\
+ #test -d /mnt/media/${openslxpart#/dev/*}/home && \
+ #ln -sf /media/${openslxpart#/dev/*} /var/home
+ echo "${openslxpart}\t/media/${openslxpart#/dev/*}\tauto\t\tnoauto\t\t 0 0" >> "/etc/fstab"
+ echo "special partition ${openslxpart} mounted on /media/${openslxpart#/dev/*}"
+ done
+ ;;
+ 82)
+ # Check for standard swap partitions and make them available to the system
+ HAVE_SWAP=no
+ for swppart in $(grep -e "82$\|0657FD6D-A4AB-43C4-84E5-0933C84B4F4F$" /etc/disk.partition | cut -d ' ' -f1); do
+ echo -e "$swppart\tswap\t\tswap\t\tdefaults\t 0 0" >> "/etc/fstab"
+ mkswap "$swppart" && swapon "$swppart" -p 10 && HAVE_SWAP=yes # low priority, in case we have zram swap, prefer that)
+ [ $HAVE_SWAP = "yes" ] && echo "swap partition found and activated"
+ done
+ ;;
+ *)
+ for hdpartnr in $(grep -e "${id}$\|${id}000000-0000-0000-0000-000000000000$" /etc/disk.partition | cut -d ' ' -f1); do
+ mount_partition "${mountpoint}" $hdpartnr
+ mount_status=$?
+ if [ $mount_status -ne 0 ]; then
+ echo "Mount of partition $hdpartnr on ${mountpoint} failed with exit code: $mount_status"
+ [ -d "${mountpoint}" ] && rm -r "${mountpoint}"
+ else
+ echo "special partition $hdpartnr mounted on ${mountpoint}"
+ fi
+ done
+ ;;
+ esac
+ echo "------------------------------------------------------"
+done
+
+#Put detected linux partitions (83) into /etc/fstab with "noauto"
+for linuxpart in $(grep -e "83$\|0FC63DAF-8483-4772-8E79-3D69D8477DE4$" /etc/disk.partition | cut -d ' ' -f1); do
+ mountpoint="/media"
+ mkdir -p "${mountpoint}/${linuxpart#/dev/*}"
+ echo "${linuxpart}\t${mountpoint}/${linuxpart#/dev/*}\tauto\t\tnoauto,noexec\t 0 0" >> "/etc/fstab"
+ echo "linux partition ${linuxpart} mounted on ${mountpoint}/${linuxpart#/dev/*}"
+ echo "------------------------------------------------------"
done
-[ "$HAVE_PERSISTENT" = "no" -a -d "$PERSISTENT" ] && rm -f "$PERSISTENT"
mount -a
# Make huge tmpfs if nothing could be mounted for /tmp
if [ "$HAVE_TEMP" = "no" ]; then
- mount_temp -t tmpfs -o size=20G none
- slxlog "partition-temp" "Running /tmp on tmpfs only!" "/etc/disk.partition"
+ mount_temp -t tmpfs -o size=${TMP_SIZE} none
+ slxlog "partition-temp" "Running /tmp on tmpfs only!" "/etc/disk.partition"
fi
+
if [ "$HAVE_SWAP" = "no" ]; then
slxlog "partition-swap" "Have no (formatted) swap partition, using zram swap only!" "/etc/disk.partition"
fi
exit 0
-