Disko: Difference between revisions

imported>Onny
mNo edit summary
m Minor formatting, in-link.
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
[https://github.com/nix-community/disko Disko] is a utility and NixOS module for declarative disk partitioning.
<languages/>
<translate>
<!--T:1-->
<strong>[https://github.com/nix-community/disko Disko]</strong> is a utility and [[NixOS modules|NixOS module]] for declarative disk partitioning.


== Usage ==
<!--T:2-->
[https://github.com/nix-community/disko/blob/master/docs/INDEX.md Disko Documentation Index]


The following example creates a new GPT partition table for the disk <code>/dev/vda</code> including two partitions for EFI boot and a [[bcachefs]] root filesystem.
== Usage == <!--T:3-->


<!--T:4-->
The following example creates a new GPT partition table for the disk <code>/dev/vda</code> including two partitions for EFI boot and a [[Special:MyLanguage/bcachefs|bcachefs]] root filesystem.
</translate>
{{file|disko-config.nix|nix|<nowiki>
{{file|disko-config.nix|nix|<nowiki>
{ disks ? [ "/dev/vda" ], ... }: {
{
   disko.devices = {
   disko.devices = {
     disk = {
     disk = {
       vdb = {
       main = {
         device = builtins.elemAt disks 0;
         device = "/dev/vda";
         type = "disk";
         type = "disk";
         content = {
         content = {
           type = "table";
           type = "gpt";
          format = "gpt";
           partitions = {
           partitions = [
             ESP = {
             {
               end = "500M";
               name = "ESP";
               type = "EF00";
              start = "1MiB";
               end = "500MiB";
              bootable = true;
               content = {
               content = {
                 type = "filesystem";
                 type = "filesystem";
Line 26: Line 31:
                 mountpoint = "/boot";
                 mountpoint = "/boot";
               };
               };
             }
             };
             {
             root = {
               name = "root";
               name = "root";
              start = "500MiB";
               end = "-0";
               end = "100%";
              part-type = "primary";
               content = {
               content = {
                 type = "filesystem";
                 type = "filesystem";
Line 37: Line 40:
                 mountpoint = "/";
                 mountpoint = "/";
               };
               };
             }
             };
           ];
           };
         };
         };
       };
       };
Line 45: Line 48:
}
}
</nowiki>}}
</nowiki>}}
<translate>


<!--T:5-->
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.
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.


</translate>
<translate>
<!--T:17-->
{{Warning|The disko commands will erase all existing data on your disk and repartition it according to the given configuration.}}
{{Warning|The disko commands will erase all existing data on your disk and repartition it according to the given configuration.}}
</translate>
<translate>


<!--T:6-->
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# sudo nix run github:nix-community/disko -- --mode zap_create_mount ./disko-config.nix
# sudo nix run github:nix-community/disko -- --mode disko ./disko-config.nix
</syntaxhighlight>
</syntaxhighlight>


Alternativley use a disk layout configuration of a [https://github.com/Lassulus/flakes-testing 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>.
<!--T:7-->
Alternativley use a disk layout configuration of a [https://github.com/Lassulus/flakes-testing remote repository] containing a <code>flake.nix</code> file as an entry point.


<!--T:8-->
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# sudo nix run github:nix-community/disko -- --mode zap_create_mount --flake github:Lassulus/flakes-testing#fnord --arg disks '[ "/dev/sda" ]'
# sudo nix run github:nix-community/disko -- --mode disko --flake github:Lassulus/flakes-testing#fnord
</syntaxhighlight>
</syntaxhighlight>


The commands above requires [[Flake]] features available on your system.
<!--T:9-->
The commands above requires [[Special:MyLanguage/Flake|Flake]] features available on your system.


<!--T:10-->
To verify both partitions got mounted correctly, run
To verify both partitions got mounted correctly, run


<!--T:11-->
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# mount | grep /mnt
# mount | grep /mnt
</syntaxhighlight>
</syntaxhighlight>


== Configuration ==
== Configuration == <!--T:12-->


In case the NixOS base system was installed on a partition layout bootstrapped with Disko, the disk config itself can be integrated into the system. First copy the the file, for example <code>disko-config.nix</code> into your system configuration directory
<!--T:13-->
In case the NixOS base system was installed on a partition layout bootstrapped with Disko, the disk config itself can be integrated into the system. First copy the file, for example <code>disko-config.nix</code> into your system configuration directory


<!--T:14-->
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# cp disko-config.nix /etc/nixos/
# cp disko-config.nix /etc/nixos/
</syntaxhighlight>
</syntaxhighlight>


<!--T:15-->
Add the Disko module on a flake-enabled system. Insert the required input and reference it and your <code>disko-config.nix</code> in the modules section. For alternative installation methods consult the Disko [https://github.com/nix-community/disko/blob/master/docs/quickstart.md quickstart guide].
Add the Disko module on a flake-enabled system. Insert the required input and reference it and your <code>disko-config.nix</code> in the modules section. For alternative installation methods consult the Disko [https://github.com/nix-community/disko/blob/master/docs/quickstart.md quickstart guide].


</translate>
{{file|/etc/nixos/flake.nix|nix|<nowiki>
{{file|/etc/nixos/flake.nix|nix|<nowiki>
{
{
Line 95: Line 115:
         ./disko-config.nix
         ./disko-config.nix
         {
         {
           _module.args.disks = [ "/dev/vda" ];
           disko.devices.main.device = nixpkgs.lib.mkForce "/dev/vda";
         }
         }
         ./configuration.nix
         ./configuration.nix
Line 103: Line 123:
}
}
</nowiki>}}
</nowiki>}}
<translate>


<!--T:16-->
Ensure that there are no automatically generated entries of <code>fileSystems</code> options in <code>/etc/nixos/hardware-configuration.nix</code>. Disko will automatically generate them for you. Rebuild your system to apply the Disko configuration.
Ensure that there are no automatically generated entries of <code>fileSystems</code> options in <code>/etc/nixos/hardware-configuration.nix</code>. Disko will automatically generate them for you. Rebuild your system to apply the Disko configuration.


[[Category:Filesystem]]
</translate>
[[Category:Filesystem{{#translation:}}]]
[[Category:Deployment]]