Skip to content

Commit

Permalink
add option to disable compression in image builder
Browse files Browse the repository at this point in the history
This allows to incrementally update installations on usb-sticks without
having to go through the process of creating slow images.

Signed-off-by: Jörg Thalheim <[email protected]>
  • Loading branch information
Mic92 authored and brianmcgillion committed Nov 21, 2024
1 parent fb6c75b commit 2b51600
Showing 1 changed file with 123 additions and 105 deletions.
228 changes: 123 additions & 105 deletions modules/disko/disko-ab-partitions.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,126 +18,144 @@
# - gp-storage : (50G) General purpose storage for some common insecure cases
# - recovery : (no quota) Recovery factory image is stored here
# - storagevm: (no quota) Dataset is meant to be used for StorageVM
{ pkgs, ... }:
{
# TODO Keep ZFS-related parts of the configuration here for now.
# This allows to have all config dependencies in one place and cleans
# other targets' configs from unnecessary components.
networking.hostId = "8425e349";
boot = {
initrd.availableKernelModules = [ "zfs" ];
supportedFilesystems = [ "zfs" ];
pkgs,
lib,
config,
...
}:
{

options = {
ghaf.imageBuilder.compression = lib.mkOption {
type = lib.types.enum [
"none"
"zstd"
];
description = "Compression algorithm used for the install image";
default = "zstd";
};
};
disko = {
# 8GB is the recommeneded minimum for ZFS, so we are using this for VMs to avoid `cp` oom errors.
memSize = 17384;
imageBuilder = {
extraPostVM = ''
${pkgs.zstd}/bin/zstd --compress $out/*raw
rm $out/*raw
'';
config = {
# TODO Keep ZFS-related parts of the configuration here for now.
# This allows to have all config dependencies in one place and cleans
# other targets' configs from unnecessary components.
networking.hostId = "8425e349";
boot = {
initrd.availableKernelModules = [ "zfs" ];
supportedFilesystems = [ "zfs" ];
};
devices = {
disk.disk1 = {
type = "disk";
imageSize = "60G";
content = {
type = "gpt";
partitions = {
boot = {
name = "boot";
size = "1M";
type = "EF02";
priority = 1; # Needs to be first partition
};
esp = {
name = "ESP";
size = "500M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [
"umask=0077"
"nofail"
];
disko = {
# 8GB is the recommeneded minimum for ZFS, so we are using this for VMs to avoid `cp` oom errors.
memSize = 17384;
imageBuilder = {
extraPostVM = lib.mkIf (config.ghaf.imageBuilder.compression == "zstd") ''
${pkgs.zstd}/bin/zstd --compress $out/*raw
rm $out/*raw
'';
};
devices = {
disk.disk1 = {
type = "disk";
imageSize = "60G";
content = {
type = "gpt";
partitions = {
boot = {
name = "boot";
size = "1M";
type = "EF02";
priority = 1; # Needs to be first partition
};
};
swap = {
size = "38G";
type = "8200";
content = {
type = "swap";
resumeDevice = true; # resume from hiberation from this device
# TODO: remove when LUKS is enabled
#randomEncryption = true;
esp = {
name = "ESP";
size = "500M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [
"umask=0077"
"nofail"
];
};
};
};
zfs_1 = {
size = "100%";
content = {
type = "zfs";
pool = "zfspool";
swap = {
size = "38G";
type = "8200";
content = {
type = "swap";
resumeDevice = true; # resume from hiberation from this device
# TODO: remove when LUKS is enabled
#randomEncryption = true;
};
};
zfs_1 = {
size = "100%";
content = {
type = "zfs";
pool = "zfspool";
};
};
};
};
};
};
zpool = {
zfspool = {
type = "zpool";
rootFsOptions = {
mountpoint = "none";
acltype = "posixacl";
compression = "lz4";
xattr = "sa";
};
# `ashift=12` optimizes alignment for 4K sector size.
# Since this is an generic image and people might upgrade from one nvme device to another,
# we should make sure it runs well on these devices, also in theory 512B would work with less.
# This trades off some space overhead for overall better performance on 4k devices.
options.ashift = "12";
datasets = {
"root" = {
type = "zfs_fs";
mountpoint = "/";
options = {
zpool = {
zfspool = {
type = "zpool";
rootFsOptions = {
mountpoint = "none";
acltype = "posixacl";
compression = "lz4";
xattr = "sa";
};
# `ashift=12` optimizes alignment for 4K sector size.
# Since this is an generic image and people might upgrade from one nvme device to another,
# we should make sure it runs well on these devices, also in theory 512B would work with less.
# This trades off some space overhead for overall better performance on 4k devices.
options.ashift = "12";
datasets = {
"root" = {
type = "zfs_fs";
mountpoint = "/";
quota = "30G";
options = {
mountpoint = "/";
quota = "30G";
};
};
};
"vm_storage" = {
type = "zfs_fs";
options = {
mountpoint = "/vm_storage";
quota = "30G";
"vm_storage" = {
type = "zfs_fs";
options = {
mountpoint = "/vm_storage";
quota = "30G";
};
};
};
"reserved" = {
type = "zfs_fs";
options = {
mountpoint = "none";
quota = "10G";
"reserved" = {
type = "zfs_fs";
options = {
mountpoint = "none";
quota = "10G";
};
};
};
"gp_storage" = {
type = "zfs_fs";
options = {
mountpoint = "/gp_storage";
quota = "50G";
"gp_storage" = {
type = "zfs_fs";
options = {
mountpoint = "/gp_storage";
quota = "50G";
};
};
};
"recovery" = {
type = "zfs_fs";
options = {
mountpoint = "none";
"recovery" = {
type = "zfs_fs";
options = {
mountpoint = "none";
};
};
};
"storagevm" = {
type = "zfs_fs";
options = {
mountpoint = "/storagevm";
"storagevm" = {
type = "zfs_fs";
options = {
mountpoint = "/storagevm";
};
};
};
};
Expand Down

0 comments on commit 2b51600

Please sign in to comment.