Skip to content

Commit

Permalink
lenovo-x1: new disk partitioning scheme
Browse files Browse the repository at this point in the history
New disk configuration provides grounds for upcoming features,
such as AB software updates and Storage VM and many more.

Signed-off-by: Ivan Nikolaenko <[email protected]>
  • Loading branch information
unbel13ver committed Jun 28, 2024
1 parent a5a852c commit bfcb361
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# Devices #
###########

PrivateDevices = true;
# PrivateDevices = true;
# DeviceAllow=/dev/null

##########
Expand Down
160 changes: 160 additions & 0 deletions modules/disko/disko-ab-partitions.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
#
# !!! To utilize this partition scheme, the disk size must be >252G !!!
#
# This partition scheme contains three common partitions and two ZFS pools.
# First LVM pool occupies 250G and second one occupies the rest of the disk space.
# Some paritions are duplicated for the future AB SWupdate implementation.
#
# First three partitions are related to the boot process:
# - boot : Bootloader partition
# - ESP-A : (500M) Kernel and initrd
# - ESP-B : (500M)
#
# First ZFS pool contains next partitions:
# - root-A : (30G) Root FS
# - root-B : (30G)
# - vm-storage-A : (30G) Possible standalone pre-built VM images are stored here
# - vm-storage-B : (30G)
# - reserved-A : (10G) Reserved partition, no use
# - reserved-B : (10G)
# - gp-storage : (50G) General purpose storage for some common insecure cases
# - recovery : (rest of the ZFS pool) Recovery factory image is stored here
#
# Second ZFS pool is dedicated for Storage VM completely.
{pkgs, ...}: {
networking.hostId = "8425e349";
disko = {
memSize = 4096;
extraPostVM = ''
${pkgs.zstd}/bin/zstd --compress $out/*raw
rm $out/*raw
'';
extraRootModules = ["zfs"];
devices = {
disk.disk1 = {
type = "disk";
imageSize = "15G";
content = {
type = "gpt";
partitions = {
boot = {
name = "boot";
size = "1M";
type = "EF02";
priority = 1; # Needs to be first partition
};
esp_a = {
name = "ESP_A";
size = "500M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [
"umask=0077"
"nofail"
];
};
};
esp_b = {
name = "ESP_B";
size = "500M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountOptions = [
"umask=0077"
"nofail"
];
};
};
zfs_1 = {
size = "100%";
content = {
type = "zfs";
pool = "zroot_1";
};
};
};
};
};
zpool = {
zroot_1 = {
type = "zpool";
rootFsOptions = {
mountpoint = "none";
acltype = "posixacl";
};
datasets = {
"root_a" = {
type = "zfs_fs";
mountpoint = "/";
options = {
mountpoint = "/";
quota = "30G";
};
};
"vm_storage_a" = {
type = "zfs_fs";
options = {
mountpoint = "/vm_storage";
quota = "30G";
};
};
"reserved_a" = {
type = "zfs_fs";
options = {
mountpoint = "none";
quota = "10G";
};
};
"root_b" = {
type = "zfs_fs";
options = {
mountpoint = "none";
quota = "30G";
};
};
"vm_storage_b" = {
type = "zfs_fs";
options = {
mountpoint = "none";
quota = "30G";
};
};
"reserved_b" = {
type = "zfs_fs";
options = {
mountpoint = "none";
quota = "10G";
};
};
"gp_storage" = {
type = "zfs_fs";
options = {
mountpoint = "/gp_storage";
quota = "50G";
};
};
"recovery" = {
type = "zfs_fs";
options = {
mountpoint = "none";
};
};
"storagevm" = {
type = "zfs_fs";
options = {
mountpoint = "/storagevm";
};
};
};
};
};
};
};
}
6 changes: 6 additions & 0 deletions modules/disko/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@
./lenovo-x1-disko-basic.nix
./disko-basic-postboot.nix
];

disko-ab-partitions-v1.imports = [
inputs.disko.nixosModules.disko
./disko-ab-partitions.nix
./disko-basic-postboot.nix
];
};
}
7 changes: 7 additions & 0 deletions modules/hardware/lenovo-x1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ in {
# Disk configuration
disko.devices.disk = hwDefinition.disks;

# Hardware specific kernel parameters
boot = {
initrd.availableKernelModules = ["nvme" "zfs"];
supportedFilesystems = ["zfs"];
kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages;
};

# Host udev rules
services.udev.extraRules = ''
# Keyboard
Expand Down
8 changes: 4 additions & 4 deletions targets/lenovo-x1/everything.nix
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@
package = hostConfiguration.config.system.build.diskoImages;
};
in [
(lenovo-x1 "gen10" "debug" [self.nixosModules.disko-lenovo-x1-basic-v1 self.nixosModules.hw-lenovo-x1])
(lenovo-x1 "gen11" "debug" [self.nixosModules.disko-lenovo-x1-basic-v1 self.nixosModules.hw-lenovo-x1])
(lenovo-x1 "gen10" "release" [self.nixosModules.disko-lenovo-x1-basic-v1 self.nixosModules.hw-lenovo-x1])
(lenovo-x1 "gen11" "release" [self.nixosModules.disko-lenovo-x1-basic-v1 self.nixosModules.hw-lenovo-x1])
(lenovo-x1 "gen10" "debug" [self.nixosModules.disko-ab-partitions-v1 self.nixosModules.hw-lenovo-x1])
(lenovo-x1 "gen11" "debug" [self.nixosModules.disko-ab-partitions-v1 self.nixosModules.hw-lenovo-x1])
(lenovo-x1 "gen10" "release" [self.nixosModules.disko-ab-partitions-v1 self.nixosModules.hw-lenovo-x1])
(lenovo-x1 "gen11" "release" [self.nixosModules.disko-ab-partitions-v1 self.nixosModules.hw-lenovo-x1])
]

0 comments on commit bfcb361

Please sign in to comment.