Page 3 of 3 FirstFirst 123
Results 21 to 28 of 28

Thread: Mdadm issue, unable to re-mount array

  1. #21
    Join Date
    Jan 2007
    Beans
    43

    Re: Mdadm issue, unable to re-mount array

    Does this not indicate the order? or have I lost that info? (taken from that post)

    It looks like this:

    Number Major Minor RaidDevice State
    0 8 33 0 active sync /dev/sdc1
    1 8 49 1 active sync /dev/sdd1
    3 8 17 2 active sync /dev/sdb1

    When it should look like this:

    Number Major Minor RaidDevice State
    0 8 17 0 active sync /dev/sdb1
    1 8 33 1 active sync /dev/sdc1
    3 8 49 2 active sync /dev/sdd1

  2. #22
    Join Date
    Nov 2009
    Location
    Catalunya, Spain
    Beans
    14,558
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Mdadm issue, unable to re-mount array

    He was also doing resync, and it worked after he put the order correctly later.
    The thing is that the current order is showing the current order, and it's irrelevant for the previous order. You can get the order with mdadm --detail /dev/md0 but when it was the original array. And then write it down so you have it for the future if something happens to the superblocks.

    Right now I can't really be sure how to get the original disk order. If replacing some disks, they might have been inserted in the middle, not at the end. Let me send a PM to someone that has more mdadm knowledge, if he can join in.
    Darko.
    -----------------------------------------------------------------------
    Ubuntu 18.04 LTS 64bit

  3. #23
    Join Date
    Jul 2010
    Location
    Michigan, USA
    Beans
    2,136
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Mdadm issue, unable to re-mount array

    Since, you've blown away the previous metadata by recreating the array, the only way to potentially recover at this point is to try every possible order combination to assemble your array and try to mount it each time to see if your data is available. Just so I understand, what you put it post #4, was after you ran mdadm --create --assume-clean, correct?

  4. #24
    Join Date
    Jan 2007
    Beans
    43

    Re: Mdadm issue, unable to re-mount array

    ok, so thats 40320 possible orders?

    Is there a script around that can perhaps:

    Create array variant 1

    mount array

    If output = 0 then success

    If (len)output>=1 then

    Delete array

    Create array variant 2

    Etc..

  5. #25
    Join Date
    Jan 2007
    Beans
    43

    Re: Mdadm issue, unable to re-mount array

    Ok, I have found a perl script, but I need some help:

    Code:
    #!/usr/bin/perl -w
    
    # If you forgot how you built an array and need to try various
    # permutations then this is for you...
    
    # based on Mark-Jason Dominus' mjd_permute: permute each word of input
    
    use strict;
    use Getopt::Long;
    
    sub usage {
     return "syntax: permute_array --md <md_device> --mount <mountpoint> [--opts <mdadm options>] [--for_real] <all devices>\n";
    }
    
    my $MD_DEVICE="/dev/md0";
    my $MOUNTPOINT="/Data";
    my $MDADM_OPTS="--assume-clean";
    my $REAL;
    
    ################################################################
    # This function is passed each permutation of component devices.
    # This includes a 'missing' device.
    # This is the place to hack command variations etc... 
    sub try_array {
      # @_ looks like: ("/dev/sda1", "missing", "/dev/sdb1")
      my @device_list = @_["/dev/sdb1", "/dev/sdc1", "/dev/sdd1", "/dev/sdf1", "/dev/sdh1", "/dev/sdi1", "/dev/sdj1", "/dev/sdk1"];
      my $num_devices = scalar $_["8"];
    
      # This may need a --force... <gulp>
      my $create = "yes | mdadm --create $MD_DEVICE --raid-devices=$num_devices --level=5 $MDADM_OPTS @device_list 2>/dev/null\n";
      # Don't forget to mount read-only
      my $mount =  "mount -oro $MD_DEVICE $MOUNTPOINT 2>/dev/null";
      my $umount =  "umount $MOUNTPOINT 2>/dev/null";
      # and stop the array...
      my $stop = "mdadm --stop $MD_DEVICE 2>/dev/null";
    
      # REAL == --for_real option
      if ($REAL) {
        # we expect this to succeed
        system $create;
        if (my $err = $?>>8) {
          die "command : $create\n   exited with status $err\n\n";
        }
        # we expect this to fail and are happy if it succeeds
        system $mount;
        if (!(my $err = $?>>8)) {
          print "Success. possible command : \n  $create\n";
          system $umount;
        }
        # we expect this to succeed
        system $stop;
        if (my $err = $?>>8) {
          die "command : $stop\n   exited with status $err\n\n";
        }
      } else {
        # Just show the create/mount/stop commands
        # If you want more control you could use this to write a script
        print "$create\n$mount\n$stop\n";
      }
    }
    
    
    ################################################################
    # Execution starts here...
    #
    sub factorial($);
    
    GetOptions ('md=s'      => \$MD_DEVICE,
    	    "mount=s"   => \$MOUNTPOINT,
    	    "opts=s"    => \$MDADM_OPTS,
    	    "for_real"  => \$REAL);
    
    if (!defined($MD_DEVICE) or !defined($MOUNTPOINT)) {
      die &usage;
    }
    
    print "using device $MD_DEVICE and mounting on $MOUNTPOINT\n";
    
    # we *always* assume a 'missing' device - not doing so will destroy
    # the array...
    my @devices = @ARGV;
    # how many devices?
    my $num_devices = scalar @devices;
    if ($num_devices < 2) {
      die "$0 needs at least two component devices\n";
    }
    # how many base permutations...
    my $num_permutations = factorial(scalar @devices);
    # try all permutations, substituting 'missing' for each device in
    # turn...
    for (my $d=0; $d < $num_devices; $d++) {
      my $skip_device = $devices[$d];
      $devices[$d] = "missing";
      print "skipping $skip_device\n\n";
      for (my $i=0; $i < $num_permutations; $i++) {
        my @permutation = @devices[n2perm($i, $#devices)];
        try_array(@permutation);
      }
      $devices[$d] = $skip_device;
    }
    
    ################################################################
    # permutation code
    
    # n2pat($N, $len) : produce the $N-th pattern of length $len
    sub n2pat {
        my $i   = 1;
        my $N   = shift;
        my $len = shift;
        my @pat;
        while ($i <= $len + 1) {   # Should really be just while ($N) { ...
            push @pat, $N % $i;
            $N = int($N/$i);
            $i++;
        }
        return @pat;
    }
    
    # pat2perm(@pat) : turn pattern returned by n2pat() into
    # permutation of integers.  XXX: splice is already O(N)
    sub pat2perm {
        my @pat    = @_;
        my @source = (0 .. $#pat);
        my @perm;
        push @perm, splice(@source, (pop @pat), 1) while @pat;
        return @perm;
    }
    
    # n2perm($N, $len) : generate the Nth permutation of $len objects
    sub n2perm {
        pat2perm(n2pat(@_));
    }
    
    # Utility function: factorial with memoizing
    BEGIN {
      my @fact = (1);
      sub factorial($) {
        my $n = shift;
        return $fact[$n] if defined $fact[$n];
        $fact[$n] = $n * factorial($n - 1);
      }
    }


    Running the code gives me the error:


    Code:
    djh@fs01:~$ sudo ./Permute_array.pl
    using device /dev/md0 and mounting on /Data
    ./Permute_array.pl needs at least two component devices


    Im guessing it's this part?

    my @device_list = @_["/dev/sdb1", "/dev/sdc1", "/dev/sdd1", "/dev/sdf1", "/dev/sdh1", "/dev/sdi1", "/dev/sdj1", "/dev/sdk1"];
    my $num_devices = scalar $_["8"];


    Thanks

    DJH

  6. #26
    Join Date
    Jan 2007
    Beans
    43

    Re: Mdadm issue, unable to re-mount array

    Ok, well was worth a try, got the script running, it takes about 10 mins but comes back with the following command to run:

    Code:
    sudo mdadm --create --assume-clean /dev/md0 --raid-devices=8 --level=5  missing /dev/sdc1 /dev/sdd1 /dev/sdj1 /dev/sdk1 /dev/sdf1 /dev/sdi1 /dev/sdh1 2>/dev/null

    It just sits there forever, what does "2>/dev/null" do?

    Without it, it creates the array, but still cannot mount, so i guess the data really is gone.


    Ran it again and it came back with a different sequence, so perhaps the script is not that good, or my array is totally messed up

    Thanks

    DJH

  7. #27
    Join Date
    Nov 2009
    Location
    Catalunya, Spain
    Beans
    14,558
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Mdadm issue, unable to re-mount array

    Before trying all different combinations, I would try remembering the flow of events, if you can. For example, if the disks were in order when first creating the array, and if they were 8 from the start, the most probable order would be: BCDEFGHI. Later if E failed for example, it can be replaced with J but the slot for J will still be number 3 (they count from 0). So, like BCDJFGHI.

    I know this is not easy, but try considering what you did with this array and try those few combinations of disk order.
    Darko.
    -----------------------------------------------------------------------
    Ubuntu 18.04 LTS 64bit

  8. #28
    Join Date
    Jul 2010
    Location
    Michigan, USA
    Beans
    2,136
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Mdadm issue, unable to re-mount array

    Quote Originally Posted by darkod View Post
    Before trying all different combinations, I would try remembering the flow of events, if you can. For example, if the disks were in order when first creating the array, and if they were 8 from the start, the most probable order would be: BCDEFGHI. Later if E failed for example, it can be replaced with J but the slot for J will still be number 3 (they count from 0). So, like BCDJFGHI.

    I know this is not easy, but try considering what you did with this array and try those few combinations of disk order.
    +1. Sorry, I wasn't clear. This is exactly what you would want to do first.

Page 3 of 3 FirstFirst 123

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •