func assembleExistingMirror()

in pkg/raid/raid.go [150:166]


func assembleExistingMirror(target, existing string, devices ...string) error {
	for _, d := range devices {
		if d != existing {
			_ = wipeDevice(d) // Ignore any error, if there's a problem it will fail in the assemble
		}
	}
	output, err := runMdadm("--assemble", target, existing, "--run")
	if err != nil {
		return fmt.Errorf("Could not bootstrap assemble from %s (%w): %s", existing, err, output)
	}
	output, err = runMdadm(slices.Concat([]string{"--add", target}, devices)...)
	if err != nil {
		_, _ = runMdadm("--stop", target) // Try to clean up as best we can
		return fmt.Errorf("Could not add other devices to existing primary %s/%v (%w): %s", existing, devices, err, output)
	}
	return nil
}