feed-image  ISSN 1836-5930

linux

Linux eBooks FREE Download

A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide


Poll

Do you care about your privacy when using a FACEBOOK?
 


Partner Linux Sites: TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux
Linux Software Raid 1 Setup
Article Index
1. Introduction
1.1. System Info
2. The Plan
3. Software Installation
4. Configure Kernel Modules
4.1. Load modules at boot time
4.2. Load modules to the Kernel
5. Prepare sdb for RAID
6. Setting Up RAID 1 Arrays
6.1. Create RAID 1 Arrays
6.2. Create a filesystem on RAID 1 Arrays
6.3. Edit mdadm.conf file
7. Edit /etc/fstab
8. Configure GRUB boot manager
9. Copy data from sda => sdb
10. Setup boot manager
11. Reboot
12. Add first hard drive ( sda ) to the RAID 1 array
12.1. Change Partition Id with sfdisk
12.2. Add partitions with mdadm to RAID 1 array
12.3. Edit /etc/mdadm/mdadm.conf
13. Finish

1. Introduction

This article describes step by step setup of Linux software RAID 1 on Linux Platform. Although this software RAID 1 configuration has been accomplished on Debian ( Ubuntu ) it also can guide you if you are running some other Linux distributions such as RedHat, Fedora , Suse, PCLinux0S etc. For RAID-1 setup we need two or more disks. RAID1 mode creates a exact mirror of all data between two or more disks.

1.1. System Info

  • OS: Debian Etch ( basic installation on /dev/sda)
  • Kernel: Linux raid 2.6.18-5-686 #1 SMP Fri Jun 1 00:47:00 UTC 2007 i686 GNU/Linux
  • Hard Drives: /dev/sda -> 4GB , /dev/sdb -> 5GB

2. The Plan

We start with running linux system Debian Etch and the following partition scheme and hard drives ( sda , sdb ):

raid paritions scheme

raid 1 setup guide

 

3. Software Installation

There is only 1 package ( + prerequisites ) needed by software raid 1 on debian. This package is mdadm. Simply use apt-get tool to install mdadm package it into your system. You may be asked to answer couple question.

apt-get install mdadm 

4. Configure Kernel Modules

4.1. Load modules at boot time

No we need to make sure that raid kernel modules are loaded at the boot time. To accomplish this task we need to edit /etc/modules files and add couple lines. Open up your favorite text editor or just simply append lines with echo command.

echo raid1 >> /etc/modules echo md >> /etc/modules 

load raid kernel modules at boot time

4.2. Load modules to the Kernel

At this stage if we want to use raid modules we have two options. First one is to reboot our system and the other option is to use modprobe or insmode  to load modules to the Kernel. I find second option easier:

modprobe raid1 

load raid kernel modules

NOTE: if you do not have md module already loaded as shown on the figure above use modprobe to load it:

modprobe md 

There are two ways to confirm that our raid modules are loaded into kernel:

lsmod | grep raid1 cat /proc/mdstat 

You should have similar output as shown on the figure below:

load raid kernel modules output from a command line

5. Prepare sdb for RAID

At this stage we need to prepare our second hard drive sdb to act as RAID 1 arrays. First we need to copy a partition table from sda => sdb1. For this task we need to use sfdisk command. This step can also be done manually if you prefer to do it that way. Make sure that you do NOT have any data on disk sdb because this sfdisk command will erase them permanently !!! This command will copy a partition table from /dev/sda to /dev/sdb.

sfdisk -d /dev/sda | sfdisk /dev/sdb 

copy a partition table

Second Hard Drive sdb is almost ready. All we need to do is to change partition ID's for partitions: sdb1, sdb5, sdb6, sdb8 and sdb9 to fd (Linux raid autodetect). Also in this task sfdisk command comes very handy: NOTE: We are not interested in mirroring swap sdb7 partition which is swap partition.

for partition in 1 5 6 8 9; do sfdisk --change-id /dev/sdb $partition fd; done 

change partition ID

6. Setting Up RAID 1 Arrays

6.1. Create RAID 1 Arrays

It is time to create RAID 1 arrays. We first create RAID 1 array only from /dev/sdb. Once this is ready, we include the first hard drive /dev/sda to this array as well.

for partition in 1 5 6 8 9; do mdadm --create /dev/md$partition --level=1 \
--raid-disks=2 missing /dev/sdb$partition; done

Create RAID 1 Arrays

6.2. Create a filesystem on RAID 1 Arrays

Now we can create a file system on our new RAID 1 arrays:

for partition in 1 5 6 8 9; do mkfs.ext3 /dev/md$partition; done 

6.3. Edit mdadm.conf file

Please make a copy of your /etc/mdadm/mdadm.conf file as we will use in later stage of this tutorial. Let's edit mdadm.conf file. Make sure that you use an append ">>" to avoid accidental overwrite of mdadm.conf file.

cp /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf_orig
mdadm --detail --scan >> /etc/mdadm/mdadm.conf

