2

Is it possible to assemple a three drive software RAID5 with only two disks? I have one failed disk in my setup which i could not read at all but the two other disks are fine. So i created a dump of the both fine devices with ddrescue and used the images as devices with losetup.

How to assemble the RAID with those two left devices?

1 Answer 1

4

Do this:

mdadm --assemble --run /dev/md0 LOOPDEVICE1 LOOPDEVICE2

The --run flag is what forces mdadm to assemble an md RAID array without all the devices.

Full Example

Create three files to put into RAID 5:

deltik@workstation [/media/datadrive]# truncate -s 1G 1.img
deltik@workstation [/media/datadrive]# truncate -s 1G 2.img
deltik@workstation [/media/datadrive]# truncate -s 1G 3.img

Make the files block devices using losetup (because mdadm needs them to be block devices):

deltik@workstation [/media/datadrive]# sudo losetup loop1 1.img 
deltik@workstation [/media/datadrive]# sudo losetup loop2 2.img 
deltik@workstation [/media/datadrive]# sudo losetup loop3 3.img

Create the RAID 5 array:

deltik@workstation [/media/datadrive]# sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/loop{1,2,3}
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 1047552K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

Stop the RAID 5 array:

deltik@workstation [/media/datadrive]# sudo mdadm --stop /dev/md0
mdadm: stopped /dev/md0

Remove one of the devices:

deltik@workstation [/media/datadrive]# sudo losetup -d /dev/loop3

Assemble the array from one missing device in RAID 5. Notice that mdadm will refuse to do so without the --run flag:

deltik@workstation [/media/datadrive]# sudo mdadm --assemble /dev/md0 /dev/loop1 /dev/loop2
mdadm: /dev/md0 assembled from 2 drives - need all 3 to start it (use --run to insist).
deltik@workstation [/media/datadrive]# sudo mdadm --assemble --run /dev/md0 /dev/loop1 /dev/loop2
mdadm: /dev/md0 has been started with 2 drives (out of 3).

Here, you can see the degraded RAID 5 array:

deltik@workstation [/media/datadrive]# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid5 loop1[0] loop2[1]
      2095104 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]

unused devices: <none>

deltik@workstation [/media/datadrive]# sudo mdadm --detail /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Tue Aug 25 04:41:27 2015
     Raid Level : raid5
     Array Size : 2095104 (2046.34 MiB 2145.39 MB)
  Used Dev Size : 1047552 (1023.17 MiB 1072.69 MB)
   Raid Devices : 3
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Tue Aug 25 04:41:44 2015
          State : clean, degraded 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 512K

           Name : 0
           UUID : 89f52950:919bded3:5d6c5c25:714a7f15
         Events : 18

    Number   Major   Minor   RaidDevice State
       0       7        1        0      active sync   /dev/loop1
       1       7        2        1      active sync   /dev/loop2
       4       0        0        4      removed
1
  • When creating a new array, you can just use the "missing" keyword instead of the device name. Thus you can start with a degraded array and add the missing disk(s) later.
    – katti
    Commented Jul 27, 2019 at 22:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .