mirror of
https://github.com/tboerger/nixos-config
synced 2024-11-23 12:42:01 +01:00
100 lines
2.3 KiB
Plaintext
100 lines
2.3 KiB
Plaintext
|
#!/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/sde
|
||
|
|
||
|
echo "-----> Create root partition"
|
||
|
sgdisk -n 0:0:0 -t 0:8300 -c 0:data /dev/sde
|
||
|
|
||
|
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/sda
|
||
|
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
|
||
|
|
||
|
echo "-----> Create raid volume"
|
||
|
mdadm --create /dev/md0 --level=1 --raid-devices=4 /dev/sda1 /dev/sdb1
|
||
|
mdadm --create /dev/md1 --level=1 --raid-devices=4 /dev/sdc1 /dev/sdd1
|
||
|
|
||
|
echo "-----> Create tank pv"
|
||
|
pvcreate /dev/md0 /dev/md1
|
||
|
|
||
|
echo "-----> Create tank vg"
|
||
|
vgcreate tank /dev/md0 /dev/md1
|