How To Set Up Software RAID1 On A Running System (Incl. GRUB2 Configuration) (Debian Squeeze) - Page 3

7 Preparing /dev/sda

If all goes well, you should now find /dev/md0 and /dev/md2 in the output of

df -h

root@server1:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/md2              4.0G  714M  3.1G  19% /
tmpfs                 249M     0  249M   0% /lib/init/rw
udev                  244M  132K  244M   1% /dev
tmpfs                 249M     0  249M   0% /dev/shm
/dev/md0              472M   25M  423M   6% /boot

The output of

cat /proc/mdstat

should be as follows:

root@server1:~# cat /proc/mdstat
Personalities : [raid1]
md2 : active raid1 sdb3[1]
      4241396 blocks super 1.2 [2/1] [_U]

md1 : active (auto-read-only) raid1 sdb2[1]
      499700 blocks super 1.2 [2/1] [_U]

md0 : active raid1 sdb1[1]
      498676 blocks super 1.2 [2/1] [_U]

unused devices: <none>

Now we must change the partition types of our three partitions on /dev/sda to Linux raid autodetect as well:

fdisk /dev/sda

root@server1:~# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help):
 <-- t
Partition number (1-4): <-- 1
Hex code (type L to list codes): <-- fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help):
 <-- t
Partition number (1-4): <-- 2
Hex code (type L to list codes): <-- fd
Changed system type of partition 2 to fd (Linux raid autodetect)

Command (m for help):
 <-- t
Partition number (1-4): <-- 3
Hex code (type L to list codes): <-- fd
Changed system type of partition 3 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.

Now we can add /dev/sda1, /dev/sda2, and /dev/sda3 to the respective RAID arrays:

mdadm --add /dev/md0 /dev/sda1
mdadm --add /dev/md1 /dev/sda2
mdadm --add /dev/md2 /dev/sda3

Now take a look at

cat /proc/mdstat

... and you should see that the RAID arrays are being synchronized:

root@server1:~# cat /proc/mdstat
Personalities : [raid1]
md2 : active raid1 sda3[2] sdb3[1]
      4241396 blocks super 1.2 [2/1] [_U]
      [==========>..........]  recovery = 54.6% (2319808/4241396) finish=0.7min speed=45058K/sec

md1 : active raid1 sda2[2] sdb2[1]
      499700 blocks super 1.2 [2/2] [UU]

md0 : active raid1 sda1[2] sdb1[1]
      498676 blocks super 1.2 [2/2] [UU]

unused devices: <none>

(You can run

watch cat /proc/mdstat

to get an ongoing output of the process. To leave watch, press CTRL+C.)

Wait until the synchronization has finished (the output should then look like this:

root@server1:~# cat /proc/mdstat
Personalities : [raid1]
md2 : active raid1 sda3[2] sdb3[1]
      4241396 blocks super 1.2 [2/2] [UU]

md1 : active raid1 sda2[2] sdb2[1]
      499700 blocks super 1.2 [2/2] [UU]

md0 : active raid1 sda1[2] sdb1[1]
      498676 blocks super 1.2 [2/2] [UU]

unused devices: <none>


Then adjust /etc/mdadm/mdadm.conf to the new situation:

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

/etc/mdadm/mdadm.conf should now look something like this:

cat /etc/mdadm/mdadm.conf

# mdadm.conf
# Please refer to mdadm.conf(5) for information about this file.

# by default, scan all partitions (/proc/partitions) for MD superblocks.
# alternatively, specify devices to scan, using wildcards if desired.
DEVICE partitions

# auto-create devices with Debian standard permissions
CREATE owner=root group=disk mode=0660 auto=yes

# automatically tag new arrays as belonging to the local system
HOMEHOST <system>

# instruct the monitoring daemon where to send mail alerts

# definitions of existing MD arrays

# This file was auto-generated on Tue, 24 May 2011 14:09:09 +0200
# by mkconf 3.1.4-1+8efb9d1
ARRAY /dev/md/0 metadata=1.2 UUID=b40c3165:17089af7:5d5ee79b:8783491b
ARRAY /dev/md/1 metadata=1.2 UUID=62e4a606:878092a0:212209c5:c91b8fef
ARRAY /dev/md/2 metadata=1.2 UUID=94e51099:d8475c57:4ff1c60f:9488a09a


8 Preparing GRUB2 (Part 2)

Now we delete /etc/grub.d/09_swraid1_setup...

rm -f /etc/grub.d/09_swraid1_setup

... and update our GRUB2 bootloader configuration:

update-initramfs -u

Now if you take a look at /boot/grub/grub.cfg, you should find that the menuentry stanzas in the ### BEGIN /etc/grub.d/10_linux ### section look pretty much the same as what we had in /etc/grub.d/09_swraid1_setup (they should now also be set to boot from /dev/md0 instead of (hd0) or (hd1)), that's why we don't need /etc/grub.d/09_swraid1_setup anymore.

Afterwards we must make sure that the GRUB2 bootloader is installed on both hard drives, /dev/sda and /dev/sdb:

grub-install /dev/sda
grub-install /dev/sdb

Reboot the system:


It should boot without problems.

That's it - you've successfully set up software RAID1 on your running Debian Squeeze system!

Share this page:

2 Comment(s)

Add comment


From: kokolorum at: 2012-05-06 11:38:49

Please add this:

apt-get install grub2

dd if=/dev/sda of=/boot/backup.dd.sda

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

sfdisk -d /dev/sda > /boot/backup.sfdisk.sda

From: simon at: 2012-06-17 23:39:12

Many thanks!

I was stuck without being enable to install RAID1 on a running squeeze install.