Showing posts with label mdadm. Show all posts
Showing posts with label mdadm. Show all posts

Sunday, 29 September 2024

My Current MDADM Setup

Just some notes on my current MDADM setup, so I do not forget.

So my current hard drives are:

# lsscsi
[0:0:0:0]    disk    ATA      Samsung SSD 860  1B6Q  /dev/sda 
[4:0:0:0]    disk    ATA      WDC WD4003FZEX-0 1A01  /dev/sdb 
[5:0:0:0]    disk    ATA      WDC WD5000AAKS-0 3B01  /dev/sdc 
[5:0:1:0]    disk    ATA      ST2000DM001-1CH1 CC29  /dev/sdd 
[10:0:0:0]   disk    WD       Ext HDD 1021     2021  /dev/sde 
[11:0:0:0]   disk    WD       Ext HDD 1021     2021  /dev/sdf 

The first one is my primary and Operating Systems and all that. Seems obvious.

The second one contains a large partition for my /home on sdb1.

Partition sdc1 of the sdc drive is a simple 500Gb partition containing some odds and ends. Not big enough for the RAID, not fast enough for the operating system.

Starting my raid setup I can do with:

# mdadm --assemble /dev/md127 /dev/sdd1 /dev/sde1 /dev/sdf1 /dev/sdb2 mdadm: /dev/md127 has been started with 4 drives.

Just so you know, it's a simple mirror setup, so I am using 4 drives to mirror a 2 TB partition.

And then I simple mount the damn thing with:

# mount /dev/md127 /mnt/raid/

Then I can watch the status with detail:

mdadm --detail /dev/md127

Thursday, 16 November 2023

Adding a device to a raid with mdadm

Reordering partitions to make room

So my current hard drives are:

# lsscsi
[0:0:0:0]    disk    ATA      Samsung SSD 860  1B6Q  /dev/sda 
[4:0:0:0]    disk    ATA      WDC WD4003FZEX-0 1A01  /dev/sdb 
[5:0:0:0]    disk    ATA      WDC WD5000AAKS-0 3B01  /dev/sdc 
[5:0:1:0]    disk    ATA      ST2000DM001-1CH1 CC29  /dev/sdd 
[10:0:0:0]   disk    WD       Ext HDD 1021     2021  /dev/sde 
[11:0:0:0]   disk    WD       Ext HDD 1021     2021  /dev/sdf 

I had a lot of unused space on /dev/sdb, and thought I could rearrange the partitions and use it as an additional device in my (software) RAID.

I used Parted1, but GParted2 is also very nice. GParted can also scan my /dev/md127, which is a raid device.

Of course there's the general problem nowadays of looking what kind of MBR/GPT or whatever boot schema you use.

So:

Disk /dev/sdb: 3.64 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: WDC WD4003FZEX-0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: D344E388-FA66-4B30-BA00-4D3B12A07B79
Device          Start        End    Sectors  Size Type
/dev/sdb1        2048       4095       2048    1M BIOS boot
/dev/sdb2        4096    1028095    1024000  500M Linux filesystem
/dev/sdb3     1028096 5273437500 5272409405  2.5T Linux filesystem
/dev/sdb4  5273438208 7420921855 2147483648    1T Linux filesystem

So it's a 4 TB hard drive, and it turns out that I only use /dev/sdb3. (The other partitions are from an old Linux install before I got a nice SDD and reinstalled Linux/Windows on that.)

So I could first rearrange it: resize /dev/sdb3 to 2T and move it to /dev/sdb1.

That worked fine using Parted. It just took some time to actually move all the data.

And then create a new /dev/sdb2 of 2T for my raid with gdisk3 (the GPT version of fdisk).

I had to look up the appropriate partition type in GPT4 for mdadm.

# gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.9

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Command (? for help): n
Partition number (2-128, default 2): 
First sector (34-7814037134, default = 3907006464) or {+-}size{KMGTP}: 
Last sector (3907006464-7814037134, default = 7814035455) or {+-}size{KMGTP}: 
Current type is 8300 (Linux filesystem)


Hex code or GUID (L to show codes, Enter = 8300): fd00
Changed type of partition to 'Linux RAID'

Command (? for help): p
Disk /dev/sdb: 7814037168 sectors, 3.6 TiB
Model: WDC WD4003FZEX-0
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): D344E388-FA66-4B30-BA00-4D3B12A07B79
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 7814037134
Partitions will be aligned on 2048-sector boundaries
Total free space is 3693 sectors (1.8 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      3907006463   1.8 TiB     8300  
   2      3907006464      7814035455   1.8 TiB     FD00  Linux RAID

Adding the device

Current raid setup:

# mdadm --assemble /dev/md127 /dev/sdd1 /dev/sde1 /dev/sdf1
mdadm: /dev/md127 has been started with 3 drives.

# mdadm --detail /dev/md127
/dev/md127:
           Version : 1.2
     Creation Time : Wed Mar  6 22:16:05 2013
        Raid Level : raid1
        Array Size : 1953380160 (1862.89 GiB 2000.26 GB)
     Used Dev Size : 1953380160 (1862.89 GiB 2000.26 GB)
      Raid Devices : 3
     Total Devices : 3
       Persistence : Superblock is persistent

       Update Time : Wed Aug 16 09:08:07 2023
             State : clean 
    Active Devices : 3
   Working Devices : 3
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : resync

              Name : micemouse:0
              UUID : ed4531c4:59c132b2:a6bfc3d1:6da3b928
            Events : 7285

    Number   Major   Minor   RaidDevice State
       4       8       65        0      active sync   /dev/sde1
       5       8       81        1      active sync   /dev/sdf1
       3       8       49        2      active sync   /dev/sdd1
# cat /proc/mdstat
Personalities : [raid1] 
md127 : active raid1 sde1[4] sdd1[3] sdf1[5]
      1953380160 blocks super 1.2 [3/3] [UUU]
      
unused devices: <none>

Adding a device:

mdadm --add /dev/md127 /dev/sdb2
mdadm: added /dev/sdb2
  
md127 : active raid1 sdb2[6](S) sde1[4] sdd1[3] sdf1[5]
      1953380160 blocks super 1.2 [3/3] [UUU]
      
unused devices: <none>
 mdadm --detail /dev/md127
/dev/md127:
           Version : 1.2
     Creation Time : Wed Mar  6 22:16:05 2013
        Raid Level : raid1
        Array Size : 1953380160 (1862.89 GiB 2000.26 GB)
     Used Dev Size : 1953380160 (1862.89 GiB 2000.26 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Sat Aug 19 16:47:58 2023
             State : clean 
    Active Devices : 3
   Working Devices : 4
    Failed Devices : 0
     Spare Devices : 1

Consistency Policy : resync

              Name : micemouse:0
              UUID : ed4531c4:59c132b2:a6bfc3d1:6da3b928
            Events : 7286

    Number   Major   Minor   RaidDevice State
       4       8       65        0      active sync   /dev/sde1
       5       8       81        1      active sync   /dev/sdf1
       3       8       49        2      active sync   /dev/sdd1

       6       8       18        -      spare   /dev/sdb2
[
root@localhost ~]# mdadm --grow /dev/md127 --raid-devices=4
raid_disks for /dev/md127 set to 4

  # mdadm --detail /dev/md127
/dev/md127:
           Version : 1.2
     Creation Time : Wed Mar  6 22:16:05 2013
        Raid Level : raid1
        Array Size : 1953380160 (1862.89 GiB 2000.26 GB)
     Used Dev Size : 1953380160 (1862.89 GiB 2000.26 GB)
      Raid Devices : 4
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Sat Aug 19 16:49:32 2023
             State : clean, degraded, recovering 
    Active Devices : 3
   Working Devices : 4
    Failed Devices : 0
     Spare Devices : 1

Consistency Policy : resync

    Rebuild Status : 0% complete

              Name : micemouse:0
              UUID : ed4531c4:59c132b2:a6bfc3d1:6da3b928
            Events : 7290

    Number   Major   Minor   RaidDevice State
       4       8       65        0      active sync   /dev/sde1
       5       8       81        1      active sync   /dev/sdf1
       3       8       49        2      active sync   /dev/sdd1
       6       8       18        3      spare rebuilding   /dev/sdb2

And now we wait.

# cat /proc/mdstat
Personalities : [raid1] 
md127 : active raid1 sdb2[6] sde1[4] sdd1[3] sdf1[5]
      1953380160 blocks super 1.2 [4/3] [UUU_]
      [>....................]  recovery =  0.1% (2956032/1953380160) finish=1156.0min speed=28118K/sec
      
unused devices: <none>

Ready in about 12 hours.

References

[1] Parted User’s Manual
https://www.gnu.org/software/parted/manual/parted.html
[2] GParted is a free partition editor for graphically managing your disk partitions.
https://gparted.org/
[3] gdisk(8) - Linux man page
https://linux.die.net/man/8/gdisk/
[4] Raid Wiki Kernel Org - Partition Types
https://raid.wiki.kernel.org/index.php/Partition_Types
WP Guru - How to add a drive to software RAID with mdadm
https://wpguru.co.uk/2021/01/expand-software-raid-mdadm/

Saturday, 13 May 2023

Mounting and umounting my MDADM disk array

In my dmesg, when connecting my USB harddrives, I get the following messages:

[ 3455.138687] usb 1-1.5: new high-speed USB device number 3 using ehci-pci
[ 3455.218450] usb 1-1.5: New USB device found, idVendor=1058, idProduct=1021, bcdDevice=20.21
[ 3455.218462] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3455.218468] usb 1-1.5: Product: Ext HDD 1021
[ 3455.218472] usb 1-1.5: Manufacturer: Western Digital
[ 3455.218476] usb 1-1.5: SerialNumber: 574D43315431373033343231
[ 3455.260880] usb-storage 1-1.5:1.0: USB Mass Storage device detected
[ 3455.261279] scsi host10: usb-storage 1-1.5:1.0
[ 3455.261525] usbcore: registered new interface driver usb-storage
[ 3455.267542] usbcore: registered new interface driver uas
[ 3455.287643] usb 1-1.6: new high-speed USB device number 4 using ehci-pci
[ 3455.367335] usb 1-1.6: New USB device found, idVendor=1058, idProduct=1021, bcdDevice=20.21
[ 3455.367347] usb 1-1.6: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3455.367353] usb 1-1.6: Product: Ext HDD 1021
[ 3455.367357] usb 1-1.6: Manufacturer: Western Digital
[ 3455.367361] usb 1-1.6: SerialNumber: 574D43315432313138383334
[ 3455.367897] usb-storage 1-1.6:1.0: USB Mass Storage device detected
[ 3455.368175] scsi host11: usb-storage 1-1.6:1.0
[ 3456.301327] scsi 10:0:0:0: Direct-Access WD Ext HDD 1021 2021 PQ: 0 ANSI: 4
[ 3456.302077] sd 10:0:0:0: Attached scsi generic sg4 type 0
[ 3456.302737] sd 10:0:0:0: [sde] 3907024896 512-byte logical blocks: (2.00 TB/1.82 TiB)
[ 3456.304758] sd 10:0:0:0: [sde] Write Protect is off
[ 3456.304771] sd 10:0:0:0: [sde] Mode Sense: 17 00 10 08
[ 3456.306754] sd 10:0:0:0: [sde] No Caching mode page found
[ 3456.306763] sd 10:0:0:0: [sde] Assuming drive cache: write through
[ 3456.335251] sde: sde1
[ 3456.335455] sd 10:0:0:0: [sde] Attached SCSI disk
[ 3456.428905] scsi 11:0:0:0: Direct-Access WD Ext HDD 1021 2021 PQ: 0 ANSI: 4
[ 3456.430291] sd 11:0:0:0: Attached scsi generic sg5 type 0
[ 3456.431366] sd 11:0:0:0: [sdf] 3907024896 512-byte logical blocks: (2.00 TB/1.82 TiB)
[ 3456.433375] sd 11:0:0:0: [sdf] Write Protect is off
[ 3456.433387] sd 11:0:0:0: [sdf] Mode Sense: 17 00 10 08
[ 3456.435502] sd 11:0:0:0: [sdf] No Caching mode page found
[ 3456.435515] sd 11:0:0:0: [sdf] Assuming drive cache: write through
[ 3456.457754] sdf: sdf1
[ 3456.457974] sd 11:0:0:0: [sdf] Attached SCSI disk

The partitions on those drives look like follows:

/dev/sdd1 2048 3907024895 3907022848 1.8T fd Linux raid autodetect
/dev/sde1 2048 3907024895 3907022848 1.8T fd Linux raid autodetect
/dev/sdf1 2048 3907024895 3907022848 1.8T fd Linux raid autodetect

Mounting said drives as a mirrored drive om /dev/md127:

mdadm --assemble /dev/md127 /dev/sdd1 /dev/sde1 /dev/sdf1
mdadm: /dev/md127 has been started with 3 drives.

To check the status:

mdadm --detail /dev/md127
/dev/md127:
           Version : 1.2
     Creation Time : Wed Mar  6 22:16:05 2013
        Raid Level : raid1
        Array Size : 1953380160 (1862.89 GiB 2000.26 GB)
     Used Dev Size : 1953380160 (1862.89 GiB 2000.26 GB)
      Raid Devices : 3
     Total Devices : 3
       Persistence : Superblock is persistent

       Update Time : Sat Mar 19 07:07:49 2022
             State : clean 
    Active Devices : 3
   Working Devices : 3
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : resync

              Name : micemouse:0
              UUID : ed4531c4:59c132b2:a6bfc3d1:6da3b928
            Events : 6587

    Number   Major   Minor   RaidDevice State
       4       8       65        0      active sync   /dev/sde1
       5       8       81        1      active sync   /dev/sdf1
       3       8       49        2      active sync   /dev/sdd1

