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
|
#!/bin/bash
# Copyright (C) 2022 by Mike Gabriel <mike.gabriel@it-zukunft-schule.de>
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
# This scripts turns a storage device into a two-partitioned
# storage, first partition containing 16GB swap space, second
# partition containing a scratch partition for local storage.
if [ $(id -u) -gt 0 ]; then
echo "ERROR: This script has to run as super-user root."
exit 1
fi
DEV="$1" # pick your disk device
p=""
if [ -z "${DEV}" ]; then
echo "no device given"
exit 1
fi
if [ ! -e ${DEV} ]; then
echo "no such device"
exit 1
fi
if echo ${DEV} | grep -E "\/dev\/nvme.*"; then
p="p"
fi
wipefs -a ${DEV} # recommended if you want to swap partition table types
# partitioning for 16G swapfs and rest as a scratch disk
SWAP_SIZE=16384
echo "label: gpt
device: ${DEV}
unit: sectors
${DEV}${p}1 : size=${SWAP_SIZE}MiB, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
${DEV}${p}2 : type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, name=DLW_SCRATCH
" | sfdisk ${DEV}
mkswap ${DEV}${p}1
mkfs.ext4 -L DLW_SCRATCH ${DEV}${p}2
|