Edit mdadm.conf file

7. Edit /etc/fstab

Just because we want to make our system to mount new RAID 1 arrays every time after reboot, we need to edit /etc/fstab file. OLD /etc/fstab

# /etc/fstab: static file system information.
#
#
proc /proc proc defaults 0 0
/dev/sda1 / ext3 defaults,errors=remount-ro 0 1
/dev/sda9 /home ext3 defaults 0 2
/dev/sda8 /tmp ext3 defaults 0 2
/dev/sda5 /usr ext3 defaults 0 2
/dev/sda6 /var ext3 defaults 0 2
/dev/sda7 none swap sw 0 0
/dev/hdc /media/cdrom0 udf,iso9660 user,noauto 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto 0 0

NEW /etc/fstab

# /etc/fstab: static file system information.
#
#
proc /proc proc defaults 0 0
/dev/md1 / ext3 defaults,errors=remount-ro 0 1
/dev/md9 /home ext3 defaults 0 2
/dev/md8 /tmp ext3 defaults 0 2
/dev/md5 /usr ext3 defaults 0 2
/dev/md6 /var ext3 defaults 0 2
/dev/sda7 none swap sw 0 0
/dev/hdc /media/cdrom0 udf,iso9660 user,noauto 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto 0 0

8. Configure GRUB boot manager

First, we make a copy of /boot/grub/menu.lst.

cp /boot/grub/menu.lst /boot/grub/menu.lst_orig 

let's engage a sed command to do this job:

sed 's/sda1/md1/' < /boot/grub/menu.lst_orig > /boot/grub/menu.lst 

edit grub to boot raid devices
Update GRUB:

update-grub 

GRUB - save changes

9. Copy data from sda => sdb

reboot in single mode:

init 1 

Copy data from each partition to new RAID 1 arrays. For this operation we use rsync command which will clone both partitions. If you do not have rsync installed on your system issue command:

apt-get install rsync 

"/" copy root partition:

mount /dev/md1 /media; rsync -aqxP / /media; umount /media 

copy /usr/ partition:

mount /dev/md5 /media; rsync -aqxP /usr/* /media; umount /media 

copy /var partition:

mount /dev/md6 /media; rsync -aqxP /var/* /media; umount /media 

copy /tmp/ partition:

NOTE: You can omit /tmp if you like !!

mount /dev/md8 /media; rsync -aqxP /tmp/* /media; umount /media 

copy /home partition:

mount /dev/md9 /media; rsync -aqxP /home/* /media; umount /media 

10. Setup boot manager

grub 

Once in GRUB type the following commands:

device (hd0) /dev/sdb
root (hd0,0)
setup (hd0)
quit

setup grub with boot manager

11. Reboot

We are ready to reboot the system. To confirm that we are running a system from RAID 1 arrays ( I guess we are on the good path since our system has started ) we can check for mounted devices with mount command:

mount 

reboot with RAID 1 arrays

12. Add first hard drive ( sda ) to the RAID 1 array

12.1. Change Partition Id with sfdisk

Same as we did with /dev/sdb we need to first change partition ID's:

for partition in 1 5 6 8 9; do sfdisk --change-id /dev/sda $partition fd; done 

Change Partition Id with sfdisk

12.2. Add partitions with mdadm to RAID 1 array

for partition in 1 5 6 8 9; do mdadm --add /dev/md$partition /dev/sda$partition; done 

Add partitions with mdadm to RAID 1 array

Since we have added new devices to a RAID 1 array the system started to resync each /dev/md* . You can see this process with watch command:

watch cat /proc/mdstat 

RAID 1 array resync

12.3. Edit /etc/mdadm/mdadm.conf

Now we need to edit /etc/mdadm/mdadm.conf file again and for that we can use our backup copy of this file as a template.

cp /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf_orig1
cp /etc/mdadm/mdadm.conf_orig /etc/mdadm/mdadm.conf
mdadm --detail --scan >> /etc/mdadm/mdadm.conf

Edit /etc/mdadm/mdadm.conf

13. Finish

  • Everything is now ready. You may want to reboot your system and confirm your successful setup of Linux software RAID 1.
  • To confirm that raid 1 is running use a cat /proc/mdstat command
cat /proc/mdstat 
  • Since we have used /dev/sda7 as a swap we have now unused partition /dev/sdb7.

Linux eBooks FREE Download

The GNU/Linux Advanced Administration
The GNU/Linux systems have reached an important level of maturity, allowing to integrate them in almost any kind of work environment, from a desktop PC to the sever facilities of a big company.

In this ebook "The GNU/Linux Operating System", the main contents are related with system administration. You will learn how to install and configure several computer services, and how to optimize and synchronize the resources using GNU/Linux.

The topics covered in this 500+ page eBook include Linux network, server and data administration, Linux kernel, security, clustering, configuration, tuning, optimization, migration and coexistence with non-Linux systems. A must read for any serious Linux system admin.

A Newbie's Getting Started Guide to Linux
Learn the basics of the Linux operating systems. Get to know what it is all about, and familiarize yourself with the practical side. Basically, if you're a complete Linux newbie and looking for a quick and easy guide to get you started this is it.

You've probably heard about Linux, the free, open-source operating system that's been pushing up against Microsoft. It's way cheaper, faster, safer, and has a far bigger active community than Windows, so why aren't you on it? Don't worry, Makeuseof.com understands. Like many things, venturing off into a completely unknown world can seem rather scary, and also be pretty difficult in the beginning. It's while adapting to the unknown, that one needs a guiding, and caring hand. This guide will tell you all you need to know in 20 illustrated pages, helping you to take your first steps. Let your curiosity take you hostage and start discovering Linux today, with this manual as your guide! Don't let Makeuseof.com keep you any longer, and download the Newbie's Initiation to Linux. With this free guide you will also receive daily updates on new cool websites and programs in your email for free courtesy of MakeUseOf.

Linux from Scratch
Linux from Scratch describes the process of creating your own Linux system from scratch from an already installed Linux distribution, using nothing but the source code of software that you need.

This 318 page eBook provides readers with the background and instruction to design and build custom Linux systems. This eBook highlights the Linux from Scratch project and the benefits of using this system. Users can dictate all aspects of their system, including directory layout, script setup, and security. The resulting system will be compiled completely from the source code, and the user will be able to specify where, why, and how programs are installed. This eBook allows readers to fully customize Linux systems to their own needs and allows users more control over their system.

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)
Getting Started with Ubuntu 10.04 (Lucid Lynx) is a comprehensive beginners guide for the Ubuntu operating system; it features comprehensive guides, How Tos and information on anything you need to know after first installing Ubuntu.

Designed to be as user-friendly and easy to follow as possible, it should provide the first point of reference to any Ubuntu newcomer with lots of information. The manual has step by step instructions and includes lots of screenshots to show you how to do tasks. It also includes a Troubleshooting section to help you solve common Ubuntu problems quickly. Download this 160+ page manual today.

Securing & Optimizing Linux: The Hacking Solution (v.3.0)
A comprehensive collection of Linux security products and explanations in the most simple and structured manner on how to safely and easily configure and run many popular Linux-based applications and services.

This book is intended for a technical audience and system administrators who manage Linux servers, but it also includes material for home users and others. It discusses how to install and setup a Linux server with all the necessary security and optimization for a high performance Linux specific machine. It can also be applied with some minor changes to other Linux variants without difficulty.

Comments (8)
  • MANFRED  - no Way - Lost nearly half of my holidays with this

    ... and still does not work ...
    Even UBUNTU 10.4 shows RAID in the drive manager tool ... but It does not work ...need someone for help, not more TEXT, real help....
    preferable around Munich in Germany ...

  • shygfgg  - bingo

    genius !!!

  • Jim Van Zandt  - cp instead of rsync

    Instead of rsync, I recommend cp to copy data to the new raid system, e.g.
    cp -ax /boot /mnt/newroot

    I maintain linked backups. Each backup is a complete copy of my filesystem, but for files that have not changed between backups, the directories have hard links to the same inodes. I have six backups, with ages (at the moment) 0, 1, 2, 11, 33, and 228 days. Each backup beyond the first costs only about five percent additional space. If I were to copy them using rsync, I would wind up with six separate copies of each file. I could use the -H flag to eliminate the duplication, but the man page cautions that costs a lot of time. "cp -a" maintains the links and still
    seemed pretty fast.

  • David Bo Jensen  - It will not boot on sda

    If you remove sdb and boot only with sda it will not boot

  • David Bo Jensen  - It will only boot on sdb

    If you remove sdb the system will not boot on sda

  • Pawan Jaitly  - not mirroring swap partition in raid 1 considered

    Nice write up with pretty pictures, by the way.

    But I had to say something about this bit:

    "NOTE: We are not interested in mirroring swap sdb7 partition which is swap partition"

    This needs to be fixed. You're in good company though, it's a misconception I have seen around before ;-)

    See discussion on http://www.debian-administration.org/articles/238 about this for why you should mirror swap on raid 1.

    regards
    Pawan Jaitly

  • Anonymous  - initramfs

    You need to run the command update-initramfs -u to update the mdadm.conf in the boot image. Otherwise, it'll drop you into initramfs saying that /dev/disk/by-uuid/bunch-of-hex-numbers wasn't found.

    To get past this, can just reassemble your raid with:
    1. mdadm --assemble /dev/mdX /dev/sda1 /dev/sdb1 ...
    2. exit

    And it'll boot, but until you update boot image, you'll have to do this everytime.

  • Ajeet S Raina  - Good Tutorial

    Its Really great tutorial.
    Hats Off to the writer.

Write comment
NOTE: To unsubscribe enter your email, select "do not dotify" with title: UNSUBSCRIBE and Send.
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
Security
Please input the anti-spam code that you can read in the image.