It's also possible to use:

mdadm --assemble --scan

Adding a drive

Previously I had only two drives, but I added one as follows:

# mdadm --grow /dev/md127 --add /dev/sdd1 --raid-devices=3
mdadm: added /dev/sdd1
raid_disks for /dev/md127 set to 3
Every 2.0s: cat /proc/mdstat                  sherlock: Sat Nov 24 15:28:29 2018

Personalities : [raid1]
md127 : active raid1 sdd1[3] sdf1[2] sde1[1]
      1953380160 blocks super 1.2 [3/2] [UU_]
      [>....................]  recovery =  0.0% (1446912/1953380160) finish=957.
9min speed=33959K/sec

unused devices: <none>

That took some time.

Thursday, 4 June 2015

RAID-1 Degraded - missing device

I have got two hard disks, both the same type/brand. They are two USB2.0 connected WesternDigital drives that work pretty well. I've setup a software-based RAID1 system using them both, by means of the MDADM Linux program. I find it works very well.

Thankfully I noticed something odd about the hard disks I used. It is probably due to Partial RAID1 mounting that I tried recently that I screwed something up.

The raid1 I setup contains two disks, as visible in the lsscsi command:
root@micemouse:~# lsscsi
[0:0:0:0]    disk    ATA      WDC WD5000AAKS-0 01.0  /dev/sda 
[4:0:1:0]    cd/dvd  SAMSUNG  DVD-ROM SDR-430  1.06  /dev/sr0 
[10:0:0:0]   disk    WD       Ext HDD 1021     2021  /dev/sdb 
[11:0:0:0]   disk    WD       Ext HDD 1021     2021  /dev/sdc
As you can see in the printout below, it is set to "Degraded", and we're missing one of the devices.
root@micemouse:~# mdadm --detail /dev/md127
/dev/md127:
        Version : 1.2
  Creation Time : Wed Mar  6 22:16:05 2013
     Raid Level : raid1
     Array Size : 1953380160 (1862.89 GiB 2000.26 GB)
  Used Dev Size : 1953380160 (1862.89 GiB 2000.26 GB)
   Raid Devices : 2
  Total Devices : 1
    Persistence : Superblock is persistent

    Update Time : Sat May 16 15:50:47 2015
          State : clean, degraded 
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0

           Name : micemouse:0  (local to host micemouse)
           UUID : ed4531c4:59c132b2:a6bfc3d1:6da3b928
         Events : 3748

    Number   Major   Minor   RaidDevice State
       0       0        0        0      removed
       1       8       33        1      active sync   /dev/sdc1
