summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas Affonso Xavier de Morais2014-08-21 23:57:26 +0200
committerMichael Pereira Neves2014-10-28 14:14:50 +0100
commit19600e53db2260b61a78af1d1e5e1d2c07dfa879 (patch)
tree63bbc58879f2bcbcf517205eec20b6f05251b35b
parent[partitioner] made partitioner a config module (diff)
downloadtm-scripts-19600e53db2260b61a78af1d1e5e1d2c07dfa879.tar.gz
tm-scripts-19600e53db2260b61a78af1d1e5e1d2c07dfa879.tar.xz
tm-scripts-19600e53db2260b61a78af1d1e5e1d2c07dfa879.zip
[partitioner] default statements implemented.
-rwxr-xr-xremote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions83
-rwxr-xr-xserver/modules/partitioner/opt/openslx/scripts/partitioner83
2 files changed, 85 insertions, 81 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 17202418..748e017d 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
@@ -1,4 +1,4 @@
-#!/bin/ash
+#!/bin/bash
# Copyright (c) 2013 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
@@ -13,12 +13,8 @@
# detecting swap and special partitions
#############################################################################
-
-# Mount point for persistent scratch partition (type 49 for BOOT, type48 for CACHE, type 47 for HOME)
-
-PERSISTENT_BOOT="/boot"
-PERSISTENT_CACHE="/cache"
-PERSISTENT_HOME="/home"
+CONFIGPATH="./config"
+. $CONFIGPATH
# General formatter for the /tmp partition on a local harddisk
diskfm () {
@@ -94,43 +90,49 @@ mount_temp_fallback () {
mount_part() { # $1=mountpoint, $2=partition(/dev/*)
mkdir -p "$1"
- if ! mount -t auto -o noexec "${2}" "$1"; then
+ if ! mount -t auto -o noexec "${2}" "$1" 2> /dev/null ; then
diskfm "$2" "jfs xfs ext3" || continue
mount -t auto -o noexec "${2}" "$1" || continue
fi
echo -e "${2}\t${1}\tauto\t\tnoauto,noexec\t\t 0 0" >> "/etc/fstab"
}
+# default case
+if [ -z "$SLX_PARTITION_TABLE" ]; then
+ SLX_PARTITION_TABLE='
+ 44,10G,/tmp
+ 45,10G,/var/scratch'
+fi
+
declare -A PARTTBL
COUNTER=1
-if [ -n "$SLX_PARTITION_TABLE" ]; then
- for PARTITION in $SLX_PARTITION_TABLE; do
- IFS=,
- set $PARTITION
- PARTTBL["$COUNTER/id"]=$1
- PARTTBL["$COUNTER/size"]=$(echo $2 | egrep -o "[0-9]*")
- PARTTBL["$COUNTER/mountpoint"]=$3
- if [ -e $4 ]; then
- PARTTBL["$COUNTER/bootable"]=0
- else
- PARTTBL["$COUNTER/bootable"]=1
- fi
- # set the partitions to non-existents
- PARTTBL["$COUNTER/persistent"]="no"
- COUNTER=$(($COUNTER+1))
- done
- unset IFS
-fi
+for PARTITION in $SLX_PARTITION_TABLE; do
+ IFS=,
+ set $PARTITION
+ PARTTBL["$COUNTER/id"]=$1
+ PARTTBL["$COUNTER/size"]=$(echo $2 | egrep -o "[0-9]*")
+ PARTTBL["$COUNTER/mountpoint"]=$3
+ if [ -e $4 ]; then
+ PARTTBL["$COUNTER/bootable"]=0
+ else
+ PARTTBL["$COUNTER/bootable"]=1
+ fi
+ PARTTBL["$COUNTER/persistent"]="no"
+ COUNTER=$(($COUNTER+1))
+done
+unset IFS
+
# 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"
+ 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 -s ' ' | cut -d ' ' -f1,5 >> "/etc/disk.partition"
+ 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"
+ 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)
@@ -141,7 +143,6 @@ done
echo "Partitions:"
cat "/etc/disk.partition"
-
# 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
@@ -162,37 +163,28 @@ for openslxpart in $(grep -e "46$\|46000000-0000-0000-0000-000000000000$" /etc/d
echo -e "${openslxpart}\t/media/${openslxpart#/dev/*}\tauto\t\tnoauto\t\t 0 0" >> "/etc/fstab"
done
-# We use special non assigned partition type (id44) for harddisk scratch
-# space, thus no normal filesystem will be incidentally deleted or
-# corrupted
-
-# Put detected linux partitions (83) into /etc/fstab with "noauto", special
-# partition 45 (persistent scratch) to /var/scratch and 46 to /var/openslx
-
-# for partid in 83 0FC63DAF-8483-4772-8E79-3D69D8477DE4 49 48 47 46; do
-
HAVE_TEMP="no"
for (( i = 1; i < $COUNTER; i++ )); do
- for hdpartnr in $(grep -e ${PARTTBL["$i/id"]} /etc/disk.partition | cut -d ' ' -f1); do
+ for hdpartnr in $(grep -e ${PARTTBL["$i/id"]}"$\|"${PARTTBL["$i/id"]}"000000-0000-0000-0000-000000000000$" /etc/disk.partition | cut -d ' ' -f1); do
if [ "${PARTTBL["$i/mountpoint"]}" = "/tmp" ]; then
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
+ PARTTBL["$i/persistent"]="yes"
else
echo "formatting failed for some reason"
fi # Made this non-forking, systemd should handle it - 2013-05-28
+ else
+ mount_part "${PARTTBL["$i/mountpoint"]}" $hdpartnr
+ PARTTBL["$i/persistent"]="yes"
fi
- mount_part "${PARTTBL["$i/mountpoint"]}" $hdpartnr
- PARTTBL["$i/persistent"]="yes"
done
[ "${PARTTBL["$i/persistent"]}" = "no" -a -d "${PARTTBL["$i/mountpoint"]}" ] && rm -f "${PARTTBL["$i/mountpoint"]}"
done
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
@@ -201,5 +193,4 @@ fi
if [ "$HAVE_SWAP" = "no" ]; then
slxlog "partition-swap" "Have no (formatted) swap partition, using zram swap only!" "/etc/disk.partition"
fi
-
exit 0 \ No newline at end of file
diff --git a/server/modules/partitioner/opt/openslx/scripts/partitioner b/server/modules/partitioner/opt/openslx/scripts/partitioner
index e5e94f4e..03b30442 100755
--- a/server/modules/partitioner/opt/openslx/scripts/partitioner
+++ b/server/modules/partitioner/opt/openslx/scripts/partitioner
@@ -3,7 +3,8 @@
# set -e
PARTITIONSPATH="/proc/partitions"
-CONFIGPATH="/opt/openslx/config"
+CONFIGPATH="./config"
+# CONFIGPATH="/opt/openslx/config"
# BLOCKSIZE=$(sfdisk -l /dev/$CHOSENDISK | grep -o -e "blocks of [0-9]* bytes" | cut -d ' ' -f3)
BLOCKSIZE=1024
@@ -19,6 +20,10 @@ if [ -z "$DISKS" ]; then
exit 1
fi
if [ -z "$SLX_CHOOSEN_DISK" ]; then
+ if [ $SLX_AUTOMATIC_PARTITIONING = "yes" ]; then
+ dialog --msgbox "ERROR: You didn' define any hard disk in your configuration file." 10 40
+ exit 1
+ fi
DIALOGSTR="This computer has the following partitions:\n"
for disk in $DISKS; do
DISKSIZE=$(($(cat $PARTITIONSPATH | grep -e $disk$ | tr -s ' ' | cut -d ' ' -f4)*$BLOCKSIZE))
@@ -63,33 +68,39 @@ if [ -z "$SLX_CHOOSEN_DISK" ]; then
exit 1
fi
fi
+if [ -z "$SLX_PARTITION_TABLE" ]; then
+ if [ $SLX_AUTOMATIC_PARTITIONING = "yes" ]; then
+ SLX_PARTITION_TABLE='
+ 44,10G,/tmp
+ 45,10G,/var/scratch'
+ else
+ dialog --msgbox "ERROR: You didn't set a valid partition table. Please check your config file." 10 40
+ exit 1
+ fi
+fi
+
# if SLX_PARTITION_TABLE is set then put his content in a associative array
declare -A PARTTBL
COUNTER=1
-if [ -n "$SLX_PARTITION_TABLE" ]; then
- for PARTITION in $SLX_PARTITION_TABLE; do
- IFS=,
- set $PARTITION
- if [ $COUNTER -eq 4 ]; then
- COUNTER=$(($COUNTER+1))
- fi
- PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/id"]=$1
- PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/size"]=$(echo $2 | egrep -o "[0-9]*")
- PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/mountpoint"]=$3
- if [ -e $4 ]; then
- PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/bootable"]=0
- else
- PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/bootable"]=1
- fi
- # set the partitions to non-existents
- PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/exists"]=0
+for PARTITION in $SLX_PARTITION_TABLE; do
+ IFS=,
+ set $PARTITION
+ if [ $COUNTER -eq 4 ]; then
COUNTER=$(($COUNTER+1))
- done
- unset IFS
-else
- dialog --msgbox "ERROR: You didn't set a valid partition table. Please check your config file." 10 40
- exit 1
-fi
+ fi
+ PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/id"]=$1
+ PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/size"]=$(echo $2 | egrep -o "[0-9]*")
+ PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/mountpoint"]=$3
+ if [ -e $4 ]; then
+ PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/bootable"]=0
+ else
+ PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/bootable"]=1
+ fi
+ # set the partitions to non-existents
+ PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/exists"]=0
+ COUNTER=$(($COUNTER+1))
+done
+unset IFS
# PARTTBL starts at 1 and ends at COUNTER-1
# check if the choosen disk is greater than the new partition table size.
@@ -101,7 +112,6 @@ for (( i = 1; i < $COUNTER; i++ )); do
fi
done
NEEDED_SPACE=$(($NEEDED_SPACE*1024*1024*1024+$COUNTER*1024*1024))
-echo "$DISKSIZE -lt $NEEDED_SPACE"
if [ $DISKSIZE -lt $NEEDED_SPACE ]; then
dialog --msgbox "ERROR: Insufficient space in disk /dev/$SLX_CHOOSEN_DISK." 6 40
exit 1
@@ -109,15 +119,18 @@ fi
# choosing the partition type (MSDOS or GPT) if it wasn't set in config file
if [ -z "$SLX_PARTITION_TYPE" ]; then
- SLX_PARTITION_TYPE=msdos
- ANS=$(dialog --no-tags --menu "Choose the partitions type" 0 0 0 "1" " MSDOS " "2" " GPT " 3>&1 1>&2 2>&3)
- if [ $? -eq 1 ]; then
- exit 1
- fi
- if [ $ANS -eq 1 ]; then
+ if [ $SLX_AUTOMATIC_PARTITIONING = "yes" ]; then
SLX_PARTITION_TYPE=msdos
else
- SLX_PARTITION_TYPE=GPT
+ ANS=$(dialog --no-tags --menu "Choose the partitions type" 0 0 0 "1" " MSDOS " "2" " GPT " 3>&1 1>&2 2>&3)
+ if [ $? -eq 1 ]; then
+ exit 1
+ fi
+ if [ $ANS -eq 1 ]; then
+ SLX_PARTITION_TYPE=msdos
+ else
+ SLX_PARTITION_TYPE=GPT
+ fi
fi
fi
@@ -140,7 +153,7 @@ DIALOGSTR=$DIALOGSTR" Free $FREESPACE ($GBSIZE GB)\n\n"
DIALOGSTR=$DIALOGSTR"All /dev/$SLX_CHOOSEN_DISK partitions will be deleted, ok?"
# asking confirmation to create the partitions
-if [[ $SLX_AUTOMATIC_PARTITIONING = "no" && SLX_DELETE_PARTITION_TABLE = 'yes' ]]; then
+if [[ $SLX_AUTOMATIC_PARTITIONING = "no" && $SLX_DELETE_PARTITION_TABLE = 'yes' ]]; then
dialog --defaultno --yesno "$DIALOGSTR" 0 0
if [ $? -eq 1 ]; then
exit 1
@@ -188,7 +201,7 @@ elif [ $(sfdisk -d /dev/$SLX_CHOOSEN_DISK 2> /dev/null | grep $SLX_CHOOSEN_DISK'
for (( i = 1; i < $COUNTER; i++ )); do
if [ $i -ne 4 ]; then
if [ ${PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]} = 0 ]; then
- sgdisk /dev/$SLX_CHOOSEN_DISK -i ${PART:3} | grep ${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}"000000-0000-0000-0000-000000000000" > /dev/null
+ sgdisk /dev/$SLX_CHOOSEN_DISK -i ${PART:3} 2> /dev/null | grep ${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}"000000-0000-0000-0000-000000000000" > /dev/null
if [ $? -eq 0 ]; then
echo "the partition $PART is the ${PARTTBL["$SLX_CHOOSEN_DISK$i/mountpoint"]} partition."
PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]=$PART
@@ -243,7 +256,7 @@ if [ $SLX_PARTITION_TYPE = 'GPT' ]; then
CMD=$CMD" -c "$i":\""${PARTTBL["$SLX_CHOOSEN_DISK$i/mountpoint"]}"\""
fi
done
- CMD=$CMD" > /dev/null"
+ CMD=$CMD" > /dev/null 2> /dev/null"
$CMD
for (( i = 1; i < $COUNTER; i++ )); do