Apr 18 2012

raid1 on existing filesystem -> Example

Existing filesystem is on /dev/sda

/dev/root  /
/dev/sda5 /var
/dev/sda6 /usr
/dev/sda8  /home

Connect new disk (for example /dev/sdb)

Copy partition structure from sda to sdc:

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

or if disk has differ size

create the same size ( or bigger) partitions on sdb

end change type for fd (Linux raid autodetect)

change disk’s blkid

tune2fs -U random /dev/sdb

Next, create the single-disk RAID-1 array. Note the “missing” keyword is specified as one of our devices. We are going to fill this missing device later.

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

or

mdadm --create /dev/md0 --metadata=0.90 --level=1 --raid-devices=2 missing /dev/sdb1

and for other partitions

mdadm --create /dev/md1 --metadata=0.90 --level=1 --raid-devices=2 missing /dev/sdb5
mdadm --create /dev/md2 --metadata=0.90 --level=1 --raid-devices=2 missing /dev/sdb6
mdadm --create /dev/md3 --metadata=0.90 --level=1 --raid-devices=2 missing /dev/sdb7

cat /proc/mdstat shows just created raid

Use the file system of your preference here. I'll use ext4 for this guide.
mkfs -t ext4 -j -L RAID-ONE /dev/md0
mkfs -t ext4 -j -L RAID-ONE /dev/md1
mkfs -t ext4 -j -L RAID-ONE /dev/md2
mkfs -t ext4 -j -L RAID-ONE /dev/md3

Make a file system on the swap partition:

mkswap -L NEW-SWAP /dev/sdb2

The new RAID-1 array is ready to start accepting data! So now we need to mount the array, and copy everything from the old system to the new system

 mkdir /tmp/md0 /tmp/md1 /tmp/md2 /tmp/md3
 mount /dev/md0 /tmp/md0

 mount /dev/md1 /tmp/md1
 mount /dev/md2 /tmp/md2
 mount /dev/md3 /tmp/md3
 rsync -avxHAXS --delete --progress /home/ /tmp/md3
 rsync -avxHAXS --delete --progress /var/ /tmp/md2
 rsync -avxHAXS --delete --progress /usr/ /tmp/md1
 rsync -avxHAXS --delete --progress / /tmp/md0

edit /etc/fstab and change mounting points to appropriate /dev/md0 .. /dev/md3

and add line:

/dev/sdb2  swap swap defaults 0 0

reboot with opition  root=/dev/md0 (where my root filesystem was located).

telinit 1 ?

First, open /dev/sda with fdisk and change all the partittions you want to have added to the array to type fd – linux raid autodetection.

Then, for each degraded array, add the appropriate non-array device to it:

mdadm /dev/md0 -a /dev/sda1

(wait for finish recovery)

(umount/dev/sda5)
mdadm /dev/md1 -a /dev/sda5

(wait for finish recovery)

umount/dev/sda6
mdadm /dev/md2 -a /dev/sda6

(wait for finish recovery)

umount/dev/sda8
mdadm /dev/md3 -a /dev/sda8

(wait for finish recovery)

Ensure your /etc/lilo.conf has the correct setup:
boot=/dev/md0
raid-extra-boot=mbr-only
root=/dev/md0

and type:

lilo

LILO will write boot information to each of the individual raid devices boot sectors, so if either /boot or your root partition are on failed disks, you’ll still be able to boot.

Create /etc/mdadm/mdadm.conf.
in /etc/mdadm/mdadm.conf put line:
DEVICE /dev/sda* /dev/sdb*

and WHEN ALL PARTITIONS ARE REBUILDED run:

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

				

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.