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/asgard-partitions
2022-09-27 22:07:46 +02:00

166 lines
4.1 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
sgdisk --zap-all /dev/sdc
sgdisk -og /dev/sdc
sgdisk --zap-all /dev/sdd
sgdisk -og /dev/sdd
sgdisk --zap-all /dev/sde
sgdisk -og /dev/sde
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
sgdisk -n 0:0:0 -t 0:8300 -c 0:tank /dev/sdc
sgdisk -n 0:0:0 -t 0:8300 -c 0:tank /dev/sdd
sgdisk -n 0:0:0 -t 0:8300 -c 0:tank /dev/sde
echo "-----> Create raid volume"
mdadm --create /dev/md0 --level=1 --raid-devices=4 /dev/sdb1 /dev/sdc1
mdadm --create /dev/md1 --level=1 --raid-devices=4 /dev/sdd1 /dev/sde1
echo "-----> Create tank pv"
pvcreate /dev/md0 /dev/md1
echo "-----> Create tank vg"
vgcreate tank /dev/md0 /dev/md1
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 500G --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 500G --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
echo "-----> Create music volume"
lvcreate --size 50G --name music tank
echo "-----> Create music filesystem"
mkfs.ext4 -L music /dev/tank/music
echo "-----> Mount music filesystem"
mkdir -p /var/lib/media/music
mount -t ext4 /dev/tank/music /var/lib/media/music
chown 20000:20000 /var/lib/media/music
echo "-----> Create shares volume"
lvcreate --size 50G --name shares tank
echo "-----> Create shares filesystem"
mkfs.ext4 -L shares /dev/tank/shares
echo "-----> Mount shares filesystem"
mkdir -p /var/lib/media/shares
mount -t ext4 /dev/tank/shares /var/lib/media/shares
chown 20000:20000 /var/lib/media/shares