1
0
mirror of https://github.com/tboerger/nixos-config synced 2024-11-26 07:43:45 +01:00

chore: restructure partitioning

This commit is contained in:
Thomas Boerger 2022-11-17 12:00:18 +01:00
parent de3c0f004e
commit 2145a25f35
No known key found for this signature in database
GPG Key ID: 09745AFF9D63C79B
11 changed files with 319 additions and 388 deletions

@ -39,54 +39,91 @@ if [[ -d /dev/md ]]; then
done done
fi fi
echo "----> Drop existing partitions" echo "----> Remove previous MDs"
wipefs -a /dev/disk/by-path/pci-0000:00:14.1-ata-1 || true if [[ -d /dev/md ]]; then
sfdisk --delete /dev/disk/by-path/pci-0000:00:14.1-ata-1 || true for MD in /dev/md/*; do
mdadm --stop $MD
done
fi
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:11.0-ata-1.0 echo "----> Drop existing partitions"
sgdisk -og /dev/disk/by-path/pci-0000:00:11.0-ata-1.0 for DISK in pci-0000:00:14.1-ata-1 pci-0000:00:11.0-ata-1.0 pci-0000:00:11.0-ata-2.0 pci-0000:00:11.0-ata-3.0 pci-0000:00:11.0-ata-4.0; do
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:11.0-ata-2.0 sgdisk --zap-all /dev/disk/by-path/${DISK}
sgdisk -og /dev/disk/by-path/pci-0000:00:11.0-ata-2.0 sgdisk -og /dev/disk/by-path/${DISK}
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:11.0-ata-3.0 done
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" echo "-----> Wait for cleanup"
sleep 3 sleep 3
sync sync
echo "-----> Mark MBR disks" echo "-----> Create sda partitions"
echo yes | parted -s /dev/disk/by-path/pci-0000:00:14.1-ata-1 -- mklabel msdos parted -a opt --script /dev/disk/by-path/pci-0000:00:14.1-ata-1 \
mklabel gpt \
mkpart primary 1MB 1GB \
set 1 bios_grub on \
name 1 boot \
mkpart primary 1GB 100% \
set 2 lvm on \
name 2 system
echo "-----> Create boot partition" echo "-----> Create sdb partitions"
parted /dev/disk/by-path/pci-0000:00:14.1-ata-1 -- mkpart primary ext4 1MB 1GB parted -a opt --script /dev/disk/by-path/pci-0000:00:11.0-ata-1 \
parted /dev/disk/by-path/pci-0000:00:14.1-ata-1 -- set 1 boot on mklabel gpt \
mkpart primary 1GB 100% \
set 1 lvm on \
name 1 tank1
echo "-----> Create root partition" echo "-----> Create sdc partitions"
parted /dev/disk/by-path/pci-0000:00:14.1-ata-1 -- mkpart primary ext4 1GB 100% parted -a opt --script /dev/disk/by-path/pci-0000:00:11.0-ata-2 \
mklabel gpt \
mkpart primary 1GB 100% \
set 1 lvm on \
name 1 tank2
echo "-----> Create tank partition" echo "-----> Create sdd partitions"
sgdisk -n 0:0:0 -t 0:8300 -c 0:tank /dev/disk/by-path/pci-0000:00:11.0-ata-1 parted -a opt --script /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-2 mklabel gpt \
sgdisk -n 0:0:0 -t 0:8300 -c 0:tank /dev/disk/by-path/pci-0000:00:11.0-ata-3 mkpart primary 1GB 100% \
sgdisk -n 0:0:0 -t 0:8300 -c 0:tank /dev/disk/by-path/pci-0000:00:11.0-ata-4 set 1 lvm on \
name 1 tank3
echo "-----> Wait for data" echo "-----> Create sde partitions"
parted -a opt --script /dev/disk/by-path/pci-0000:00:11.0-ata-4 \
mklabel gpt \
mkpart primary 1GB 100% \
set 1 lvm on \
name 1 tank4
echo "-----> Reload partition table"
partprobe
echo "-----> Create raid0 volume"
echo yes | mdadm --create /dev/md0 --level=10 --raid-devices=4 /dev/disk/by-partlabel/tank1 /dev/disk/by-partlabel/tank2 /dev/disk/by-partlabel/tank3 /dev/disk/by-partlabel/tank4
echo "-----> Wait for raids"
sleep 3 sleep 3
sync sync
echo "-----> Create data pv" echo "-----> Create data pv"
pvcreate /dev/disk/by-path/pci-0000:00:14.1-ata-1-part2 pvcreate /dev/disk/by-partlabel/system
echo "-----> Create data vg" echo "-----> Create data vg"
vgcreate system /dev/disk/by-path/pci-0000:00:14.1-ata-1-part2 vgcreate system /dev/disk/by-partlabel/system
echo "-----> Create tank pv"
pvcreate /dev/md0
echo "-----> Create tank vg"
vgcreate tank /dev/md0
echo "-----> Create swap volume" echo "-----> Create swap volume"
lvcreate -y --size 24G --name swap system lvcreate -y --size $(cat /proc/meminfo | grep MemTotal | cut -d':' -f2 | sed 's/ //g') --name swap system
echo "-----> Create root volume" echo "-----> Create root volume"
lvcreate -y --size 50G --name root system lvcreate -y --size 20G --name root system
echo "-----> Create nix volume"
lvcreate -y --size 50G --name nix system
echo "-----> Create home volume" echo "-----> Create home volume"
lvcreate -y --size 50G --name home system lvcreate -y --size 50G --name home system
@ -99,42 +136,45 @@ echo "-----> Create root filesystem"
mkfs.ext4 -L root /dev/system/root mkfs.ext4 -L root /dev/system/root
echo "-----> Mount root filesystem" echo "-----> Mount root filesystem"
mkdir -p /mnt
mount -t ext4 /dev/system/root /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" echo "-----> Create home filesystem"
mkfs.ext4 -L home /dev/system/home mkfs.ext4 -L home /dev/system/home
echo "-----> Mount home filesystem" echo "-----> Mount home filesystem"
mkdir /mnt/home mkdir -p /mnt/home
mount -t ext4 /dev/system/home /mnt/home mount -t ext4 /dev/system/home /mnt/home
echo "-----> Create boot filesystem" echo "-----> Create boot filesystem"
mkfs.ext4 -L boot /dev/disk/by-path/pci-0000:00:14.1-ata-1-part1 mkfs.ext4 -L boot /dev/disk/by-partlabel/boot1
echo "-----> Mount boot filesystem" echo "-----> Mount boot filesystem"
mkdir /mnt/boot mkdir -p /mnt/boot
mount /dev/disk/by-path/pci-0000:00:14.1-ata-1-part1 /mnt/boot mount /dev/disk/by-partlabel/boot1 /mnt/boot
echo "-----> Wait for filesystems" #
sleep 3 # STORAGE
sync #
echo "----> Remove previous MDs" for PARTITION in ; do
if [[ -d /dev/md ]]; then echo "-----> Create ${PARTITION} volume"
for MD in /dev/md/*; do lvcreate -y --size 5G --name ${PARTITION} system
mdadm --stop $MD
done
fi
echo "-----> Create raid volume" echo "-----> Create ${PARTITION} filesystem"
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 mkfs.ext4 -L ${PARTITION} /dev/system/${PARTITION}
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" echo "-----> Mount ${PARTITION} filesystem"
pvcreate /dev/md0 /dev/md1 mkdir /mnt/var/lib/${PARTITION}
mount -t ext4 /dev/system/${PARTITION} /mnt/var/lib/${PARTITION}
echo "-----> Create tank vg" done
vgcreate tank /dev/md0 /dev/md1
echo "-----> Create shares volume" echo "-----> Create shares volume"
lvcreate -y --size 10G --name shares tank lvcreate -y --size 10G --name shares tank
@ -143,9 +183,8 @@ echo "-----> Create shares filesystem"
mkfs.ext4 -L shares /dev/tank/shares mkfs.ext4 -L shares /dev/tank/shares
echo "-----> Mount shares filesystem" echo "-----> Mount shares filesystem"
mkdir -p /mnt/var/lib/media/shares mkdir -p /mnt/var/lib/shares
mount -t ext4 /dev/tank/shares /mnt/var/lib/media/shares mount -t ext4 /dev/tank/shares /mnt/var/lib/shares
chown 20000:20000 /mnt/var/lib/media/shares
echo "-----> Create photos volume" echo "-----> Create photos volume"
lvcreate -y --size 100G --name photos tank lvcreate -y --size 100G --name photos tank
@ -154,9 +193,8 @@ echo "-----> Create photos filesystem"
mkfs.ext4 -L photos /dev/tank/photos mkfs.ext4 -L photos /dev/tank/photos
echo "-----> Mount photos filesystem" echo "-----> Mount photos filesystem"
mkdir -p /mnt/var/lib/media/photos mkdir -p /mnt/var/lib/photos
mount -t ext4 /dev/tank/photos /mnt/var/lib/media/photos mount -t ext4 /dev/tank/photos /mnt/var/lib/photos
chown 20000:20000 /mnt/var/lib/media/photos
echo "-----> Create videos volume" echo "-----> Create videos volume"
lvcreate -y --size 100G --name videos tank lvcreate -y --size 100G --name videos tank
@ -165,56 +203,11 @@ echo "-----> Create videos filesystem"
mkfs.ext4 -L videos /dev/tank/videos mkfs.ext4 -L videos /dev/tank/videos
echo "-----> Mount videos filesystem" echo "-----> Mount videos filesystem"
mkdir -p /mnt/var/lib/media/videos mkdir -p /mnt/var/lib/videos
mount -t ext4 /dev/tank/videos /mnt/var/lib/media/videos mount -t ext4 /dev/tank/videos /mnt/var/lib/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" echo "-----> Create printer volume"
lvcreate -y --size 5G --name printer tank lvcreate -y --size 10G --name printer tank
echo "-----> Create printer filesystem" echo "-----> Create printer filesystem"
mkfs.ext4 -L printer /dev/tank/printer mkfs.ext4 -L printer /dev/tank/printer
@ -222,10 +215,9 @@ mkfs.ext4 -L printer /dev/tank/printer
echo "-----> Mount printer filesystem" echo "-----> Mount printer filesystem"
mkdir -p /mnt/var/lib/printer mkdir -p /mnt/var/lib/printer
mount -t ext4 /dev/tank/printer /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" echo "-----> Create backup volume"
lvcreate -y --size 50G --name backup tank lvcreate -y --size 1000G --name backup tank
echo "-----> Create backup filesystem" echo "-----> Create backup filesystem"
mkfs.ext4 -L backup /dev/tank/backup mkfs.ext4 -L backup /dev/tank/backup

@ -32,33 +32,48 @@ for PV in $(pvs --noheadings 2>/dev/null | sed -e 's/^[[:space:]]*//' | cut -d"
pvremove -y ${PV} 2>/dev/null pvremove -y ${PV} 2>/dev/null
done done
echo "----> Remove previous MDs"
if [[ -d /dev/md ]]; then
for MD in /dev/md/*; do
mdadm --stop $MD
done
fi
echo "----> Remove previous MDs"
if [[ -d /dev/md ]]; then
for MD in /dev/md/*; do
mdadm --stop $MD
done
fi
echo "----> Drop existing partitions" echo "----> Drop existing partitions"
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:1f.2-ata-1.0 for DISK in pci-0000:00:1f.2-ata-1.0; do
sgdisk -og /dev/disk/by-path/pci-0000:00:1f.2-ata-1.0 sgdisk --zap-all /dev/disk/by-path/${DISK}
sgdisk -og /dev/disk/by-path/${DISK}
done
echo "-----> Wait for cleanup" echo "-----> Wait for cleanup"
sleep 3 sleep 3
sync sync
echo "-----> Create sda partitions" echo "-----> Create sda partitions"
parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-1.0 \ parted -a opt --script /dev/disk/by-path/pci-0000:00:14.1-ata-1 \
mklabel gpt \ mklabel gpt \
mkpart primary fat32 0% 1GiB \ mkpart primary fat32 0% 1GB \
mkpart primary 1GiB 100% \
set 1 esp on \ set 1 esp on \
name 1 boot \ name 1 boot \
mkpart primary 1GB 100% \
set 2 lvm on \ set 2 lvm on \
name 2 data name 2 system
echo "-----> Wait for partitions" echo "-----> Reload partition table"
sleep 3 partprobe
sync
echo "-----> Create data pv" echo "-----> Create data pv"
pvcreate /dev/disk/by-partlabel/data pvcreate /dev/disk/by-partlabel/system
echo "-----> Create data vg" echo "-----> Create data vg"
vgcreate system /dev/disk/by-partlabel/data vgcreate system /dev/disk/by-partlabel/system
echo "-----> Create swap volume" echo "-----> Create swap volume"
lvcreate -y --size $(cat /proc/meminfo | grep MemTotal | cut -d':' -f2 | sed 's/ //g') --name swap system lvcreate -y --size $(cat /proc/meminfo | grep MemTotal | cut -d':' -f2 | sed 's/ //g') --name swap system
@ -80,25 +95,42 @@ echo "-----> Create root filesystem"
mkfs.ext4 -L root /dev/system/root mkfs.ext4 -L root /dev/system/root
echo "-----> Mount root filesystem" echo "-----> Mount root filesystem"
mkdir -p /mnt
mount -t ext4 /dev/system/root /mnt mount -t ext4 /dev/system/root /mnt
echo "-----> Create nix filesystem" echo "-----> Create nix filesystem"
mkfs.ext4 -L nix /dev/system/nix mkfs.ext4 -L nix /dev/system/nix
echo "-----> Mount nix filesystem" echo "-----> Mount nix filesystem"
mkdir /mnt/nix mkdir -p /mnt/nix
mount -t ext4 /dev/system/nix /mnt/nix mount -t ext4 /dev/system/nix /mnt/nix
echo "-----> Create home filesystem" echo "-----> Create home filesystem"
mkfs.ext4 -L home /dev/system/home mkfs.ext4 -L home /dev/system/home
echo "-----> Mount home filesystem" echo "-----> Mount home filesystem"
mkdir /mnt/home mkdir -p /mnt/home
mount -t ext4 /dev/system/home /mnt/home mount -t ext4 /dev/system/home /mnt/home
echo "-----> Create boot filesystem" echo "-----> Create boot filesystem"
mkfs.vfat -F32 -n boot /dev/disk/by-partlabel/boot mkfs.vfat -F32 -n boot /dev/disk/by-partlabel/boot
echo "-----> Mount boot filesystem" echo "-----> Mount boot filesystem"
mkdir /mnt/boot mkdir -p /mnt/boot
mount /dev/disk/by-label/boot /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

@ -32,15 +32,18 @@ for PV in $(pvs --noheadings 2>/dev/null | sed -e 's/^[[:space:]]*//' | cut -d"
pvremove -y ${PV} 2>/dev/null pvremove -y ${PV} 2>/dev/null
done 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" echo "----> Drop existing partitions"
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:1f.2-ata-3.0 for DISK in pci-0000:00:1f.2-ata-3.0 pci-0000:00:1f.2-ata-4.0 pci-0000:00:1f.2-ata-5.0 pci-0000:00:1f.2-ata-6.0; do
sgdisk -og /dev/disk/by-path/pci-0000:00:1f.2-ata-3.0 sgdisk --zap-all /dev/disk/by-path/${DISK}
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:1f.2-ata-4.0 sgdisk -og /dev/disk/by-path/${DISK}
sgdisk -og /dev/disk/by-path/pci-0000:00:1f.2-ata-4.0 done
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:1f.2-ata-5.0
sgdisk -og /dev/disk/by-path/pci-0000:00:1f.2-ata-5.0
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:1f.2-ata-6.0
sgdisk -og /dev/disk/by-path/pci-0000:00:1f.2-ata-6.0
echo "-----> Wait for cleanup" echo "-----> Wait for cleanup"
sleep 3 sleep 3
@ -49,47 +52,50 @@ sync
echo "-----> Create sda partitions" echo "-----> Create sda partitions"
parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-3.0 \ parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-3.0 \
mklabel gpt \ mklabel gpt \
mkpart primary fat32 0% 1GiB \ mkpart primary 1MB 1GB \
mkpart primary 1GiB 100% \ set 1 bios_grub on \
set 1 esp on \
name 1 boot1 \ name 1 boot1 \
mkpart primary 1GB 100% \
set 2 lvm on \ set 2 lvm on \
name 2 tank1 name 2 tank1
echo "-----> Create sdb partitions" echo "-----> Create sdb partitions"
parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-4.0 \ parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-4.0 \
mklabel gpt \ mklabel gpt \
mkpart primary fat32 0% 1GiB \ mkpart primary 1MB 1GB \
mkpart primary 1GiB 100% \ set 1 bios_grub on \
set 1 esp on \
name 1 boot2 \ name 1 boot2 \
mkpart primary 1GB 100% \
set 2 lvm on \ set 2 lvm on \
name 2 tank2 name 2 tank2
echo "-----> Create sdc partitions" echo "-----> Create sdc partitions"
parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-5.0 \ parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-5.0 \
mklabel gpt \ mklabel gpt \
mkpart primary fat32 0% 1GiB \ mkpart primary 1MB 1GB \
mkpart primary 1GiB 100% \ set 1 bios_grub on \
set 1 esp on \
name 1 boot3 \ name 1 boot3 \
mkpart primary 1GB 100% \
set 2 lvm on \ set 2 lvm on \
name 2 tank3 name 2 tank3
echo "-----> Create sdd partitions" echo "-----> Create sdd partitions"
parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-6.0 \ parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-6.0 \
mklabel gpt \ mklabel gpt \
mkpart primary fat32 0% 1GiB \ mkpart primary 1MB 1GB \
mkpart primary 1GiB 100% \ set 1 bios_grub on \
set 1 esp on \
name 1 boot4 \ name 1 boot4 \
mkpart primary 1GB 100% \
set 2 lvm on \ set 2 lvm on \
name 2 tank4 name 2 tank4
echo "-----> Create raid10 volume" echo "-----> Reload partition table"
partprobe
echo "-----> Create raid0 volume"
echo yes | mdadm --create /dev/md0 --level=10 --raid-devices=4 /dev/disk/by-partlabel/tank1 /dev/disk/by-partlabel/tank2 /dev/disk/by-partlabel/tank3 /dev/disk/by-partlabel/tank4 echo yes | mdadm --create /dev/md0 --level=10 --raid-devices=4 /dev/disk/by-partlabel/tank1 /dev/disk/by-partlabel/tank2 /dev/disk/by-partlabel/tank3 /dev/disk/by-partlabel/tank4
echo "-----> Wait for partitions" echo "-----> Wait for raids"
sleep 3 sleep 3
sync sync
@ -103,13 +109,13 @@ echo "-----> Create swap volume"
lvcreate -y --size $(cat /proc/meminfo | grep MemTotal | cut -d':' -f2 | sed 's/ //g') --name swap system lvcreate -y --size $(cat /proc/meminfo | grep MemTotal | cut -d':' -f2 | sed 's/ //g') --name swap system
echo "-----> Create root volume" echo "-----> Create root volume"
lvcreate -y --size 10G --name root system lvcreate -y --size 20G --name root system
echo "-----> Create nix volume" echo "-----> Create nix volume"
lvcreate -y --size 45G --name nix system lvcreate -y --size 50G --name nix system
echo "-----> Create home volume" echo "-----> Create home volume"
lvcreate -y --size 1G --name home system lvcreate -y --size 50G --name home system
echo "-----> Enable swap partition" echo "-----> Enable swap partition"
mkswap -L swap /dev/system/swap mkswap -L swap /dev/system/swap
@ -137,11 +143,27 @@ mkdir -p /mnt/home
mount -t ext4 /dev/system/home /mnt/home mount -t ext4 /dev/system/home /mnt/home
echo "-----> Create boot filesystem" echo "-----> Create boot filesystem"
mkfs.vfat -F32 -n boot1 /dev/disk/by-partlabel/boot1 mkfs.ext4 -L boot /dev/disk/by-partlabel/boot1
echo "-----> Mount boot filesystem" echo "-----> Mount boot filesystem"
mkdir -p /mnt/boot mkdir -p /mnt/boot
mount /dev/disk/by-label/boot1 /mnt/boot mount /dev/disk/by-partlabel/boot1 /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
echo "-----> Create movies volume" echo "-----> Create movies volume"
lvcreate -y --size 2000G --name movies system lvcreate -y --size 2000G --name movies system

