summaryrefslogtreecommitdiffstats
path: root/core/modules/gdisk/data/inc/setup_gpt.differentapproach
blob: 6f3013eee82dfbaaf19d4bd5223022d972055963 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/ash
# -----------------------------------------------------------------------------
#
# Copyright (c) 2014..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
#
# -----------------------------------------------------------------------------

# Partition IDs
# Prefix for all partitions is 0FC63DAF-8483-4772-8E79-9999999999
# Suffix:
#  44: non-persistent scratch partition
#  45: persistent partition
#  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

PREFIX=/mnt

# Set disks to none
ID44=
ID45=
ID46=

# Mountpoints
ID44MNT=/tmp
ID45MNT=/opt/openslx/mnt/persistent
ID46MNT=/opt/openslx/mnt/non-persistent

# 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" ; 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
}

# Format and mount ID44 (/tmp)
mount_id44 () {
	HAVE_TMP=no
	if echo $ID44 | grep -q '/dev/disk/'
		then
		# check for supported filesystem and formatter
		if diskfm $ID44; then
			mkdir -p $PREFIX$ID44MNT
			if mount -t auto "$ID44" "$PREFIX$ID44MNT" 2>/dev/null
				then
				chmod a+rwxt $PREFIX$ID44MNT
				echo -e "$ID44\t$ID44MNT\tauto\tnoexec\t0 0" >> "/etc/fstab"
				HAVE_TMP=yes
			else
				echo "Could not mount partition $ID44"
			fi
		else
			echo "Could not format partition $ID44"
		fi
	fi
}

# Mount persistent partition 45
mount_id45 () {
	HAVE_PERSISTENT=no
	if echo $ID45 | grep -q '/dev/disk/'
		then
		mkdir -p $PREFIX$ID45MNT
		if mount -t auto "$ID45" "$PREFIX$ID45MNT" 2>/dev/null
			then
			echo -e "$ID45\t$ID45MNT\tauto\tnoauto\t0 0" >> "/etc/fstab"
			HAVE_PERSISTENT=yes
		else
			echo "Could not mount persistent partition $ID45"
		fi
	fi
}

# Mount non-persistent partition 46
mount_id46 () {
	HAVE_NONPERSISTENT=no
	if echo $ID46 | grep -q '/dev/disk/'
		then
		# check for supported filesystem and formatter
		if diskfm $ID46; then
			mkdir -p $PREFIX$ID46MNT
			if mount -t auto -o noexec "$ID46" "$PREFIX$ID46MNT" 2>/dev/null
				then
				echo -e "$ID46\t$ID46MNT\tauto\tnoauto,noexec\t0 0" >> "/etc/fstab"
				HAVE_NONPERSISTENT=yes
			else
				echo "Could not mount non-persistent partition $ID46"
			fi
		else
			echo "Could not format partition $ID44"
		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
        [ -r /etc/hdisks.conf ] && . /etc/hdisks.conf

fi