document

Software RAID and LVM2 on Slackware 10.2

Introduction

Lately I've been tinkering with the idea of increasing the reliability of my server, and the first thing to do, although it doesn't increase uptime it does make sure no important data is lost due to hard-drive failure, is set up RAID. Most computers nowadays come with RAID-controllers directly implemented on the motherboard, but these are usually badly made knockoffs just barely fitting the description hardware-RAID (for instance those implemented in Nvidia nForce 3/4 chipsets).

The only real option with these things is simply to use software RAID instead that while having comparative performance supports a lot more features, which if you have the disks to use RAID-level 5 is a mentionable step up. In order to make the solution a little more flexible I'm also going to use LVM2 to manage the disk space on the RAID.

Table of Contents


0. Hardware

The computer I'm using for the purpose of this document has the following specifications, and while not everything is top dollar equipment it probably compares to most generic homebuilt Linux desktops these days:
  • MSI K8N NEO2-FX,nForce3 250Gb,Socket-939
  • AMD Athlon64(TM) 3000+
  • 1GB Crucial Value PC3200 DDR RAM
  • Western Digital Caviar SE 200GB IDE ATA/100 8MB 7200RPM
  • 2x Western Digital Caviar SE16 250GB SATA2
  • Creative SB Audigy
  • Sapphire Radeon 7000 32MB SDR
The operating system currently used on this system, and will be the object of this document, is Slackware version 10.2. Some steps described here will probably be superfluous in new version of Slackware since later version probably have better out-of-the-box support for software RAID and LVM2. In order to follow this guide you will also need to use the 2.6-kernel instead of the standard 2.4-kernel - the kernel-image "test26.s" that comes with this distribution will work perfectly, and is also the one I'll be using for this guide, as long as you remember to install the kernel-modules found on the second cd.

1. Software RAID

I've recently purchased two new Western Digital Serial ATA disks that I plan to use in a RAID-mirror configuration, and my computer automatically loaded the correct modules needed to use these via the SATA-controller so in a comparable configuration there shouldn't be any problems. Software RAID is set-up and configured using the mdadm-utility (package is called "mdadm 2.1-i486-1"), but first we'll need to set up two partitions, one on each drive in the mirror (/dev/sda and /dev/sdb on my system), of equal size (I used 100GB for this purpose) with the partition type set to "Linux raid autodetect" - see the image below as to how this looks like in cfdisk (command used was "cfdisk /dev/sdb").
cfdisk /dev/sda
cfdisk /dev/sdb

1.0 Creating the array

We're now ready to set-up software RAID using the previously created partitions (make sure you've loaded the module "dm_mod") using the mdadm-utility.
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
The RAID will now have been created, but it'll take a long way for the array to be successfully built and while you could strictly speaking continue working on it until it's done I'd recommend that you wait just incase something bad happens. You can monitor the process by running the following command:
mdadm --detail /dev/md0

1.1 Software RAID configuration

The RAID device should now be fully operational and ready for use, but as it is now all details about it will be lost after a reboot so we'll have to make some configuration changes in order to make the device available at boot. The first step is editing the file "/etc/mdadm.conf" and make sure it lists all the devices used in the RAID by adding a line such as the following:
DEVICE /dev/sda1 /dev/sdb1
We also need to specify the actual RAID-configuration and while this is a bit harder to do manually we can simply make this happen automatically by giving the following command:
mdadm --examine --scan >> /etc/mdadm.conf

1.2 Altering Slackware 10.2 so that RAID-volumes can be mounted at boot

The last and final thing we now need to do is to make sure that Slackware starts the RAID before we try to use it as part of a LVM-configuration and in order to do that we need to edit the file /etc/rc.d/rc.S and add the following section just before the initialization of the Logical Volume Manager:
#
# Start any configured RAID arrays
#
/sbin/mdadm --assemble --scan
This should now allow any RAID-volumes to be used and mounted automatically via "/etc/fstab".

2. Logical Volume Manager, version 2 (LVM2)

Setting up LVM is thankfully a lot easier, but you should first make sure that LVM version 1 isn't still installed on the system (package is named "lvm 1.0.8-i486-1") and if it is start by removing it. Packages for LVM2 aren't directly available for Slackware 10.2, but the ones in the extra packages directory for Slackware-current are and they can be used on this version of Slackware as well - download and install the packages "lvm2-2.02.09-i486-1.tgz" and "device-mapper-1.02.09-i486-1.tgz" from your local mirror, or just get them from the Norwegian mirror.

From this point on LVM2 is heavily documented all over the web and there really isn't that much of a need for detailed descriptions of the configuration I'm using, but the following se of commands will set things off by first initializing LVM2 on the RAID-volume, creating a volume group on top of that and finally create an LVM-volume we'll call "mirror" that we'll finally format using the Reiser filesystem.
# Initialize LVM2 on our RAID-device
pvcreate /dev/md0

# Create LVM volume-group simply named lvm-raid
vgcreate lvm-raid /dev/md0

# Show details about newly created volume group
vgdisplay lvm-raid

# Create a 50GB large LVM-partition on volume group "lvm-raid" called "mirror"
lvcreate -L 50G lvm-raid -n mirror

# Format the partition and mount the partition on a new mountpoint
mkfs.reiserfs /dev/lvm-raid/mirror
mkdir /mnt/mirror
mount /dev/lvm-raid/mirror /mnt/mirror
That should be all that there is to it so enjoy your new flexible LVM2-system with added reliability of a RAID1 (mirroring) configuration.

3. Relevant links