Created
October 8, 2021 17:24
-
-
Save rvolosatovs/9965dc31e79ec58bd6027c8fb1d7375b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
disk="/dev/nvme0n1" | |
luksName="luksroot" | |
vgName="partitions" | |
btrfsName="butter" | |
swapName="swap" | |
swapSize="72G" | |
rootSub="@" | |
homeSub="@home" | |
snapSub="@snapshots" | |
btrfsMountOpts="autodefrag,noatime,ssd,compress=zstd" | |
subvolumes=( $rootSub $homeSub $snapSub ) | |
bootPart="${disk}p1" | |
luksPart="${disk}p2" | |
echo "Encrypting $luksPart..." | |
cryptsetup luksFormat -v --use-random --verify-passphrase $luksPart || exit 1 | |
cryptsetup luksOpen $luksPart $luksName || exit 1 | |
luksDev="/dev/mapper/$luksName" | |
echo "Setting up LVM on $luksDev..." | |
pvcreate $luksDev || exit 1 | |
vgcreate $vgName $luksDev || exit 1 | |
swapDev="/dev/$vgName/$swapName" | |
echo "Creating swap on $swapDev..." | |
lvcreate -L $swapSize $vgName -n $swapName || exit 1 | |
mkswap -L $swapName $swapDev || exit 1 | |
btrfsDev="/dev/$vgName/$btrfsName" | |
echo "Creating btrfs on $swapDev..." | |
lvcreate -l 100%FREE $vgName -n $btrfsName || exit 1 | |
mkfs.btrfs -L $btrfsName $btrfsDev || exit 1 | |
mount -o $btrfsMountOpts $btrfsDev /mnt || exit 1 | |
for sub in ${subvolumes[@]}; do | |
path="/mnt/$sub" | |
mkdir -pv `dirname $path` || exit 1 | |
btrfs su create $path || exit 1 | |
done | |
umount /mnt | |
echo "Creating vfat on $bootPart..." | |
mkfs.vfat -F 32 -n boot $bootPart || exit 1 | |
mount -o $btrfsMountOpts,subvol=$rootSub $btrfsDev /mnt || exit 1 | |
mkdir -pv /mnt/{home,boot,.snaphots} || exit 1 | |
mount $bootPart /mnt/boot || exit 1 | |
mount -o $btrfsMountOpts,subvol=$homeSub $btrfsDev /mnt/home || exit 1 | |
swapon $swapDev || exit 1 | |
echo "Done, now install nixos" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment