Disko/ru: Difference between revisions
Created page with "Следующий пример создаёт новую таблицу разделов GPT для диска <code>/dev/vda</code> включая два раздела для EFI boot и корневой раздел файловой системы bcachefs." |
No edit summary Tags: Mobile edit Mobile web edit |
||
Line 12: | Line 12: | ||
Следующий пример создаёт новую таблицу разделов GPT для диска <code>/dev/vda</code> включая два раздела для EFI boot и корневой раздел файловой системы [[bcachefs]]. | Следующий пример создаёт новую таблицу разделов GPT для диска <code>/dev/vda</code> включая два раздела для EFI boot и корневой раздел файловой системы [[bcachefs]]. | ||
{{file|disko-config.nix|nix|<nowiki> | |||
{ 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 = "/"; | |||
}; | |||
} | |||
]; | |||
}; | |||
}; | |||
}; | |||
}; | |||
} | |||
</nowiki>}} | |||
{{file|disko-config.nix|nix|<nowiki> | {{file|disko-config.nix|nix|<nowiki> |
Revision as of 13:57, 20 July 2024
Disko is a utility and NixOS module for declarative disk partitioning.
Использование
Следующий пример создаёт новую таблицу разделов GPT для диска /dev/vda
включая два раздела для EFI boot и корневой раздел файловой системы bcachefs.
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 = "/";
};
}
];
};
};
};
};
}
disko-config.nix
{
disko.devices = {
disk = {
main = {
device = "/dev/vda";
type = "disk";
content = {
type = "gpt";
partitions = {
ESP = {
end = "500M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
};
root = {
name = "root";
end = "-0";
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.
# sudo nix run github:nix-community/disko -- --mode disko ./disko-config.nix
Alternativley use a disk layout configuration of a remote repository containing a flake.nix
file as an entry point.
# sudo nix run github:nix-community/disko -- --mode disko --flake github:Lassulus/flakes-testing#fnord
The commands above requires Flake features available on your system.
To verify both partitions got mounted correctly, run
# mount | grep /mnt
Configuration
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 disko-config.nix
into your system configuration directory
# cp disko-config.nix /etc/nixos/
Add the Disko module on a flake-enabled system. Insert the required input and reference it and your disko-config.nix
in the modules section. For alternative installation methods consult the Disko quickstart guide.
/etc/nixos/flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
disko.url = "github:nix-community/disko";
disko.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = {self, nixpkgs, disko, ...}@inputs: {
nixosConfigurations.mysystem = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs.inputs = inputs;
modules = [
disko.nixosModules.disko
./disko-config.nix
{
disko.devices.main.device = nixpkgs.lib.mkForce "/dev/vda";
}
./configuration.nix
];
};
};
}
Ensure that there are no automatically generated entries of fileSystems
options in /etc/nixos/hardware-configuration.nix
. Disko will automatically generate them for you. Rebuild your system to apply the Disko configuration.