-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
73 lines (55 loc) · 1.87 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
DISK=/dev/nvme0n1
SWAP_SIZE=16G
set -e
######################
# Partition the disk #
######################
#parted $DISK -- mklabel gpt
#parted $DISK -- set 1 esp on
#parted $DISK -- mkpart primary 512MiB 100%
##################################################
# Setup the encrypted LUKS partition and open it #
##################################################
#cryptsetup --verify-passphrase -v luksFormat "$DISK"p2
#cryptsetup config "$DISK"p2 --label cryptroot
#cryptsetup luksOpen "$DISK"p2 enc-pv
###############
# Create LV's #
###############
pvcreate /dev/mapper/enc-pv
vgcreate vg /dev/mapper/enc-pv
lvcreate -L $SWAP_SIZE -n swap vg
lvcreate -l '100%FREE' -n root vg
#####################
# Format Partitions #
#####################
mkfs.fat -F 32 -n boot "$DISK"p1
mkswap -L swap /dev/vg/swap
swapon /dev/vg/swap
mkfs.btrfs -L root /dev/vg/root
#####################
# Create subvolumes #
#####################
mount -t btrfs /dev/vg/root /mnt
# We first create the subvolumes outlined above:
btrfs subvolume create /mnt/root
btrfs subvolume create /mnt/persist
btrfs subvolume create /mnt/nix
btrfs subvolume create /mnt/log
# We then take an empty *readonly* snapshot of the root subvolume,
# which we'll eventually rollback to on every boot.
btrfs subvolume snapshot -r /mnt/root /mnt/root-blank
umount /mnt
#########################
# Mount the directories #
#########################
mount -o subvol=root,compress=zstd,noatime,ssd,space_cache=v2 /dev/vg/root /mnt
mkdir -p /mnt/{persist,nix,var/log}
mount -o subvol=persist,compress=zstd,noatime,ssd,space_cache=v2 /dev/vg/root /mnt/persist
mount -o subvol=nix,compress=zstd,noatime,ssd,space_cache=v2 /dev/vg/root /mnt/nix
mount -o subvol=log,compress=zstd,noatime,ssd,space_cache=v2 /dev/vg/root /mnt/var/log
# Mount boot partition
mkdir /mnt/boot
mount "$DISK"p1 /mnt/boot
echo "All good"
# nixos-generate-config --root /mnt