From 568fff55826a89068712b3e2c27358e907ff8dc7 Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Thu, 17 Nov 2022 13:32:11 +0100 Subject: [PATCH] feat: move partition scripts into machine folders --- README.md | 12 +- .../chnum/partitions.sh | 26 +--- desktops/hathor/partitions.sh | 112 ++++++++++++++++++ desktops/osiris/partitions.sh | 112 ++++++++++++++++++ .../asgard/partitions.sh | 4 + .../niflheim/partitions.sh | 4 + .../utgard/partitions.sh | 4 + 7 files changed, 246 insertions(+), 28 deletions(-) rename scripts/chnum-partitions => desktops/chnum/partitions.sh (82%) create mode 100755 desktops/hathor/partitions.sh create mode 100755 desktops/osiris/partitions.sh rename scripts/asgard-partitions => servers/asgard/partitions.sh (99%) rename scripts/niflheim-partitions => servers/niflheim/partitions.sh (99%) rename scripts/utgard-partitions => servers/utgard/partitions.sh (98%) diff --git a/README.md b/README.md index 2ebcc1b..0bb79b1 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ latest changes pulled in. sudo loadkeys de sudo nix-shell --packages nixUnstable -bash -c "$(curl -fsSL https://raw.githubusercontent.com/tboerger/nixos-config/master/scripts/chnum-partitions)" +bash -c "$(curl -fsSL https://raw.githubusercontent.com/tboerger/nixos-config/master/desktops/chnum/partitions.sh)" mkdir -p /mnt/etc/ssh cp /etc/ssh/ssh_host_* /mnt/etc/ssh/ @@ -37,7 +37,7 @@ nixos-install --no-root-password --root /mnt --flake github:tboerger/nixos-confi sudo loadkeys de sudo nix-shell --packages nixUnstable -bash -c "$(curl -fsSL https://raw.githubusercontent.com/tboerger/nixos-config/master/scripts/hathor-partitions)" +bash -c "$(curl -fsSL https://raw.githubusercontent.com/tboerger/nixos-config/master/desktops/hathor/partitions.sh)" mkdir -p /mnt/etc/ssh cp /etc/ssh/ssh_host_* /mnt/etc/ssh/ @@ -50,7 +50,7 @@ nixos-install --no-root-password --root /mnt --flake github:tboerger/nixos-confi sudo loadkeys de sudo nix-shell --packages nixUnstable -bash -c "$(curl -fsSL https://raw.githubusercontent.com/tboerger/nixos-config/master/scripts/osiris-partitions)" +bash -c "$(curl -fsSL https://raw.githubusercontent.com/tboerger/nixos-config/master/desktops/osiris/partitions.sh)" mkdir -p /mnt/etc/ssh cp /etc/ssh/ssh_host_* /mnt/etc/ssh/ @@ -88,7 +88,7 @@ EOF nixos-generate -o /root/result -f kexec-bundle -c /root/config.nix /root/result -bash -c "$(curl -fsSL https://raw.githubusercontent.com/tboerger/nixos-config/master/scripts/niflheim-partitions)" +bash -c "$(curl -fsSL https://raw.githubusercontent.com/tboerger/nixos-config/master/servers/niflheim/partitions.sh)" mkdir -p /mnt/etc/ssh cp /etc/ssh/ssh_host_* /mnt/etc/ssh/ @@ -101,7 +101,7 @@ nixos-install --no-root-password --root /mnt --flake github:tboerger/nixos-confi sudo loadkeys de sudo nix-shell --packages nixUnstable -bash -c "$(curl -fsSL https://raw.githubusercontent.com/tboerger/nixos-config/master/scripts/asgard-partitions)" +bash -c "$(curl -fsSL https://raw.githubusercontent.com/tboerger/nixos-config/master/servers/asgard/partitions.sh)" mkdir -p /mnt/etc/ssh cp /etc/ssh/ssh_host_* /mnt/etc/ssh/ @@ -114,7 +114,7 @@ nixos-install --no-root-password --root /mnt --flake github:tboerger/nixos-confi sudo loadkeys de sudo nix-shell --packages nixUnstable -bash -c "$(curl -fsSL https://raw.githubusercontent.com/tboerger/nixos-config/master/scripts/utgard-partitions)" +bash -c "$(curl -fsSL https://raw.githubusercontent.com/tboerger/nixos-config/master/servers/utgard/partitions.sh)" mkdir -p /mnt/etc/ssh cp /etc/ssh/ssh_host_* /mnt/etc/ssh/ diff --git a/scripts/chnum-partitions b/desktops/chnum/partitions.sh similarity index 82% rename from scripts/chnum-partitions rename to desktops/chnum/partitions.sh index 1f2fda6..48ac19b 100755 --- a/scripts/chnum-partitions +++ b/desktops/chnum/partitions.sh @@ -34,12 +34,6 @@ for PV in $(pvs --noheadings 2>/dev/null | sed -e 's/^[[:space:]]*//' | cut -d" pvremove -y ${PV} 2>/dev/null done -echo "----> Remove previous MDs" -mdadm --stop --scan || true - -echo 'AUTO -all -ARRAY UUID=00000000:00000000:00000000:00000000' > /etc/mdadm/mdadm.conf - echo "----> Drop existing partitions" for DISK in pci-0000:00:1f.2-ata-1.0; do sgdisk --zap-all /dev/disk/by-path/${DISK} @@ -63,6 +57,10 @@ parted -a opt --script /dev/disk/by-path/pci-0000:00:14.1-ata-1 \ echo "-----> Reload partition table" partprobe +echo "-----> Wait for partitions" +sleep 3 +sync + echo "-----> Create data pv" pvcreate /dev/disk/by-partlabel/system @@ -112,19 +110,3 @@ mkfs.vfat -F32 -n boot /dev/disk/by-partlabel/boot echo "-----> Mount boot filesystem" mkdir -p /mnt/boot mount /dev/disk/by-label/boot /mnt/boot - -# -# STORAGE -# - -for PARTITION in ; do - echo "-----> Create ${PARTITION} volume" - lvcreate -y --size 5G --name ${PARTITION} system - - echo "-----> Create ${PARTITION} filesystem" - mkfs.ext4 -L ${PARTITION} /dev/system/${PARTITION} - - echo "-----> Mount ${PARTITION} filesystem" - mkdir /mnt/var/lib/${PARTITION} - mount -t ext4 /dev/system/${PARTITION} /mnt/var/lib/${PARTITION} -done diff --git a/desktops/hathor/partitions.sh b/desktops/hathor/partitions.sh new file mode 100755 index 0000000..48ac19b --- /dev/null +++ b/desktops/hathor/partitions.sh @@ -0,0 +1,112 @@ +#!/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" +vgchange -an + +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 "----> Drop existing partitions" +for DISK in pci-0000:00:1f.2-ata-1.0; do + sgdisk --zap-all /dev/disk/by-path/${DISK} + sgdisk -og /dev/disk/by-path/${DISK} +done + +echo "-----> Wait for cleanup" +sleep 3 +sync + +echo "-----> Create sda partitions" +parted -a opt --script /dev/disk/by-path/pci-0000:00:14.1-ata-1 \ + mklabel gpt \ + mkpart primary fat32 0% 1GB \ + set 1 esp on \ + name 1 boot \ + mkpart primary 1GB 100% \ + set 2 lvm on \ + name 2 system + +echo "-----> Reload partition table" +partprobe + +echo "-----> Wait for partitions" +sleep 3 +sync + +echo "-----> Create data pv" +pvcreate /dev/disk/by-partlabel/system + +echo "-----> Create data vg" +vgcreate system /dev/disk/by-partlabel/system + +echo "-----> Create swap volume" +lvcreate -y --size $(cat /proc/meminfo | grep MemTotal | cut -d':' -f2 | sed 's/ //g') --name swap system + +echo "-----> Create root volume" +lvcreate -y --size 20G --name root system + +echo "-----> Create nix volume" +lvcreate -y --size 50G --name nix 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" +mkdir -p /mnt +mount -t ext4 /dev/system/root /mnt + +echo "-----> Create nix filesystem" +mkfs.ext4 -L nix /dev/system/nix + +echo "-----> Mount nix filesystem" +mkdir -p /mnt/nix +mount -t ext4 /dev/system/nix /mnt/nix + +echo "-----> Create home filesystem" +mkfs.ext4 -L home /dev/system/home + +echo "-----> Mount home filesystem" +mkdir -p /mnt/home +mount -t ext4 /dev/system/home /mnt/home + +echo "-----> Create boot filesystem" +mkfs.vfat -F32 -n boot /dev/disk/by-partlabel/boot + +echo "-----> Mount boot filesystem" +mkdir -p /mnt/boot +mount /dev/disk/by-label/boot /mnt/boot diff --git a/desktops/osiris/partitions.sh b/desktops/osiris/partitions.sh new file mode 100755 index 0000000..48ac19b --- /dev/null +++ b/desktops/osiris/partitions.sh @@ -0,0 +1,112 @@ +#!/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" +vgchange -an + +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 "----> Drop existing partitions" +for DISK in pci-0000:00:1f.2-ata-1.0; do + sgdisk --zap-all /dev/disk/by-path/${DISK} + sgdisk -og /dev/disk/by-path/${DISK} +done + +echo "-----> Wait for cleanup" +sleep 3 +sync + +echo "-----> Create sda partitions" +parted -a opt --script /dev/disk/by-path/pci-0000:00:14.1-ata-1 \ + mklabel gpt \ + mkpart primary fat32 0% 1GB \ + set 1 esp on \ + name 1 boot \ + mkpart primary 1GB 100% \ + set 2 lvm on \ + name 2 system + +echo "-----> Reload partition table" +partprobe + +echo "-----> Wait for partitions" +sleep 3 +sync + +echo "-----> Create data pv" +pvcreate /dev/disk/by-partlabel/system + +echo "-----> Create data vg" +vgcreate system /dev/disk/by-partlabel/system + +echo "-----> Create swap volume" +lvcreate -y --size $(cat /proc/meminfo | grep MemTotal | cut -d':' -f2 | sed 's/ //g') --name swap system + +echo "-----> Create root volume" +lvcreate -y --size 20G --name root system + +echo "-----> Create nix volume" +lvcreate -y --size 50G --name nix 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" +mkdir -p /mnt +mount -t ext4 /dev/system/root /mnt + +echo "-----> Create nix filesystem" +mkfs.ext4 -L nix /dev/system/nix + +echo "-----> Mount nix filesystem" +mkdir -p /mnt/nix +mount -t ext4 /dev/system/nix /mnt/nix + +echo "-----> Create home filesystem" +mkfs.ext4 -L home /dev/system/home + +echo "-----> Mount home filesystem" +mkdir -p /mnt/home +mount -t ext4 /dev/system/home /mnt/home + +echo "-----> Create boot filesystem" +mkfs.vfat -F32 -n boot /dev/disk/by-partlabel/boot + +echo "-----> Mount boot filesystem" +mkdir -p /mnt/boot +mount /dev/disk/by-label/boot /mnt/boot diff --git a/scripts/asgard-partitions b/servers/asgard/partitions.sh similarity index 99% rename from scripts/asgard-partitions rename to servers/asgard/partitions.sh index 1298582..c27744a 100755 --- a/scripts/asgard-partitions +++ b/servers/asgard/partitions.sh @@ -92,6 +92,10 @@ parted -a opt --script /dev/disk/by-path/pci-0000:00:11.0-ata-4 \ echo "-----> Reload partition table" partprobe +echo "-----> Wait for partitions" +sleep 3 +sync + echo "-----> Create raid0 volume" echo yes | mdadm --create /dev/md0 --level=10 --raid-devices=4 --homehost=asgard --name=md0 /dev/disk/by-partlabel/tank1 /dev/disk/by-partlabel/tank2 /dev/disk/by-partlabel/tank3 /dev/disk/by-partlabel/tank4 wipefs -a /dev/md0 diff --git a/scripts/niflheim-partitions b/servers/niflheim/partitions.sh similarity index 99% rename from scripts/niflheim-partitions rename to servers/niflheim/partitions.sh index ca6e555..f58b9fe 100755 --- a/scripts/niflheim-partitions +++ b/servers/niflheim/partitions.sh @@ -94,6 +94,10 @@ parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-6.0 \ echo "-----> Reload partition table" partprobe +echo "-----> Wait for partitions" +sleep 3 +sync + echo "-----> Create raid0 volume" echo yes | mdadm --create /dev/md0 --level=10 --raid-devices=4 --homehost=niflheim --name=md0 /dev/disk/by-partlabel/tank1 /dev/disk/by-partlabel/tank2 /dev/disk/by-partlabel/tank3 /dev/disk/by-partlabel/tank4 wipefs -a /dev/md0 diff --git a/scripts/utgard-partitions b/servers/utgard/partitions.sh similarity index 98% rename from scripts/utgard-partitions rename to servers/utgard/partitions.sh index ff15a0e..ed50d39 100755 --- a/scripts/utgard-partitions +++ b/servers/utgard/partitions.sh @@ -70,6 +70,10 @@ parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-2.0 \ echo "-----> Reload partition table" partprobe +echo "-----> Wait for partitions" +sleep 3 +sync + echo "-----> Create data pv" pvcreate /dev/disk/by-partlabel/system