RAID-1, Part 2

How to make a RAID-1 swap device and how to boot from a RAID-1 device, using RAID-1 to facilitate disk backups.

If you are using RAID-1 to help to ensure that your system stays up in the event of a hard disk partition failure, you should consider raiding your swap partition(s). If the disk or partition you are using for swap goes bad, your machine may crash. Using a RAID-1 device for a swap partition can help prevent that crash. If one of the mirrored swap partitions goes bad, the kernel automatically will fail over to the other, and your system should keep running until you can fix the disk problem. The steps that can be used to set up swap on a RAID-1 device are outlined below:

  1. Partition the second disk. See Part 1 of this article for details about this step.

  2. Create /etc/raidtab with an entry for the swap partition. The raidtab file is used by mkraid to configure the RAID device and write the RAID superblock. Once the RAID device is configured, the RAID superblock is used to detect the device. The raidtab file is not used when an existing RAID device is activated. The raidtab entry that was used in this example is shown in Listing 1.

  3. Turn off swap so that the swap RAID array can be created. If you machine is lightly loaded you may be able to turn off swap without causing problems. However, turning off swap could cause a machine to crash. Don't turn off swap unless you can recover from a crash. To be safe, you can go to single-user mode and stop all the user processes on the machine. You can turn off swap, on a Linux machine, using the command swapoff -a; the command swapoff /dev/swappartition also may work. Typing swapon -s will show you the name of the swap partition, before you turn it off, and it will indicate that you have turned off swap after you run swapoff. A safer way to turn off swap is to disable the swap device in /etc/fstab and reboot the machine with no swap enabled. That way, there's no possibility of causing a crash, because swapoff does not have to be invoked.

  4. Use fdisk to toggle the filesystem type of the swap partition on the first disk. You should have already set the swap partition on the second disk to fd (Linux RAID autodetect). If you compile RAID-1 support into the kernel and have the swap partition filesystem type set to fd, your machine can mount the swap RAID-1 array during boot. Otherwise, you'll have to use init scripts to mount the swap RAID-1 array after the disk that contains the md module is mounted. Some will prefer to set up the RAID-1 arrays this way. We don't cover that approach in this article.

  5. Make the new RAID-1 swap array with mkraid /dev/md2. After you run that, type cat /proc/mdstat; /proc/mdstat should indicate that the RAID-1 personality exists (Personalities : [raid1]) and that /dev/md2 is active (md2 : active raid1 hdc4[1] hda4[0]). If it doesn't, you're into troubleshooting mode. For troubleshooting help use the references provided below.

  6. Make the new RAID array a swap partition. Use the command mkswap /dev/md2, but do not mkswap on the RAID-1 component partitions, in this case /dev/hda4 and /dev/hdc4.

  7. Turn swap on using with swapon /dev/md2. swapon -s should show that the /dev/md2 device is being used for swap.

  8. To use the RAID-1 array /dev/md2 as a swap partition on boot, edit the /etc/fstab file. The line should read /dev/md2 swap swap defaults 0 0.

  9. At this point you can reboot the system to test the swap RAID-1 array configuration. If you are in single-user mode you can use init 3 to bring the user processes back up. When you reboot you should see something like the following in the boot.log and dmesg:

    'md: raid1 personality registered as nr 3', 'md: md driver 0.90.0 MAX_MD_DEVS=256,
    MD_SB_DISKS=27', 'md: Autodetecting RAID arrays.', 'md: considering
    hdc4 ...', 'md: adding hdc4 ...', 'md: adding hda4 ...', 'md: created
    md2', 'raid1: raid set md2 active with 2 out of 2 mirrors', '......',
    'Adding Swap: 795128k swap-space (priority -1)'. 
    
    If RAID support is not compiled into the kernel, you may see an initial failure when starting swap as the system boots. As the OS transitions to multi-user mode, swap will become available.... Just something we noticed before we had it compiled in.

Listing 1. The /etc/raidtab with an entry for the swap partition raiddev /dev/md2
        raid-level      1
        nr-raid-disks   2
        persistent-superblock 1
        chunk-size      4
        device          /dev/hda4
        raid-disk       0
        device          /dev/hdc4
        raid-disk       1
______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

problem with raid configuration

sumet's picture

Dear Sir

I am configuring RAID level 1 on debian knoppix linux afetr all procedures it finally works . i have mounted /home partition in raid (/dev/md0). It start working successfully but when i restart my computer then it becomes inactive it shows when i run command mdadm --detail /dev/md0

i have done all procedures but cant get my RAID

Thank you
Sumeet Upadhyay
RHCE

RAID 1 Help

Arunabh B's picture

Nice tutorial....
I've IBM eSeries PIII server. Configuration is 1.2 Ghz cpu speed, 1 GB SDRAM, 36*2 GB SCSI internal Harddisks. OS is RedHat 7.2. Actually this is installed in our respective customer's premises. I configured Software RAID 1 (Disk mirroring) in the server. Partition details are as below -

/boot - 100 MB
/ - 12 GB
swap - 2 GB
/var - 4 GB
/opt - Rest available space ( Approx. 18 GB)

Partition order is same as mentioned above. I've created the partitions using Disk Druid during installation. The same partitions with same size and same order have been created in the other harddisks and configured RAID 1.
I've assinged the partition /boot as md0, / as md1, swap as md3, /var as md4 and /opt as md5 respectively. Everything was going fine before that power failure. Server was poweroff suddenly due to faulty UPS. When it powered up, during boot up system shows that one hdd gone bad. I've replaced the hdd (it was first one). Now I've to add the new hdd to the RAID array.
Please guide me how to add a new hdd in an existing RAID. Please explain me step by step so that I can understand what I'm doing during all the process. Also, Please explain me the both way (In case of first hdd gone bad and incase of second hdd gone bad).

Please help me out.
Waiting for your reply.