disko icon indicating copy to clipboard operation
disko copied to clipboard

`mdadm` array not symlinked correctly after creation

Open szethh opened this issue 7 months ago • 9 comments

I'm trying to set up a raid1 array using mdadm. The array is created correctly, but it seems that the symlink to /dev/md/arrayname is not created correctly.

These are the last log lines before the process fails:

mkfs.fat 4.2 (2021-01-31)
+ device=/dev/disk/by-partlabel/disk-_dev_sdb-nixos
+ name=nixos
+ type=mdraid
+ echo /dev/disk/by-partlabel/disk-_dev_sdb-nixos
+ level=1
+ metadata=default
+ name=nixos
+ type=mdadm
+ test -e /dev/md/nixos
+ readarray -t disk_devices
++ cat /tmp/tmp.YXB4lIUGsi/raid_nixos
+ echo y
++ wc -l /tmp/tmp.YXB4lIUGsi/raid_nixos
++ cut -f 1 -d ' '
+ mdadm --create /dev/md/nixos --level=1 --raid-devices=2 --metadata=default --force --homehost=any /dev/disk/by-partlabel/disk-_dev_sda-nixos /dev/disk/by-partlabel/disk-_dev_sdb-nixos
mdadm: array /dev/md/nixos started.
mdadm: timeout waiting for /dev/md/nixos
+ partprobe /dev/md/nixos
Error: Could not stat device /dev/md/nixos - No such file or directory.
+ rm -rf /tmp/tmp.YXB4lIUGsi
Connection to <ip> closed.

If I ssh into the host and run this same command (mdadm --create /dev/md/nixos --level=1 --raid-devices=2 --metadata=default --force --homehost=any /dev/disk/by-partlabel/disk-_dev_sda-nixos /dev/disk/by-partlabel/disk-_dev_sdb-nixos) manually, the array is created at /dev/md127, with a symlink from /dev/md/nixos pointing to it.

So manually running the command creates the symlink, disko's script does not. In either case the array is created fine (below is the output for running lsblk after either method):

root@rescue ~ # lsblk
NAME      MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINTS
loop0       7:0    0  3.1G  1 loop  
sda         8:0    0  3.6T  0 disk  
|-sda1      8:1    0  512M  0 part  
`-sda2      8:2    0  3.6T  0 part  
  `-md127   9:127  0  3.6T  0 raid1 
sdb         8:16   0  3.6T  0 disk  
|-sdb1      8:17   0  512M  0 part  
`-sdb2      8:18   0  3.6T  0 part  
  `-md127   9:127  0  3.6T  0 raid1 

Here's my disko config, although checking other people's it seems to be fine.

{ lib, ... }: {
  disk = lib.genAttrs [ "/dev/sda" "/dev/sdb" ] (disk: {
    type = "disk";
    device = disk;
    content = {
      type = "gpt";
      partitions = {
        ESP = {
          size = "512M";
          type = "EF00";
          content = {
            type = "filesystem";
            format = "vfat";
            mountpoint = "/boot";
          };
          priority = 1;
        };
        nixos = {
          size = "100%";
          content = {
            type = "mdraid";
            name = "nixos";
          };
          priority = 2;
        };
      };
    };
  });
  mdadm = {
    nixos = {
      type = "mdadm";
      level = 1;
      content = {
        type = "filesystem";
        format = "ext4";
        mountpoint = "/";
      };
    };
  };
}

The disks are 2 sata hdds in a bare metal hetzner server, if that matters. I am using disko via nixos-anywhere.

szethh avatar Jul 12 '24 14:07 szethh