nix-community / disko

Declarative disk partitioning and formatting using nix [maintainers=@Lassulus @Enzime]
MIT License
1.72k stars 187 forks source link

Ignore Partitions #533

Open jacobranson opened 7 months ago

jacobranson commented 7 months ago

I think it would be beneficial if there was a way to mark partitions as "ignored", meaning Disko won't touch them in any way. For M1 Macs, there are two partitions that cannot be deleted without rendering the machine unbootable, those being iBootSystemContainer and RecoveryOSContainer, like shown below.

nixos# sgdisk /dev/nvme0n1 -p
Disk /dev/nvme0n1: 244276265 sectors, 931.8 GiB
Model: APPLE SSD AP1024Q                       
Sector size (logical/physical): 4096/4096 bytes
Disk identifier (GUID): 27054D2E-307A-41AA-9A8C-3864D56FAF6B
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 5
First usable sector is 6, last usable sector is 244276259
Partitions will be aligned on 1-sector boundaries
Total free space is 0 sectors (0 bytes)

Number  Start (sector)    End (sector)  Size       Code  Name
   1               6          128005   500.0 MiB   FFFF  iBootSystemContainer
   2          128006       219854567   838.2 GiB   AF0A  Container
   3       219854568       220465127   2.3 GiB     AF0A  
   4       220465128       220590311   489.0 MiB   EF00  
   5       220590312       242965550   85.4 GiB    8300  
   6       242965551       244276259   5.0 GiB     FFFF  RecoveryOSContainer

Alternatively, if there is already a mechanism for something like this, perhaps the examples directory can be updated to include a M1 Mac example configuration.

Alex0159 commented 3 months ago

!!! i tested this on a virtual machine be careful with the real disk !!!

After studying the code a little, I realized that the partition number is set by the variable = _index And so that the disk is not formatted, you need to use the mode = format

modified example from README.md:

{
...
          partitions = {
            ESP = {
              type = "EF00";
              size = "500M";
              _index = 4;
              content = {
                type = "filesystem";
                format = "vfat";
                mountpoint = "/boot";
              };
            };
            root = {
              size = "100%";
              _index = 5;
...
}
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode format /tmp/disk-config.nix
Mic92 commented 3 months ago

I have that such a feature becomes to complex to implement with just the nixos module system and shell scripts.

Lassulus commented 3 months ago

it should basically work by replicating your current disk layout in disko (using priority for the order of the partitons) and then just running the format script manually (not the disko one, as that one zaps your disks) the format script should not nuke your table if it already exists. so in theory it should just work.