Debian : Mounting a raid array

24,650

there are two 2Tb hard disks in RAID. Is there any way I can format them to one single partition on both drives and mount them to lets say /media/attachment

For the purposes of this answer I am using /dev/sda and /dev/sdb. It is your responsibility to ensure that this matches your situation.

You can do this provided you are happy to erase all the data on these two disks.

  1. Ensure the disks are unused and you have taken a backup of any data on them that you wanted to keep
  2. Using fdisk or your preferred alternative, erase the partition table and create a single partition covering the entire disk. This will leave you with partitions /dev/sda1 and /dev/sdb1
  3. EITHER

    • Create a RAID 1 device, which we will identify as /dev/md1, using these two physical partitions

      mdadm --create /dev/md1 --level=raid1 --raid-devices=2 /dev/sda1 /dev/sdb1
      

    OR

    • Create a RAID 0 device, also identified as /dev/md1

      mdadm --create /dev/md1 --level=raid0 --raid-devices=2 /dev/sda1 /dev/sdb1
      
  4. Save the metadata for boot time

    mdadm --examine --brief /dev/sda1 /dev/sdb1 >> /etc/mdadm/mdadm.conf
    
  5. Create the filesystem. Notice that the RAID device is /dev/md1 and from this point on you rarely need to reference /dev/sda1 or /dev/sdb1

    mkfs -t ext4 -L bigdisk /dev/md1
    
  6. Mount it. Don't forget to update /etc/fstab if you want this configured permanently

    mkdir -p /media/attachment
    mount /dev/md1 /media/attachment
    

You can cat /proc/mdstat to see the state of the RAID device. If you are running as RAID 1 this will show you the synchronisation status.

Share:
24,650

Related videos on Youtube

We are Borg
Author by

We are Borg

Working in Pune,India. Open to meet new people, attend conferences, good talks. For followup on any answer or any doubt about posts on SO, email at kernelfreak[at]gmail.com :-)

Updated on September 18, 2022

Comments

  • We are Borg
    We are Borg almost 2 years

    I have a Debian system on which we migrated to a SSD for faster execution. Before that we had a 2.0Tb hard disks in RAID. Now we want to use the RAID drives to perform storage generated by the application.

    I tried using the mount command to mount one of the disks, but it failed.

    fdisk -l output :

    Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
    255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00089ca4
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048    33556480    16777216+  fd  Linux raid autodetect
    /dev/sdb2        33558528    34607104      524288+  fd  Linux raid autodetect
    /dev/sdb3        34609152  3907027120  1936208984+  fd  Linux raid autodetect
    
    Disk /dev/sdc: 480.1 GB, 480103981056 bytes
    255 heads, 63 sectors/track, 58369 cylinders, total 937703088 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00047ef7
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdc1            2048    33556480    16777216+  82  Linux swap / Solaris
    /dev/sdc2        33558528    34607104      524288+  83  Linux
    /dev/sdc3        34609152   937701040   451545944+  83  Linux
    
    Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
    255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x000275d2
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1            2048    33556480    16777216+  fd  Linux raid autodetect
    /dev/sda2        33558528    34607104      524288+  fd  Linux raid autodetect
    /dev/sda3        34609152  3907027120  1936208984+  fd  Linux raid autodetect
    

    As you can see there are two 2Tb hard disks in RAID. Is there any way I can format them to one single partition on both drives and mount them to lets say /media/attachment?? Any help would be nice. Thanks a lot. :-)

    • roaima
      roaima about 9 years
      You can merge the two disks and create one usable partition. Do you want one 2TB partition as RAID 1 (mirrored across the two disks) or one 4TB partition as RAID 0 (sharing the disks)?
  • We are Borg
    We are Borg about 9 years
    Can you tell me how I can do that?
  • We are Borg
    We are Borg about 9 years
    Sorry, i cannot mess around as this is production server I am dealing with.
  • Marco
    Marco about 9 years
    Sorry but I cannot help you with exact commands. Just tried to give you an approach. Do you have a testing machine on which you can create a RAID and then 'remove' it?
  • We are Borg
    We are Borg about 9 years
    I will check this out in sometime as soon as I take a backup and let you know. Thanks a lot.
  • We are Borg
    We are Borg about 9 years
    This worked like a charm. Kudos.
  • roaima
    roaima about 9 years
    One safe way to test is to use a loop device. dd if=/dev/zero bs=1M count=100 of=/tmp/a ; losetup -v /dev/loop1 /tmp/a and repeat for /tmp/b and /dev/loop2. Then you can fdisk, mdadm, mkfs, and even mount with those two loopN devices and the consequent mdN RAID device