We are missing /dev/sdb1.

Rebuilding the array

Let's re-add the missing device.
root@micemouse:~# mdadm --remove /dev/md127 /dev/sdb1
mdadm: hot remove failed for /dev/sdb1: No such device or address
root@micemouse:~# mdadm --add /dev/md127 /dev/sdb1
mdadm: added /dev/sdb1
The array is rebuilding itself.
root@micemouse:~# mdadm -D /dev/md127
/dev/md127:
        Version : 1.2
  Creation Time : Wed Mar  6 22:16:05 2013
     Raid Level : raid1
     Array Size : 1953380160 (1862.89 GiB 2000.26 GB)
  Used Dev Size : 1953380160 (1862.89 GiB 2000.26 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Sat May 16 15:54:20 2015
          State : clean, degraded, recovering 
 Active Devices : 1
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 1

 Rebuild Status : 0% complete

           Name : micemouse:0  (local to host micemouse)
           UUID : ed4531c4:59c132b2:a6bfc3d1:6da3b928
         Events : 3750

    Number   Major   Minor   RaidDevice State
       2       8       17        0      spare rebuilding   /dev/sdb1
       1       8       33        1      active sync   /dev/sdc1
Trying out "watch -n 2 cat /proc/mdstat" to check on its progress (every two seconds in this case).
Every 2.0s: cat /proc/mdstat                            Sat May 16 16:00:38 2015

Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [ra
id10]
md127 : active raid1 sdb1[2] sdc1[1]
      1953380160 blocks super 1.2 [2/1] [_U]
      [>....................]  recovery =  0.2% (5763072/1953380160) finish=6519
.5min speed=4978K/sec

unused devices: <none>
Recovery in progress, but it looks a long long way away yet.

Much later...

After a very long time, /proc/mdstat mentioned that things were finished:
Every 60.0s: cat /proc/mdstat                           Sun May 17 22:23:29 2015

Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [ra
id10]
md127 : active raid1 sdb1[2] sdc1[1]
      1953380160 blocks super 1.2 [2/2] [UU]

unused devices: <none>
And a closer look at the raid device, shows:
root@micemouse:~# mdadm -D /dev/md127
/dev/md127:
        Version : 1.2
  Creation Time : Wed Mar  6 22:16:05 2013
     Raid Level : raid1
     Array Size : 1953380160 (1862.89 GiB 2000.26 GB)
  Used Dev Size : 1953380160 (1862.89 GiB 2000.26 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Sun May 17 20:46:50 2015
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : micemouse:0  (local to host micemouse)
           UUID : ed4531c4:59c132b2:a6bfc3d1:6da3b928
         Events : 5216

    Number   Major   Minor   RaidDevice State
       2       8       17        0      active sync   /dev/sdb1
       1       8       33        1      active sync   /dev/sdc1
The important part being "State: clean".

References

RAID1 - State : clean, degraded
https://www.howtoforge.com/community/threads/raid1-state-clean-degraded.66744/
Mdadm - recover degraded Array
https://www.thomas-krenn.com/en/wiki/Mdadm_recover_degraded_Array

Thursday, 28 May 2015

Partial RAID-1 mounting

I recently (read: ages ago) needed to bring my RAID1 disks to a friend, and it seemed silly for a mirrored disk array to bring more than 1 harddisk. Surely a single harddisk would cover it? Mount it read-only and away we go.

Let's take /dev/sdb1 drive of an array {/dev/sdb1, /dev/sdc1}.

The simplest way is to just start up the raid array using mdadm with a single disk2. But for some reason I failed to get this to work.

One way to do it (according to [1]), is to assume that the raidarray uses ext4 as an underlying filesystem and then just fiddle with the offsets.

The command "mdadm --examine /dev/sdb1" shows "Data Offset : 262144 sectors".

Then create a loop device, starting from that offset multiplied by the mdadm sector size (512).
losetup --find --show --read-only --offset $((262144*512)) /dev/sdb1
Than, simply mount the loop device.
mount /dev/loop0 /mnt/raid1/

References

[1] StackExchange - How to mount/recover data on a disk that was part of a mdadm raid 1 on another machine?
http://unix.stackexchange.com/questions/64889/how-to-mount-recover-data-on-a-disk-that-was-part-of-a-mdadm-raid-1-on-another-m
[2] sleeplessbeastie's notes - How to mount software RAID1 member using mdadm
https://blog.sleeplessbeastie.eu/2012/05/08/how-to-mount-software-raid1-member-using-mdadm/

Thursday, 21 May 2015

Mirroring a.k.a. RAID 1 - Followup

When connecting my two mirrored drives created with mdadm to another machine (my labtop in this case), this happens:

[ 3006.059308] usb 2-1.1: new high-speed USB device number 3 using ehci_hcd
[ 3006.145807] usb 2-1.1: New USB device found, idVendor=1058, idProduct=1021
[ 3006.145818] usb 2-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3006.145823] usb 2-1.1: Product: Ext HDD 1021
[ 3006.145828] usb 2-1.1: Manufacturer: Western Digital
[ 3006.145832] usb 2-1.1: SerialNumber: 574D43315431373033343231
[ 3006.149589] scsi8 : usb-storage 2-1.1:1.0
[ 3007.154933] scsi 8:0:0:0: Direct-Access WD Ext HDD 1021 2021 PQ: 0 ANSI: 4
[ 3007.157133] sd 8:0:0:0: [sdb] 3907024896 512-byte logical blocks: (2.00 TB/1.81 TiB)
[ 3007.157508] sd 8:0:0:0: Attached scsi generic sg2 type 0
[ 3007.158940] sd 8:0:0:0: [sdb] Write Protect is off
[ 3007.158956] sd 8:0:0:0: [sdb] Mode Sense: 17 00 10 08
[ 3007.160824] sd 8:0:0:0: [sdb] No Caching mode page present
[ 3007.160835] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[ 3007.166300] sd 8:0:0:0: [sdb] No Caching mode page present
[ 3007.166312] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[ 3007.182900] sdb: sdb1
[ 3007.188055] sd 8:0:0:0: [sdb] No Caching mode page present
[ 3007.188067] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[ 3007.188073] sd 8:0:0:0: [sdb] Attached SCSI disk
[ 3007.764265] md: bind
[ 3013.631277] usb 2-1.2: new high-speed USB device number 4 using ehci_hcd
[ 3013.717235] usb 2-1.2: New USB device found, idVendor=1058, idProduct=1021
[ 3013.717246] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3013.717251] usb 2-1.2: Product: Ext HDD 1021
[ 3013.717256] usb 2-1.2: Manufacturer: Western Digital
[ 3013.717261] usb 2-1.2: SerialNumber: 574D43315432313138383334
[ 3013.718543] scsi9 : usb-storage 2-1.2:1.0
[ 3014.722760] scsi 9:0:0:0: Direct-Access WD Ext HDD 1021 2021 PQ: 0 ANSI: 4
[ 3014.724734] sd 9:0:0:0: Attached scsi generic sg3 type 0
[ 3014.725314] sd 9:0:0:0: [sdc] 3907024896 512-byte logical blocks: (2.00 TB/1.81 TiB)
[ 3014.727731] sd 9:0:0:0: [sdc] Write Protect is off
[ 3014.727744] sd 9:0:0:0: [sdc] Mode Sense: 17 00 10 08
[ 3014.729563] sd 9:0:0:0: [sdc] No Caching mode page present
[ 3014.729575] sd 9:0:0:0: [sdc] Assuming drive cache: write through
[ 3014.735276] sd 9:0:0:0: [sdc] No Caching mode page present
[ 3014.735287] sd 9:0:0:0: [sdc] Assuming drive cache: write through
[ 3014.753371] sdc: sdc1
[ 3014.758786] sd 9:0:0:0: [sdc] No Caching mode page present
[ 3014.758796] sd 9:0:0:0: [sdc] Assuming drive cache: write through
[ 3014.758802] sd 9:0:0:0: [sdc] Attached SCSI disk
[ 3015.063908] md: bind
[ 3015.153298] md: raid1 personality registered for level 1
[ 3015.153537] bio: create slab at 1
[ 3015.153667] md/raid1:md127: not clean -- starting background reconstruction
[ 3015.153670] md/raid1:md127: active with 2 out of 2 mirrors
[ 3015.153729] md127: detected capacity change from 0 to 2000261283840
[ 3015.161179] md127: unknown partition table
Turns out, a device is automatically made, called /dev/md127.

