Mirrored drives on Fedora 7 and 8

This is a companion piece to my earlier post on Mirrored USB drives under Linux, and covers a few bits and pieces that should make your life just that little bit easier.

The first thing that you need to be aware of is that in Fedora 7 and above you will no longer see IDE drives listed as /dev/hdX, but instead they are re-mapped to an equivalent SCSI style name, such as /dev/sdX. This has resulted in an absolute mandatory rule that you should no longer use device names in your file system table. You need to ensure everything uses a file system label. If you are using LVM (Logical Volume Management) then the device names (such as /dev/VolGroup00/LogVol00) are OK and you won't have to label those file systems, but it doesn't hurt to do so anyway.

This piece presumes that you have a working bootable system and are adding a mirrored pair (or indeed a RAID 5 stripe) to your system as secondary storage. I'll cover bootable RAID in a future article.

The process is relatively easy if you are creating a simple RAID array and not going to overlay LVM on top of it.

Basically you need to check that you have the mdadm utility. This comes in the mdadm package on Fedora linux, but you may find it in raidtools or some other name on other distributions.

Step 1: Install the drives.

Install the hardware, and boot back into a usable system. You can boot into single user mode if you like. If you have the GRUB boot loader then you can use the 'a' command to append to the boot command before the system boots. If you don't have a menu of options but simply a countdown, hit return and you'll see the default kernel. Press 'a' and then add a 's' to the end of the command as a word on its own. Then hit return to boot the amended kernel configuration. This is only for this boot so it won't affect future start ups.

Step 2: Set up partitions

For this you need to use fdisk. You need to know what disks are what before using this so you don't destroy what you already have set up. Try cat /proc/scsi/scsi. This should give you a list of devices in the order they are found on the system. Look for those marked as 'Direct Access', or basically anything that isn't a DVD or CDROM and start numbering from the top as sda, sdb, sdc etc. It doesn't really matter if you get it wrong at this stage as we will verify when we fire up fdisk.

Now assuming you have one existing drive, the two new drives will be at /dev/sdb and /dev/sdc. So lets set them up (and I'll do /dev/sdb, but both are set the same way). What you type in is shown in bold, the rest is what the system will display (which will of course be dependent on your hardware).


fdisk /dev/sdb

The number of cylinders for this disk is set to 14410.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help):

For a new disk you may also see a warning about an invalid partition table. This is nothing to worry about and is perfectly normal. In that situation you can skip the check following, but it won't hurt if you do do it:

Command (m for help): p

Disk /dev/sdb: 118.5 GB, 118526284800 bytes
255 heads, 63 sectors/track, 14410 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help):

Note that in this case we don't have any existing devices set up, which is what we would expect of a new drive, however if you do see a list it will either be that we have chosen the wrong drive (in which case use the 'q' option and check your drive designations) or the drive has been recycled or pre-installed and you need to remove the partitions. I won't cover that just yet though, lets proceed on a virgin disk.


Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

There you have it, you have now created /dev/sdb1 as a Linux RAID partition that will be auto-detected on boot.

Do the same for the second drive. If you get errors in the final stage don't panic, you just need to reboot before taking the next step.

Step 3: Building the RAID device

There are a lot of options to mdadm, but if this is the first RAID device you've created it should be relatively simple:

mdadm -C /dev/md0 -n2 -l1 /dev/sdb1 /dev/sdc1

To decipher, -C (or --create) creates a new RAID device and starts it (unless there were errors in the creation). The first device name is the name the new RAID device will take. -n2 says that we will have 2 devices in the array and -l1 says to use RAID level 1 (mirrored pair). Then follows the two devices we want to build the array from, in this case the newly created autodetecting RAID partitions.

Step 4: Build a file system

I'm assuming you want to use the entire RAID device as a file system, so this part is relatively easy:

mke2fs -j -L MyNewRaidDevice /dev/md0

The -j says that we want an EXT3 file system rather than an EXT2 file system (basically adds the journal). The -L option allows us to provide a file system label, which can be any string up to 16 characters long. This becomes the "handle" by which we can mount the file system later on.

Step 5: Create a mount point

We need a point in the current file system to attach the new file system. This is just an empty directory that we create somewhere convenient. I've chosen /mirror here.

mkdir /mirror

Step 6: Add file system to file system table

We need to edit /etc/fstab and add the new device so it will be available on reboot, and to make mounting it easier. Here we add a line like:

LABEL=MyNewRaidDevice /mirror ext3 defaults 0 0

The first field tells the system the device to use, in this case we've used the label of the file system (which is the best option in Fedora 7 and above otherwise upgrades are problematic). In older versions we could have used /dev/md0 just as easily.

The second field is the mount point, the directory we created in the last step.

The third field is the file system type.

The next field is the mount options, which in this case we set to the defaults.

The last two fields are related to backup frequency and check order. If you want the file system checked on boot, make the last field 2 instead of zero.

Step 7: Reboot and enjoy

You could simply mount the file system if you don't want to reboot, but we want to make sure everything will come up clean in case of a power failure, so we reboot and watch it all happen.

No feedback yet


Form is loading...