1
0
mirror of https://github.com/tboerger/nixos-config synced 2024-11-23 03:32:08 +01:00
github.com-tboerger-nixos-c.../scripts/utgard-partitions
2022-04-11 00:22:59 +02:00

143 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eo pipefail
if [ "${EUID}" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
while true; do
read -p "Are you sure you want to wipe all partitions? " awnser
case ${awnser} in
[Yy]*)
break
;;
[Nn]*)
exit
;;
*)
echo "Please answer yes or no!"
;;
esac
done
echo "----> Drop existing partitions"
sgdisk --zap-all /dev/sda
sgdisk -og /dev/sda
sgdisk --zap-all /dev/sdb
sgdisk -og /dev/sdb
echo "-----> Create boot partition"
sgdisk -n 0:0:+1G -t 0:ef00 -c 0:boot /dev/sda
echo "-----> Create root partition"
sgdisk -n 0:0:0 -t 0:8300 -c 0:data /dev/sda
echo "-----> Create data pv"
pvcreate /dev/disk/by-partlabel/data
echo "-----> Create data vg"
vgcreate system /dev/disk/by-partlabel/data
echo "-----> Create swap volume"
lvcreate --size 24G --name swap system
echo "-----> Create root volume"
lvcreate --size 50G --name root system
echo "-----> Create home volume"
lvcreate --size 50G --name home system
echo "-----> Enable swap partition"
mkswap -L swap /dev/system/swap
swapon /dev/system/swap
echo "-----> Create root filesystem"
mkfs.ext4 -L root /dev/system/root
echo "-----> Mount root filesystem"
mount -t ext4 /dev/system/root /mnt
echo "-----> Create home filesystem"
mkfs.ext4 -L home /dev/system/home
echo "-----> Mount home filesystem"
mkdir /mnt/home
mount -t ext4 /dev/system/home /mnt/home
echo "-----> Create boot filesystem"
mkfs.vfat -n boot /dev/disk/by-partlabel/boot
echo "-----> Wait for boot"
sleep 3
echo "-----> Mount boot filesystem"
mkdir /mnt/boot
mount /dev/disk/by-label/boot /mnt/boot
echo "-----> Create tank partition"
sgdisk -n 0:0:0 -t 0:8300 -c 0:tank /dev/sdb
echo "-----> Create tank pv"
pvcreate /dev/disk/by-partlabel/tank
echo "-----> Create tank vg"
vgcreate tank /dev/disk/by-partlabel/tank
echo "-----> Create downloads volume"
lvcreate --size 50G --name downloads tank
echo "-----> Create downloads filesystem"
mkfs.ext4 -L downloads /dev/tank/downloads
echo "-----> Mount downloads filesystem"
mkdir -p /var/lib/media/downloads
mount -t ext4 /dev/tank/downloads /var/lib/media/downloads
chown 20000:20000 /var/lib/media/downloads
echo "-----> Create movies volume"
lvcreate --size 200G --name movies tank
echo "-----> Create movies filesystem"
mkfs.ext4 -L movies /dev/tank/movies
echo "-----> Mount movies filesystem"
mkdir -p /var/lib/media/movies
mount -t ext4 /dev/tank/movies /var/lib/media/movies
chown 20000:20000 /var/lib/media/movies
echo "-----> Create series volume"
lvcreate --size 300G --name series tank
echo "-----> Create series filesystem"
mkfs.ext4 -L series /dev/tank/series
echo "-----> Mount series filesystem"
mkdir -p /var/lib/media/series
mount -t ext4 /dev/tank/series /var/lib/media/series
chown 20000:20000 /var/lib/media/series
echo "-----> Create books volume"
lvcreate --size 50G --name books tank
echo "-----> Create books filesystem"
mkfs.ext4 -L books /dev/tank/books
echo "-----> Mount books filesystem"
mkdir -p /var/lib/media/books
mount -t ext4 /dev/tank/books /var/lib/media/books
chown 20000:20000 /var/lib/media/books
for PARTITION in acme nzbget jellyfin bazarr lidarr prowlarr radarr readarr sonarr; do
echo "-----> Create ${PARTITION} volume"
lvcreate --size 5G --name ${PARTITION} system
echo "-----> Create ${PARTITION} filesystem"
mkfs.ext4 -L ${PARTITION} /dev/system/${PARTITION}
echo "-----> Mount ${PARTITION} filesystem"
mkdir /var/lib/${PARTITION}
mount -t ext4 /dev/system/${PARTITION} /var/lib/${PARTITION}
done