Setting up RAID1 on an existing Debian Squeeze installation

Valic —  September 15, 2011 — 4 Comments

In this post i will show you what steps  I followed to adapt RAID1 on an existing installation of Debian Squeeze.

Step1. Make sure you have the following packages are installed:

apt-get update && apt-get upgrade
apt-get install mdadm rsync initramfs-tools grub-pc

Step2.  Partitioning the new drive:

First connect the new drive (/dev/sdb) and boot into your sistem.
Then use fdisk to display the partition informations for the existing drive (/dev/sda).

[email protected]:~# fdisk -l /dev/sda

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007384e

Device Boot Start End Blocks Id System
/dev/sda1 * 1 9330 74936320 83 Linux
/dev/sda2 9330 9730 3212289 5 Extended
/dev/sda5 9330 9730 3212288 82 Linux swap / Solaris

Now create partitions of the same size on the new drive.

NOTE:If the new drive is bigger leave the rest of the drive unpartitioned.

Step3. Create new degraded RAID1 arrays:

mdadm –create /dev/md0 –level=1 –raid-devices=2 missing /dev/sdb1
mdadm –create /dev/md1 –level=1 –raid-devices=2 missing /dev/sdb2

Then format like this:

mkswap /dev/md1
mkfs.ext4 /dev/md0

Make sure you specify these devices in /etc/mdadm/mdadm.conf like this:

DEVICE /dev/sda* /dev/sdb*

Append the RAID1 arrays to the end of that file:

mdadm –detail –scan >> /etc/mdadm/mdadm.conf
dpkg-reconfigure mdadm

Check the status of your RAID1 by running the following  command:

cat /proc/mdstat

Step4. Install GRUB2 on both drives:

Run the following command:

dpkg-reconfigure grub-pc

select both /dev/sda and /dev/sdb as installation targets.

Step5.  Sync all data on the existing drive onto the new one using rsync:

mkdir /tmp/mntroot
mount /dev/md0 /tmp/mntroot
rsync -auHxv –exclude=/proc/* –exclude=/sys/* –exclude=/tmp/* /* /tmp/mntro

Step6. Preparing to reboot using the RAID1 drive and test the system:

Before rebooting  open /tmp/mntroot/etc/fstab, and change /dev/sda1 and /dev/sda2 to /dev/md0 and /dev/md1.
Now reboot and from the GRUB2 menu, hit “e” to enter edit mode and make sure that you will be booting off of the new disk:

set root=’(md/0)’
linux /boot/vmlinuz-2.6.32-5-686 root=/dev/md0 ro quiet

Step7. Wipe out the original drive by adding it to the RAID1 array:

mdadm /dev/md0 -a /dev/sda1
mdadm /dev/md1 -a /dev/sda2

NOTE: Now you’ll have to wait until the two partitions are fully synchronized. You can check the status of synchronization using the following command:

watch -n1 cat /proc/mdstat

Step8. Test booting off of the original drive(/deb/dsa):

First update the boot loader menu:


Then shut down the system:

shutdown -h now

Now physically disconect the second drive(/deb/sdb) and power on the server.
If the server successfuly boot, shut down the server again and plug the second drive(/dev/sdb) back in before powering it up again.

Step9. Resync drives:

After reboot if everything works fine  you should see the following output after running the command:

cat /proc/mdstat

[email protected]:~# cat /proc/mdstat
md0 : active raid1 sda1[1]
280567040 blocks [2/1] [_U]

That indicates the RAID1 array is incomplete and that the second drive is not part of it. We need to add back the second drive(/dev/sdb)  and start the sync again:

mdadm /dev/md0 -a /dev/sdb1

OPTIONAL: You cand speed up the RAID1 synchronizing speed with these two commands:

echo 250000 > /proc/sys/dev/raid/speed_limit_max
echo 250000 > /proc/sys/dev/raid/speed_limit_min

After changing these values, the maximum transfer timing will be 250MB/s.

Enjoy, and feel free to comment.


Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

4 responses to Setting up RAID1 on an existing Debian Squeeze installation

  1. nice little howto. short and simple to follow.

    I’d like to add one thing for step 2: to make creating the same partitions on disk 2 a swift, you can use sfdisk:

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

  2. Small info for those using this procedure with the sparc architecture of Debian: the equivalent of grub on sparc is SILO and you will need to add your root MD device in the root= parameter of the /etc/silo.conf file.

  3. sorry i have a question if i want to install by deb-installer what steps i have to follow because of the end the installation debian wont install grub ,

    i want boot from the cd and setup a raid 1, but grubs doesnt install !!

    thanks :(

  4. This tutorial refers to systems already installed.
    If you want to create RAID 1 at the beginning of Debian installation, this tutorial is not good for you.

Leave a Reply