@ -32,11 +32,25 @@ for PV in $(pvs --noheadings 2>/dev/null | sed -e 's/^[[:space:]]*//' | cut -d"
pvremove -y ${PV} 2>/dev/null pvremove -y ${PV} 2>/dev/null
done done
echo "----> Remove previous MDs"
if [[ -d /dev/md ]]; then
for MD in /dev/md/*; do
mdadm --stop $MD
done
fi
echo "----> Remove previous MDs"
if [[ -d /dev/md ]]; then
for MD in /dev/md/*; do
mdadm --stop $MD
done
fi
echo "----> Drop existing partitions" echo "----> Drop existing partitions"
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:1f.2-ata-1.0 for DISK in pci-0000:00:1f.2-ata-1.0 pci-0000:00:1f.2-ata-2.0; do
sgdisk -og /dev/disk/by-path/pci-0000:00:1f.2-ata-1.0 sgdisk --zap-all /dev/disk/by-path/${DISK}
sgdisk --zap-all /dev/disk/by-path/pci-0000:00:1f.2-ata-2.0 sgdisk -og /dev/disk/by-path/${DISK}
sgdisk -og /dev/disk/by-path/pci-0000:00:1f.2-ata-2.0 done
echo "-----> Wait for cleanup" echo "-----> Wait for cleanup"
sleep 3 sleep 3
@ -45,29 +59,34 @@ sync
echo "-----> Create sda partitions" echo "-----> Create sda partitions"
parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-1.0 \ parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-1.0 \
mklabel gpt \ mklabel gpt \
mkpart primary fat32 0% 1GiB \ mkpart primary fat32 0% 1GB \
mkpart primary 1GiB 100% \
set 1 esp on \ set 1 esp on \
name 1 boot \ name 1 boot \
mkpart primary 1GB 100% \
set 2 lvm on \ set 2 lvm on \
name 2 data name 2 system
echo "-----> Create sdb partitions" echo "-----> Create sdb partitions"
parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-2.0 \ parted -a opt --script /dev/disk/by-path/pci-0000:00:1f.2-ata-2.0 \
mklabel gpt \ mklabel gpt \
mkpart primary 0% 100% \ mkpart primary 0% 100% \
set 1 lvm on \ set 1 lvm on \
name 1 tank1 name 1 tank
echo "-----> Wait for partitions" echo "-----> Reload partition table"
sleep 3 partprobe
sync
echo "-----> Create data pv" echo "-----> Create data pv"
pvcreate /dev/disk/by-partlabel/data pvcreate /dev/disk/by-partlabel/system
echo "-----> Create data vg" echo "-----> Create data vg"
vgcreate system /dev/disk/by-partlabel/data vgcreate system /dev/disk/by-partlabel/system
echo "-----> Create tank pv"
pvcreate /dev/disk/by-partlabel/tank
echo "-----> Create tank vg"
vgcreate tank /dev/disk/by-partlabel/tank
echo "-----> Create swap volume" echo "-----> Create swap volume"
lvcreate -y --size $(cat /proc/meminfo | grep MemTotal | cut -d':' -f2 | sed 's/ //g') --name swap system lvcreate -y --size $(cat /proc/meminfo | grep MemTotal | cut -d':' -f2 | sed 's/ //g') --name swap system
@ -89,54 +108,42 @@ echo "-----> Create root filesystem"
mkfs.ext4 -L root /dev/system/root mkfs.ext4 -L root /dev/system/root
echo "-----> Mount root filesystem" echo "-----> Mount root filesystem"
mkdir -p /mnt
mount -t ext4 /dev/system/root /mnt mount -t ext4 /dev/system/root /mnt
echo "-----> Create nix filesystem" echo "-----> Create nix filesystem"
mkfs.ext4 -L nix /dev/system/nix mkfs.ext4 -L nix /dev/system/nix
echo "-----> Mount nix filesystem" echo "-----> Mount nix filesystem"
mkdir /mnt/nix mkdir -p /mnt/nix
mount -t ext4 /dev/system/nix /mnt/nix mount -t ext4 /dev/system/nix /mnt/nix
echo "-----> Create home filesystem" echo "-----> Create home filesystem"
mkfs.ext4 -L home /dev/system/home mkfs.ext4 -L home /dev/system/home
echo "-----> Mount home filesystem" echo "-----> Mount home filesystem"
mkdir /mnt/home mkdir -p /mnt/home
mount -t ext4 /dev/system/home /mnt/home mount -t ext4 /dev/system/home /mnt/home
echo "-----> Create boot filesystem" echo "-----> Create boot filesystem"
mkfs.vfat -F32 -n boot /dev/disk/by-partlabel/boot mkfs.vfat -F32 -n boot /dev/disk/by-partlabel/boot
echo "-----> Mount boot filesystem" echo "-----> Mount boot filesystem"
mkdir /mnt/boot mkdir -p /mnt/boot
mount /dev/disk/by-label/boot /mnt/boot mount /dev/disk/by-label/boot /mnt/boot
echo "-----> Create tank pv" #
pvcreate /dev/disk/by-partlabel/tank1 # STORAGE
#
echo "-----> Create tank vg" for PARTITION in acme hass; do
vgcreate tank /dev/disk/by-partlabel/tank1
echo "-----> Create downloads volume"
lvcreate -y --size 200G --name downloads tank
echo "-----> Create downloads filesystem"
mkfs.ext4 -L downloads /dev/tank/downloads
echo "-----> Mount downloads filesystem"
mkdir -p /mnt/var/lib/downloads
mount -t ext4 /dev/tank/downloads /mnt/var/lib/downloads
chown 20000:20000 /mnt/var/lib/downloads
for PARTITION in acme nzbget jellyfin bazarr lidarr prowlarr radarr readarr sonarr hass; do
echo "-----> Create ${PARTITION} volume" echo "-----> Create ${PARTITION} volume"
lvcreate -y --size 5G --name ${PARTITION} tank lvcreate -y --size 5G --name ${PARTITION} system
echo "-----> Create ${PARTITION} filesystem" echo "-----> Create ${PARTITION} filesystem"
mkfs.ext4 -L ${PARTITION} /dev/tank/${PARTITION} mkfs.ext4 -L ${PARTITION} /dev/system/${PARTITION}
echo "-----> Mount ${PARTITION} filesystem" echo "-----> Mount ${PARTITION} filesystem"
mkdir /mnt/var/lib/${PARTITION} mkdir /mnt/var/lib/${PARTITION}
mount -t ext4 /dev/tank/${PARTITION} /mnt/var/lib/${PARTITION} mount -t ext4 /dev/system/${PARTITION} /mnt/var/lib/${PARTITION}
done done

@ -15,8 +15,12 @@
grub = { grub = {
enable = true; enable = true;
version = 2; version = 2;
device = "/dev/disk/by-path/pci-0000:00:14.1-ata-1";
efiSupport = false; efiSupport = false;
copyKernels = true;
devices = [
"/dev/disk/by-path/pci-0000:00:14.1-ata-1"
];
}; };
}; };

@ -13,13 +13,13 @@
]; ];
}; };
# fileSystems."/nix" = { fileSystems."/nix" = {
# device = "/dev/disk/by-label/nix"; device = "/dev/disk/by-label/nix";
# fsType = "ext4"; fsType = "ext4";
# options = [ options = [
# "noatime" "noatime"
# ]; ];
# }; };
fileSystems."/home" = { fileSystems."/home" = {
device = "/dev/disk/by-label/home"; device = "/dev/disk/by-label/home";
@ -30,7 +30,7 @@
}; };
fileSystems."/boot" = { fileSystems."/boot" = {
device = "/dev/disk/by-label/boot"; device = "/dev/disk/by-label/boot1";
fsType = "ext4"; fsType = "ext4";
options = [ options = [
"noatime" "noatime"
@ -82,66 +82,6 @@
]; ];
}; };
fileSystems."/var/lib/movies" = {
device = "/dev/disk/by-label/movies";
fsType = "ext4";
options = [
"noatime"
];
};
fileSystems."/exports/movies" = {
device = "/var/lib/movies";
options = [
"bind"
];
};
fileSystems."/var/lib/shows" = {
device = "/dev/disk/by-label/shows";
fsType = "ext4";
options = [
"noatime"
];
};
fileSystems."/exports/shows" = {
device = "/var/lib/shows";
options = [
"bind"
];
};
fileSystems."/var/lib/books" = {
device = "/dev/disk/by-label/books";
fsType = "ext4";
options = [
"noatime"
];
};
fileSystems."/exports/books" = {
device = "/var/lib/books";
options = [
"bind"
];
};
fileSystems."/var/lib/music" = {
device = "/dev/disk/by-label/music";
fsType = "ext4";
options = [
"noatime"
];
};
fileSystems."/exports/music" = {
device = "/var/lib/music";
options = [
"bind"
];
};
fileSystems."/var/lib/printer" = { fileSystems."/var/lib/printer" = {
device = "/dev/disk/by-label/printer"; device = "/dev/disk/by-label/printer";
fsType = "ext4"; fsType = "ext4";
@ -164,4 +104,11 @@
"noatime" "noatime"
]; ];
}; };
fileSystems."/exports/backup" = {
device = "/var/lib/backup";
options = [
"bind"
];
};
} }

@ -12,23 +12,26 @@
cleanTmpDir = true; cleanTmpDir = true;
loader = { loader = {
efi = { grub = {
canTouchEfiVariables = true;
};
systemd-boot = {
enable = true; enable = true;
consoleMode = "2"; version = 2;
configurationLimit = 5; efiSupport = false;
editor = false; copyKernels = true;
devices = [
"/dev/disk/by-path/pci-0000:00:1f.2-ata-3.0"
"/dev/disk/by-path/pci-0000:00:1f.2-ata-4.0"
"/dev/disk/by-path/pci-0000:00:1f.2-ata-5.0"
"/dev/disk/by-path/pci-0000:00:1f.2-ata-6.0"
];
}; };
}; };
kernelModules = [ ]; kernelModules = [ "kvm-intel" ];
extraModulePackages = [ ]; extraModulePackages = [ ];
initrd = { initrd = {
availableKernelModules = [ "xhci_pci" "uhci_hcd" "ehci_pci" "ahci" "usbhid" "sd_mod" "sr_mod" ]; availableKernelModules = [ "ehci_pci" "ahci" "sd_mod" ];
kernelModules = [ "dm-snapshot" ]; kernelModules = [ "dm-snapshot" ];
}; };
}; };

@ -31,6 +31,41 @@
fileSystems."/boot" = { fileSystems."/boot" = {
device = "/dev/disk/by-label/boot1"; device = "/dev/disk/by-label/boot1";
fsType = "vfat"; fsType = "ext4";
options = [
"noatime"
];
};
fileSystems."/var/lib/movies" = {
device = "/dev/disk/by-label/movies";
fsType = "ext4";
options = [
"noatime"
];
};
fileSystems."/var/lib/shows" = {
device = "/dev/disk/by-label/shows";
fsType = "ext4";
options = [
"noatime"
];
};
fileSystems."/var/lib/books" = {
device = "/dev/disk/by-label/books";
fsType = "ext4";
options = [
"noatime"
];
};
fileSystems."/var/lib/music" = {
device = "/dev/disk/by-label/music";
fsType = "ext4";
options = [
"noatime"
];
}; };
} }

@ -2,7 +2,7 @@
{ {
imports = [ imports = [
(modulesPath + "/profiles/qemu-guest.nix") (modulesPath + "/installer/scan/not-detected.nix")
]; ];
hardware = { hardware = {

@ -3,19 +3,29 @@
{ {
networking = { networking = {
hostName = "niflheim"; hostName = "niflheim";
defaultGateway = "192.168.64.1"; defaultGateway = "176.9.93.193";
defaultGateway6 = "fe80::1";
nameservers = [ nameservers = [
"1.1.1.1" "1.1.1.1"
"8.8.8.8" "8.8.8.8"
"2a01:4ff:ff00::add:1"
"2a01:4ff:ff00::add:2"
]; ];
interfaces = { interfaces = {
enp0s1 = { enp3s0 = {
ipv4 = { ipv4 = {
addresses = [{ addresses = [{
address = "192.168.64.4"; address = "176.9.93.214";
prefixLength = 24; prefixLength = 27;
}];
};
ipv6 = {
addresses = [{
address = "2a01:4f8:151:34ba::2";
prefixLength = 64;
}]; }];
}; };
}; };

@ -1,22 +1,6 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let
nfsOptions = [
"x-systemd.automount"
"noauto"
"x-systemd.idle-timeout=60"
"x-systemd.device-timeout=5s"
"x-systemd.mount-timeout=5s"
"nfsvers=4.2"
];
in
{ {
environment = {
systemPackages = with pkgs; [
nfs-utils
];
};
swapDevices = [{ swapDevices = [{
device = "/dev/disk/by-label/swap"; device = "/dev/disk/by-label/swap";
}]; }];
@ -62,78 +46,6 @@ in
]; ];
}; };
fileSystems."/var/lib/nzbget" = {
device = "/dev/disk/by-label/nzbget";
fsType = "ext4";
options = [
"noatime"
"discard"
];
};
fileSystems."/var/lib/jellyfin" = {
device = "/dev/disk/by-label/jellyfin";
fsType = "ext4";
options = [
"noatime"
"discard"
];
};
fileSystems."/var/lib/bazarr" = {
device = "/dev/disk/by-label/bazarr";
fsType = "ext4";
options = [
"noatime"
"discard"
];
};
fileSystems."/var/lib/lidarr" = {
device = "/dev/disk/by-label/lidarr";
fsType = "ext4";
options = [
"noatime"
"discard"
];
};
fileSystems."/var/lib/prowlarr" = {
device = "/dev/disk/by-label/prowlarr";
fsType = "ext4";
options = [
"noatime"
"discard"
];
};
fileSystems."/var/lib/radarr" = {
device = "/dev/disk/by-label/radarr";
fsType = "ext4";
options = [
"noatime"
"discard"
];
};
fileSystems."/var/lib/readarr" = {
device = "/dev/disk/by-label/readarr";
fsType = "ext4";
options = [
"noatime"
"discard"
];
};
fileSystems."/var/lib/sonarr" = {
device = "/dev/disk/by-label/sonarr";
fsType = "ext4";
options = [
"noatime"
"discard"
];
};
fileSystems."/var/lib/hass" = { fileSystems."/var/lib/hass" = {
device = "/dev/disk/by-label/hass"; device = "/dev/disk/by-label/hass";
fsType = "ext4"; fsType = "ext4";
@ -142,37 +54,4 @@ in
"discard" "discard"
]; ];
}; };
fileSystems."/var/lib/downloads" = {
device = "/dev/disk/by-label/downloads";
fsType = "ext4";
options = [
"noatime"
"discard"
];
};
fileSystems."/var/lib/movies" = {
device = "192.168.1.10:/movies";
fsType = "nfs";
options = nfsOptions;
};
fileSystems."/var/lib/shows" = {
device = "192.168.1.10:/shows";
fsType = "nfs";
options = nfsOptions;
};
fileSystems."/var/lib/books" = {
device = "192.168.1.10:/books";
fsType = "nfs";
options = nfsOptions;
};
fileSystems."/var/lib/music" = {
device = "192.168.1.10:/music";
fsType = "nfs";
options = nfsOptions;
};
} }