Disko: Difference between revisions

From NixOS Wiki
imported>Onny
mNo edit summary
imported>Onny
Fix nix run remote flake command
Line 54: Line 54:
</syntaxhighlight>
</syntaxhighlight>


Alternativley use a disk layout configuration of a remote repository containing a <code>flake.nix</code> file as an entry point
Alternativley use a disk layout configuration of a remote repository containing a <code>flake.nix</code> file as an entry point. The <code>--arg</code> parameter specifies the target disk <code>/dev/sda</code>.


<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# sudo nix run github:nix-community/disko -- --mode zap_create_mount --flake github:Lassulus/flakes-testing#fnord
# sudo nix run github:nix-community/disko/refactor -- --mode zap_create_mount --flake github:Lassulus/flakes-testing#fnord --arg disks '[ "/dev/sda" ]'
</syntaxhighlight>
</syntaxhighlight>
Flakes support is currently broken in the latest disko release, therefore we use the <code>refactor</code> branch until [https://github.com/nix-community/disko/issues/241 the issue] is fixed.


The commands above requires [[Flake]] features available on your system.
The commands above requires [[Flake]] features available on your system.

Revision as of 12:30, 21 May 2023

Disko is a utility and NixOS module for declarative disk partitioning.

Usage

The following example creates a new GPT partition table for the disk /dev/vda including two partitions for EFI boot and a bcachefs root filesystem.

disko-config.nix
{ disks ? [ "/dev/vda" ], ... }: {
  disko.devices = {
    disk = {
      vdb = {
        device = builtins.elemAt disks 0;
        type = "disk";
        content = {
          type = "table";
          format = "gpt";
          partitions = [
            {
              name = "ESP";
              start = "1MiB";
              end = "500MiB";
              bootable = true;
              content = {
                type = "filesystem";
                format = "vfat";
                mountpoint = "/boot";
              };
            }
            {
              name = "root";
              start = "500MiB";
              end = "100%";
              part-type = "primary";
              content = {
                type = "filesystem";
                format = "bcachefs";
                mountpoint = "/";
              };
            }
          ];
        };
      };
    };
  };
}

The following command will apply the disk layout specified in the configuration and mount them afterwards. Warning: This will erase all data on the disk.

Warning: The disko commands will erase all existing data on your disk and repartition it according to the given configuration.
# sudo nix run github:nix-community/disko -- --mode zap_create_mount ./disko-config.nix

Alternativley use a disk layout configuration of a remote repository containing a flake.nix file as an entry point. The --arg parameter specifies the target disk /dev/sda.

# sudo nix run github:nix-community/disko/refactor -- --mode zap_create_mount --flake github:Lassulus/flakes-testing#fnord  --arg disks '[ "/dev/sda" ]'

Flakes support is currently broken in the latest disko release, therefore we use the refactor branch until the issue is fixed.

The commands above requires Flake features available on your system.

To verify both partitions got mounted correctly, run

# mount | grep /mnt