Linux software RAID

Recently I got two Maxtor 80GB disks. Sometimes the existing external hard disk runs out of space but can be easily sorted by erasing unnecessary data. As this external hard disk has been on constant use for around 4 years I thought it might be a good idea to use the additional Maxtors to build a software RAID and backup the existing external disk that stores the data.

My setup is pretty simple as all of the disks are external and connected via USB with the main system. The two 80GB disks are on RAID-1 (mirroring) syncing (via rsync in a cron-job) all the required data from the existing external hard disk. To keep syncing simple, I’ve created two single partitions (/dev/sdb1 and /dev/sdc1) on each of the RAID disks and then created a RAID-1 /dev/md0

I tried two different ways configuring the RAID, one with raidtools2 and one with mdadm.

mdadm is straight forward and can be used directly from the command file as below:

mdadm --create --verbose /dev/md0 --level=raid1 --raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm: chunk size defaults to 64K
mdadm: /dev/sdb1 appears to contain an ext2fs file system
    size=78156192K  mtime=Thu Jan  1 01:00:00 1970
mdadm: /dev/sdc1 appears to contain an ext2fs file system
    size=78156192K  mtime=Thu Jan  1 01:00:00 1970
Continue creating array? (y/n) y
mdadm: array /dev/md0 started.

There is no need to explain the mdadm parameters as it is pretty much obvious what is happening. A look at the man page reveals all the possible options and what they stand for.

You can also check in /proc/mdstat to see if the RAID is running:

# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
      167772160 blocks 64k rounding

The other way is to use raidtools and declare the raid setup in /etc/raidtab:

$ cat /etc/raidtab
raiddev /dev/md0
        raid-level      1
        nr-raid-disks   2
	nr-spare-disks	0
	chunk-size	4
        persistent-superblock 1
        device          /dev/sdc1
        raid-disk       0
        device          /dev/sdd1
        raid-disk       1

And then the raid can be created:

# mkraid /dev/md0
handling MD device /dev/md0
analyzing super-block
disk 0: /dev/sdb1, 78156193kB, raid superblock at 78156096kB
disk 1: /dev/sdc1, 78156193kB, raid superblock at 78156096kB

Either way, raidtools or mdadm, you can then create and format partitions on /dev/md0 the normal way, using fdisk and mkfs.ext*. Once done so, the partitions can be mounted as would any other partition and syncing between the external storage disk and the raid can start.

I think that I’ll stick with mdadm as it is easier and more flexible than raidtools.

Some useful links:

How to replace a failed disk on Linux software RAID-1
mdadm: A new tool for Linux software RAID management
The Software-RAID HOW-TO

Advertisement

SAS RAID 0 on Linux

We have a Dell PowerEdge R900 server with two SAS 300GB disk forming a RAID 1. There was a need of around 2TB of space and for that reason we bought 2 x 1TB SAS disks and attached them on the machine.
I’d expect that Linux (Scientific Linux 5.2) would automatically see the disks and display them on the “fdisk -l” output. But unfortunately that didn’t work. Checking with “dmesg” the disks were detected (and the PERC controller of course):

megasas: FW now in Ready state
scsi1 : LSI SAS based MegaRAID driver
  Vendor: SEAGATE   Model: ST3300555SS       Rev: T211
  Type:   Direct-Access                      ANSI SCSI revision: 05
  Vendor: SEAGATE   Model: ST3300555SS       Rev: T211
  Type:   Direct-Access                      ANSI SCSI revision: 05
  Vendor: SEAGATE   Model: ST31000640SS      Rev: MS04
  Type:   Direct-Access                      ANSI SCSI revision: 05
  Vendor: SEAGATE   Model: ST31000640SS      Rev: MS04
  Type:   Direct-Access                      ANSI SCSI revision: 05
usb 1-7: new high speed USB device using ehci_hcd and address 3
  Vendor: DP        Model: BACKPLANE         Rev: 1.06
  Type:   Enclosure                          ANSI SCSI revision: 05
  Vendor: DELL      Model: PERC 6/i          Rev: 1.11
  Type:   Direct-Access                      ANSI SCSI revision: 05

I was a bit puzzled on why the system didn’t show the disks while being detected. Checking under /proc/scsi/scsi just confirmed that the disks weren’t available to the system at all:

cat /proc/scsi/scsi 
Attached devices:
Host: scsi0 Channel: 00 Id: 32 Lun: 00
  Vendor: DP       Model: BACKPLANE        Rev: 1.06
  Type:   Enclosure                        ANSI SCSI revision: 05
Host: scsi0 Channel: 02 Id: 00 Lun: 00
  Vendor: DELL     Model: PERC 6/i         Rev: 1.11
  Type:   Direct-Access                    ANSI SCSI revision: 05

After a bit of Googling I came across a post on a forum which was saying that the disks should be built in a array in order to be available to the system. That actually means that the disks have to be Online and configured on the PERL controller and then the controller would make them available to the system. Next step was to reboot the machine and run the disk configuration utility.
While being in the utility, the steps for creating a RAID0 array for concatenating the disks’ were:
– Select the right PERC controller
– Check disks status on the Physical Disk Management page (the status indication for the new disks was “OFFLINE” so that explained to me why the disks weren’t accessible)
– Return to the Virtual Disk Management page
– Select Controller 1 from the top
– New Virtual Disk
– Select the two available hard drives
– Check available space
– Specify name
– Select stripe option
– OK
– Return to VD Management page
– Exit the utility
– Reboot the machine
– Job done 🙂

Then, “fdisk -l” would display the new /dev/sdb device with 2TB of space free. Just to confirm that everything was there:

cat /proc/scsi/scsi 
Attached devices:
Host: scsi1 Channel: 00 Id: 32 Lun: 00
  Vendor: DP       Model: BACKPLANE        Rev: 1.06
  Type:   Enclosure                        ANSI SCSI revision: 05
Host: scsi1 Channel: 02 Id: 00 Lun: 00
  Vendor: DELL     Model: PERC 6/i         Rev: 1.11
  Type:   Direct-Access                    ANSI SCSI revision: 05
Host: scsi1 Channel: 02 Id: 01 Lun: 00
  Vendor: DELL     Model: PERC 6/i         Rev: 1.11
  Type:   Direct-Access                    ANSI SCSI revision: 05

And the last thing was to create a huge filesystem and mount it on the system 🙂