1
0
mirror of https://github.com/tboerger/nixos-config synced 2024-11-26 07:43:45 +01:00
github.com-tboerger-nixos-c.../scripts/asgard-partitions
2022-11-10 16:01:39 +01:00

236 lines
6.7 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 "----> Remove previous VGs"
for VG in $(vgs --noheadings 2>/dev/null | sed -e 's/^[[:space:]]*//' | cut -d" " -f 1); do
vgremove -y ${VG} 2>/dev/null
done
echo "----> Remove previous PVs"
for PV in $(pvs --noheadings 2>/dev/null | sed -e 's/^[[:space:]]*//' | cut -d" " -f 1); do
pvremove -y ${PV} 2>/dev/null
done
echo "----> Remove previous MDs"
if [[ -d /dev/md ]]; then
for MD in /dev/md/*; do
mdadm --stop $MD
done
fi
echo "----> Drop existing partitions"
wipefs -a /dev/disk/by-path/pci-0000:00:14.1-ata-1 || true
sfdisk --delete /dev/disk/by-path/pci-0000:00:14.1-ata-1 || true
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:11.0-ata-1.0
sgdisk -og /dev/disk/by-path/pci-0000:00:11.0-ata-1.0
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:11.0-ata-2.0
sgdisk -og /dev/disk/by-path/pci-0000:00:11.0-ata-2.0
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:11.0-ata-3.0
sgdisk -og /dev/disk/by-path/pci-0000:00:11.0-ata-3.0
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:11.0-ata-4.0
sgdisk -og /dev/disk/by-path/pci-0000:00:11.0-ata-4.0
echo "-----> Wait for cleanup"
sleep 3
sync
echo "-----> Mark MBR disks"
echo yes | parted -s /dev/disk/by-path/pci-0000:00:14.1-ata-1 -- mklabel msdos
echo "-----> Create boot partition"
parted /dev/disk/by-path/pci-0000:00:14.1-ata-1 -- mkpart primary ext4 1MB 1GB
parted /dev/disk/by-path/pci-0000:00:14.1-ata-1 -- set 1 boot on
echo "-----> Create root partition"
parted /dev/disk/by-path/pci-0000:00:14.1-ata-1 -- mkpart primary ext4 1GB 100%
echo "-----> Create tank partition"
sgdisk -n 0:0:0 -t 0:8300 -c 0:tank /dev/disk/by-path/pci-0000:00:11.0-ata-1
sgdisk -n 0:0:0 -t 0:8300 -c 0:tank /dev/disk/by-path/pci-0000:00:11.0-ata-2
sgdisk -n 0:0:0 -t 0:8300 -c 0:tank /dev/disk/by-path/pci-0000:00:11.0-ata-3
sgdisk -n 0:0:0 -t 0:8300 -c 0:tank /dev/disk/by-path/pci-0000:00:11.0-ata-4
echo "-----> Wait for data"
sleep 3
sync
echo "-----> Create data pv"
pvcreate /dev/disk/by-path/pci-0000:00:14.1-ata-1-part2
echo "-----> Create data vg"
vgcreate system /dev/disk/by-path/pci-0000:00:14.1-ata-1-part2
echo "-----> Create swap volume"
lvcreate -y --size 24G --name swap system
echo "-----> Create root volume"
lvcreate -y --size 50G --name root system
echo "-----> Create home volume"
lvcreate -y --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.ext4 -L boot /dev/disk/by-path/pci-0000:00:14.1-ata-1-part1
echo "-----> Mount boot filesystem"
mkdir /mnt/boot
mount /dev/disk/by-path/pci-0000:00:14.1-ata-1-part1 /mnt/boot
echo "-----> Wait for filesystems"
sleep 3
sync
echo "----> Remove previous MDs"
if [[ -d /dev/md ]]; then
for MD in /dev/md/*; do
mdadm --stop $MD
done
fi
echo "-----> Create raid volume"
echo yes | mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/disk/by-path/pci-0000:00:11.0-ata-1.0-part1 /dev/disk/by-path/pci-0000:00:11.0-ata-2.0-part1
echo yes | mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/disk/by-path/pci-0000:00:11.0-ata-3.0-part1 /dev/disk/by-path/pci-0000:00:11.0-ata-4.0-part1
echo "-----> Create tank pv"
pvcreate /dev/md0 /dev/md1
echo "-----> Create tank vg"
vgcreate tank /dev/md0 /dev/md1
echo "-----> Create shares volume"
lvcreate -y --size 10G --name shares tank
echo "-----> Create shares filesystem"
mkfs.ext4 -L shares /dev/tank/shares
echo "-----> Mount shares filesystem"
mkdir -p /mnt/var/lib/media/shares
mount -t ext4 /dev/tank/shares /mnt/var/lib/media/shares
chown 20000:20000 /mnt/var/lib/media/shares
echo "-----> Create photos volume"
lvcreate -y --size 100G --name photos tank
echo "-----> Create photos filesystem"
mkfs.ext4 -L photos /dev/tank/photos
echo "-----> Mount photos filesystem"
mkdir -p /mnt/var/lib/media/photos
mount -t ext4 /dev/tank/photos /mnt/var/lib/media/photos
chown 20000:20000 /mnt/var/lib/media/photos
echo "-----> Create videos volume"
lvcreate -y --size 100G --name videos tank
echo "-----> Create videos filesystem"
mkfs.ext4 -L videos /dev/tank/videos
echo "-----> Mount videos filesystem"
mkdir -p /mnt/var/lib/media/videos
mount -t ext4 /dev/tank/videos /mnt/var/lib/media/videos
chown 20000:20000 /mnt/var/lib/media/videos
echo "-----> Create movies volume"
lvcreate -y --size 500G --name movies tank
echo "-----> Create movies filesystem"
mkfs.ext4 -L movies /dev/tank/movies
echo "-----> Mount movies filesystem"
mkdir -p /mnt/var/lib/media/movies
mount -t ext4 /dev/tank/movies /mnt/var/lib/media/movies
chown 20000:20000 /mnt/var/lib/media/movies
echo "-----> Create shows volume"
lvcreate -y --size 500G --name shows tank
echo "-----> Create shows filesystem"
mkfs.ext4 -L shows /dev/tank/shows
echo "-----> Mount shows filesystem"
mkdir -p /mnt/var/lib/media/shows
mount -t ext4 /dev/tank/shows /mnt/var/lib/media/shows
chown 20000:20000 /mnt/var/lib/media/shows
echo "-----> Create books volume"
lvcreate -y --size 50G --name books tank
echo "-----> Create books filesystem"
mkfs.ext4 -L books /dev/tank/books
echo "-----> Mount books filesystem"
mkdir -p /mnt/var/lib/media/books
mount -t ext4 /dev/tank/books /mnt/var/lib/media/books
chown 20000:20000 /mnt/var/lib/media/books
echo "-----> Create music volume"
lvcreate -y --size 50G --name music tank
echo "-----> Create music filesystem"
mkfs.ext4 -L music /dev/tank/music
echo "-----> Mount music filesystem"
mkdir -p /mnt/var/lib/media/music
mount -t ext4 /dev/tank/music /mnt/var/lib/media/music
chown 20000:20000 /mnt/var/lib/media/music
echo "-----> Create printer volume"
lvcreate -y --size 5G --name printer tank
echo "-----> Create printer filesystem"
mkfs.ext4 -L printer /dev/tank/printer
echo "-----> Mount printer filesystem"
mkdir -p /mnt/var/lib/printer
mount -t ext4 /dev/tank/printer /mnt/var/lib/printer
chown 20001:20001 /mnt/var/lib/printer
echo "-----> Create backup volume"
lvcreate -y --size 50G --name backup tank
echo "-----> Create backup filesystem"
mkfs.ext4 -L backup /dev/tank/backup
echo "-----> Mount backup filesystem"
mkdir -p /mnt/var/lib/backup
mount -t ext4 /dev/tank/backup /mnt/var/lib/backup