NSLU2-Linux
view · edit · print · history

HowTo.RaidLinearOnSlugOS History

Hide minor edits - Show changes to markup

January 05, 2009, at 09:26 PM by Kimmo Pietarinen --
Changed line 1 from:

Linear RAID for SlugOS

to:

Linear RAID for SlugOS/BE

Changed line 53 from:

A NSLU2 is available with SlugOS installed and the RAID is going to be on a

to:

A NSLU2 is available with SlugOS/BE (OpenSlug) installed and the RAID is going to be on a

January 05, 2009, at 09:16 PM by Kimmo Pietarinen -- Minor formatting changes
Changed line 14 from:

250MB drive and then bought a 500MB drive. Later I decided to get a 750 to have

to:

250GB drive and then bought a 500GB drive. Later I decided to get a 750GB drive to have

Changed line 42 from:

USB devices have no fixed mount point by default. The device name can

to:

USB devices have no fixed mount points by default. The device name can

Added line 66:
Added line 71:
Added line 76:
Added line 81:
Added line 88:
Added line 95:
Added line 102:
Added line 131:
Added line 138:
Added line 143:
Added line 148:
Added line 168:
Added line 175:
Added line 181:
Added line 186:
Added line 200:
Added line 207:
Changed lines 251-252 from:

@]

to:

@]

Added line 258:
January 05, 2009, at 09:08 PM by Kimmo Pietarinen -- Linear raid howto, initial revision
Added lines 1-242:

Linear RAID for SlugOS

This howto describes how to setup a linear raid on your nslu2 device. I have gathered information for this how to from a number of excellent howtos on this site, like http://www.nslu2-linux.org/wiki/HowTo/RAID1OnSlugOS and http://www.nslu2-linux.org/wiki/HowTo/Partitionable-Software-RAID-6-on-OpenSlug. Although the information is available at the other pages, I think my "concept" is worth publishing for others.

Background

I want share my disk setup for the nslu2 with this community. I hope someone can have some use of the information published here to setup their own nslu2 device. I am very impressed with the capacity of this wonderful little thing. I have several USB drives of various sizes connected to my nslu2. I started with an 250MB drive and then bought a 500MB drive. Later I decided to get a 750 to have as a main disk, which I can rsync to the two other drives.

I first thought that I should use LVM to create a logical volume with the contents of the two other drives. Unfortunately there is no information available how to do this on SlugOS (maybe it is not even possible?). I therefore looked further for other solutions as UnionFS? etc. Finally I settled with using a linear RAID setup, as this seems to have good support in SlugOS.

Linear RAID

RAID-linear is one of the options that can be selected when using LINUX software RAID. It is a simple concatenation of partitions for creating a single larger partition. As noted in the LINUX software RAID HOWTO, this actually decreases reliability as you get more devices that can break your filesystem. I use it only as a backup storage so for me it is not an issue. If it fails, I will most likely have the main disk available with data.

Goals

My goals for setting up the RAID is to have a single partition with (at least) the same capacity as my main hard drive that I can have to backup all my files. I have no intentions of having a 'real' backup with features like recovering deleted files etc. I just want have a snapshot backup using rsync. I will not go into how to setup that as it is beyond the scope of this HOWTO.

Also I want to have the backup partition automatically mounted when the nslu2 is rebooted.

Mount by Label

USB devices have no fixed mount point by default. The device name can change as you change how they are connected to the NSLU2. I have therefore utilized disk labels to setup the mount points. I will show you later how this can be done. Without this it is a real pain to manage USB drives. You can also add a similar technique into the /etc/udev/scripts/boot.sh script for your other USB drives. That is what I have done.

Actually I could have hardcoded the RAID partition mount point, but I wanted to be consistent with how I manage my other partitions.

Prerequisites

A NSLU2 is available with SlugOS installed and the RAID is going to be on a non-root file system. I am using a USB memory stick myself for my root filesystem which I find very convinient (easy to backup etc).

I also expect that the reader has quite good knowledge of how LINUX works and the tools used to manage and create file systems.

Preparations

Login as root and install the kernel modules for linear RAID.

# ipkg update
# ipkg install kernel-module-linear

Install the RAID management tool:

# ipkg install mdadm

Make the kernel aware of the new modules:

# depmod

I use also e2label to read disk labels. Install it if you want to utilize it too.

# ipkg install e2fsprogs

Partitioning RAID members

If you are uncertain which disks to use for creating the RAID, use the following command to list available disks and partitions.

cat /proc/partitions

To view detailed information about the USB storage devices, use udevinfo.

Example: Display information about the /dev/sdc device.

# udevinfo -a -p /sys/block/sdc

Now, I assume that you have identified the drives for using as raid members. Then let us create new partitions on these. (I use the drives sdc and sdd in my examples)

# fdisk /dev/sdc

Hit <p> and <Enter> to display the partitions. Choose <d> and select any available partitions and delete them until there are no more left. Select <n> and <p> for 'primary' partition. Then just hit <Enter> and accept the default start and stop blocks to create a partition that spans the entire disk.