Saturday, 6 April 2013

Mirroring a.k.a. RAID 1


Introduction


I have recently bought 2 WD (Western Digital) 2 TB Elements external (USB 2.0) harddrives. I am using them for making Backups, therefore I considered a NAS to be overkill.

This article is pure for me to remember the steps I took to get RAID 1 working, and which devices I have, and what my logs said.

The steps followed are basically the steps as mentioned in [1].

Steps


# yum install mdadm
# apt-get update && apt-get install mdadm
# fdisk /dev/sdb
# fdisk /dev/sdc
# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
# mkfs.ext3 -j -Lraid1 -v -m1 /dev/md0
-- -v = verbose
-- -m1 = percentage of disk used for Root, 1% is more than enough (=20gb)
-- -j = journaling
-- -L = label, in this case "raid1".
# mkdir /mnt/raid1
# mount /dev/md0 /mnt/raid1
# df -H
What my system said in "dmesg", once the drives were under power and plugged into USB ports.
[ 1128.092533] usb 2-1.3: new high-speed USB device number 8 using ehci_hcd
[ 1128.189507] Initializing USB Mass Storage driver...
[ 1128.189698] scsi10 : usb-storage 2-1.3:1.0
[ 1128.189820] usbcore: registered new interface driver usb-storage
[ 1128.189824] USB Mass Storage support registered.
[ 1129.190936] scsi 10:0:0:0: Direct-Access     WD       Ext HDD 1021     2021 PQ: 0 ANSI: 4
[ 1129.192184] sd 10:0:0:0: Attached scsi generic sg2 type 0
[ 1129.195482] sd 10:0:0:0: [sdb] 3907024896 512-byte logical blocks: (2.00 TB/1.81 TiB)
[ 1129.197278] sd 10:0:0:0: [sdb] Write Protect is off
[ 1129.197284] sd 10:0:0:0: [sdb] Mode Sense: 17 00 10 08
[ 1129.199146] sd 10:0:0:0: [sdb] No Caching mode page present
[ 1129.199153] sd 10:0:0:0: [sdb] Assuming drive cache: write through
[ 1129.204101] sd 10:0:0:0: [sdb] No Caching mode page present
[ 1129.204118] sd 10:0:0:0: [sdb] Assuming drive cache: write through   
[ 1129.220472]  sdb: sdb1
[ 1129.225647] sd 10:0:0:0: [sdb] No Caching mode page present
[ 1129.225653] sd 10:0:0:0: [sdb] Assuming drive cache: write through
[ 1129.225658] sd 10:0:0:0: [sdb] Attached SCSI disk
[ 1131.676246] usb 2-1.8: new high-speed USB device number 9 using ehci_hcd
[ 1131.770350] scsi11 : usb-storage 2-1.8:1.0
[ 1132.770974] scsi 11:0:0:0: Direct-Access     WD       Ext HDD 1021     2021 PQ: 0 ANSI: 4
[ 1132.772018] sd 11:0:0:0: Attached scsi generic sg3 type 0
[ 1132.773413] sd 11:0:0:0: [sdc] 3907024896 512-byte logical blocks: (2.00 TB/1.81 TiB)
[ 1132.775265] sd 11:0:0:0: [sdc] Write Protect is off
[ 1132.775274] sd 11:0:0:0: [sdc] Mode Sense: 17 00 10 08
[ 1132.777192] sd 11:0:0:0: [sdc] No Caching mode page present
[ 1132.777198] sd 11:0:0:0: [sdc] Assuming drive cache: write through
[ 1132.781952] sd 11:0:0:0: [sdc] No Caching mode page present
[ 1132.781958] sd 11:0:0:0: [sdc] Assuming drive cache: write through
[ 1132.800861]  sdc: sdc1
[ 1132.805944] sd 11:0:0:0: [sdc] No Caching mode page present
[ 1132.805950] sd 11:0:0:0: [sdc] Assuming drive cache: write through
[ 1132.805956] sd 11:0:0:0: [sdc] Attached SCSI disk
Originally, the drives came preformatted with NTFS, but that was easily fixed.
root@micemouse:~# fdisk /dev/sdb

Command (m for help): p

Disk /dev/sdb: 2000.4 GB, 2000396746752 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907024896 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: 0x000575ba

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  3907024895  1953511424    7  HPFS/NTFS/exFAT

Command (m for help):

root@micemouse:~# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm: /dev/sdb1 appears to be part of a raid array:
    level=raid0 devices=0 ctime=Thu Jan  1 01:00:00 1970
mdadm: partition table exists on /dev/sdb1 but will be lost or
       meaningless after creating array
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
mdadm: /dev/sdc1 appears to be part of a raid array:
    level=raid0 devices=0 ctime=Thu Jan  1 01:00:00 1970
mdadm: partition table exists on /dev/sdc1 but will be lost or
       meaningless after creating array
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
Time to grab a cup of something for the next part. Formatting 2 Terabytes takes a while.
root@micemouse:~# mkfs.ext3 -j -Lraid1 -v -m1 /dev/md0
mke2fs 1.42 (29-Nov-2011)
fs_types for mke2fs.conf resolution: 'ext3'
Filesystem label=raid1
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
122093568 inodes, 488345040 blocks
4883450 blocks (1.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
14904 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
    102400000, 214990848

Allocating group tables: done                           
Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Status

# watch -n 2 cat /proc/mdstat   
# tail -f /proc/mdstat
# mdadm --query /dev/md0

maartenl@micemouse:~$ tail -f /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
      1953380160 blocks super 1.2 [2/2] [UU]
      [>....................]  resync =  0.1% (2340864/1953380160) finish=1801.8min speed=18046K/sec
     
unused devices: <none>
tail: /proc/mdstat: file truncated
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
      1953380160 blocks super 1.2 [2/2] [UU]
      [>....................]  resync =  0.1% (2340864/1953380160) finish=1801.8min speed=18046K/sec
     
unused devices: <none>

References

[1] How to configure usb mybooks as RAID 1
http://martystech.lucidway.org/2008/01/how-to-configure-usb-mybooks-as.html
Linux - creating software reaid one arrays
http://www.cyberciti.biz/faq/linux-creating-software-raid-one-arrays/
Software RAID HOWTO
http://tldp.org/HOWTO/Software-RAID-HOWTO.html
RAID - Wikipedia
http://en.wikipedia.org/wiki/RAID
Linux RAID HOWTO
https://raid.wiki.kernel.org/index.php/Linux_Raid