Then set the partition type by hitting <t> and choosing 'fd' (Linux raid autodetect).

Finally hit <w> to save the partition layout.

Repeat this for all disks that will be a part of the RAID.

Reboot to make the changes effective.

Create the RAID

Load the raid module:

# modprobe linear
# lsmod
Module                  Size  Used by
linear                  3808  1 
md_mod                 64564  2 linear
ixp400_eth             24156  0 
ixp400                949188  1 ixp400_eth
ext3                  109864  4 
jbd                    45940  1 ext3
mbcache                 5540  1 ext3

Make sure that the modules, md_mod and linear are loaded.

Create the RAID device:

# mknod /dev/md0 9 4

Create the RAID:

# mdadm --create --verbose /dev/md0 --level=linear --raid-devices=2 /dev/sdc1 /dev/sdd1

Now, create a file system on the RAID.

# mkfs.ext3 -m 0 -O sparse_super -L backup /dev/md0

My drive will only contain personal data files so I want to maximize the space and therefore I do not want to have any reserved space for root and my RAID is also large so I enable the 'sparse_super' option to save additional space. I also use the partition label to mount the partition so I assing an appropriate label here 'backup'.

Create unique RAID member devices

As we are using USB storage drives for our RAID, we will have problems if we reorder the way the drives are connected to the SLUG, because the drives might be assigned different device names. I use the udev daemon to create unique links that points to the correct drives.

Use udevinfo to identify something unique on your drives

# udevinfo -a -p /sys/block/sdc
...
# udevinfo -a -p /sys/block/sdd
...

I used the SYSFS(model) string as all my drives are different.

Edit the udev local.rules file:

# vi /etc/udev/rules.d/local.rules

Modify the two lines after the Media automounting line (Add the chosen string as argument 1):

SUBSYSTEM=="block", ACTION=="add"    RUN+="/etc/udev/scripts/mount.sh '%s{model}'"
SUBSYSTEM=="block", ACTION=="remove" RUN+="/etc/udev/scripts/mount.sh '%s{model}'"

Then edit the SlugOS mount script:

# vi /etc/udev/scripts/mount.sh

Add these lines after the blacklist check. (Replace OneTouch? and 2500JB External with your chosen unique strings):

# Make links to raid devices
model="`trim $1`"
if [ "$model" = "OneTouch" ]; then
    ln -s `basename $DEVNAME` /dev/mdd1
    exit 0
elif [ "$model" = "2500JB External" ]; then
    ln -s `basename $DEVNAME` /dev/mdd2
    exit 0
fi

The exit command is executed, because we do not want to auto mount these partitions.

Create the boot script

# vi /etc/init.d/raid

Add the following contents to the 'raid' file:

#!/bin/sh                                                                      
# /etc/init.d/raid                                                              
#                                                                               

RMDIR=/bin/rmdir                                                                
MOUNT=/bin/mount                                                                
UMOUNT=/bin/umount                                                              
E2LABEL=/sbin/e2label                                                           
MODPROBE=/sbin/modprobe                                                         
MDADM=/sbin/mdadm                                                               
MKNOD=/bin/mknod                                                                

# Some things that run always                                                   
touch /var/lock/raid                                                            
raiddev=/dev/md0                                                                

# Carry out specific functions when asked to by the system                      
case "$1" in                                                                    
  start)                                                                        
   echo "Starting script raid "                                                 
   $MODPROBE linear                                                             
   $MKNOD "$raiddev" b 9 4 2>/dev/null                                          
   $MDADM --assemble "$raiddev" /dev/mdd1 /dev/mdd2                             
   name=`$E2LABEL "$raiddev" || echo raid`                                      
   mp="/media/$name"                                                            
   ! test -d "$mp" && mkdir -p "$mp"                                            
   if ! $MOUNT -o noatime "$raiddev" "$mp"; then                                
       $RMDIR "$mp"                                                             
       echo "Failed to mount $raiddev at $mp" >&2                               
       exit 1                                                                   
   fi                                                                           
   ;;                                                                           
 stop)                                                                          
   echo "Stopping script raid"                                                  
   $UMOUNT $raiddev                                                             
   $MDADM --stop $raiddev                                                       
   ;;                                                                           
 *)                                                                             
   echo "Usage: /etc/init.d/raid {start|stop}"                                
   exit 1                                                                       
   ;;                                                                           

Add the script to the boot sequence:

# chmod 755 /etc/init.d/raid
# update-rc.d raid start 2345 stop 016 90 

Now we are done. Reboot and cross your fingers.

(You can put for example echo statements that redirects the output to a file to debug the modified scripts if they do not work as expected. E.g. echo "foo" > /tmp/debug.txt)

view · edit · print · history · Last edited by Kimmo Pietarinen.
Originally by Kimmo Pietarinen.
Page last modified on January 05, 2009, at 09:26 PM