« Hints and Tips for testing and trying things out.HOWTO Expand a RAID 5 by replacing the disk with lager ones. »

HOWTO: Create a new RAID 1 (mirror)

27/12/08

HOWTO: Create a new RAID 1 (mirror)

You have two devices of approximately same size and want to mirror the data on one of them to the other to make your system more secure.

sudo fdisk /dev/sdb

The number of cylinders for this disk is set to 30401. 


There is nothing wrong with that, but this is larger than 1024, 
and could in certain setups cause problems with: 
1) software that runs at boot time (e.g., old versions of LILO) 
2) booting and partitioning software from other OSs 
   (e.g., DOS FDISK, OS/2 FDISK) 
 
Command (m for help):

Use the p command to see the current partitions on the drive or just to make sure you have the right one :)

Command (m for help): p 


Disk /dev/sdb: 250.0 GB, 250059350016 bytes 
255 heads, 63 sectors/track, 30401 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 
Disk identifier: 0x00045339 
 
   Device Boot      Start         End      Blocks   Id  System 
 

Add a new partition making sure the same size will fit on both disks if they are not exactly the same.

Command (m for help): n 


Command action 
   e   extended 
   p   primary partition (1-4) 

Partition number (1-4): 1 
First cylinder (1-30401, default 1):  
Using default value 1 
Last cylinder or +size or +sizeM or +sizeK (1-30401, default 30401):  
Using default value 30401 

Lastly set the dick ID type to Linux RAID. This is what it would be set to if you have created the RAID 1 array while installing Ubuntu. I'm not going to argue with the guys that produce this great Linux distribution. :)

Command (m for help): t 


Selected partition 1 
Hex code (type L to list codes): fd 
Changed system type of partition 1 to fd (Linux RAID autodetect) 

Just one more check that all is as expected before writing the new values to the disk.

Command (m for help): p 


 
Disk /dev/sdb: 250.0 GB, 250059350016 bytes 
255 heads, 63 sectors/track, 30401 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 
Disk identifier: 0x00045339 
 
   Device Boot      Start         End      Blocks   Id  System 
/dev/sdb1               1       30401   244196001   fd  Linux RAID autodetect 
 

This looks good to me so write away!

Command (m for help): w 


The partition table has been altered! 
 
Calling ioctl() to re-read partition table. 
Syncing disks. 

Do the same again for he second disk and we will be ready to create the new mirrored disk array.

sudo mdadm --create --verbose /dev/md1 --level=mirror --raid-devices=2 /dev/sdb1 /dev/sdc1

mdadm: size set to 244195904K 


mdadm: array /dev/md1 started. 

Note: I used md1 as the device name as I already used md0 for the raid 5 array. 


 

You can now watch the array sync itself over the two disks.

watch -n 7 cat /proc/mdstat  


Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]  
md1 : active raid1 sdc1[1] sdb1[0] 
      244195904 blocks [2/2] [UU] 
      [>....................]  resync =  1.7% (4328640/244195904) finish=48.5min speed=82380K/sec 
 
unused devices: <none> 
 

You will of course need to format it, I use reiserfs so this is done with the following command. I like to label my disks as I think its make life a little simpler.

sudo mkreiserfs /dev/md1 --label=mirror_root

Guessing about desired format.. Kernel 2.6.24-22-generic is running. 


Format 3.6 with standard journal 
Count of blocks on the device: 61048976 
Number of blocks consumed by mkreiserfs formatting process: 10075 
Blocksize: 4096 
Hash function used to sort names: "r5" 
Journal Size 8193 blocks (first block 18) 
Journal Max transaction length 1024 
inode generation number: 0 
UUID: 1ab2c3d4-51b6-4471-b356-906cb9281293 
LABEL: mirror_root 
ATTENTION: YOU SHOULD REBOOT AFTER FDISK! 
        ALL DATA WILL BE LOST ON '/dev/md1'! 
Continue (y/n):y 
Initializing journal - 0%....20%....40%....60%....80%....100% 
Syncing..ok 
 
Tell your friends to use a kernel based on 2.4.18 or later, and especially not a 
kernel based on 2.4.9, when you use reiserFS. Have fun. 
 
ReiserFS is successfully created on /dev/md1. 

You can now mount the drive from the command line using

sudo mkdir /mnt/mirror 


sudo mount /dev/md1 /mnt/mirror 

or from within the fstab file with any ONE of the following. The UUID can be found by looking at the message given out from the command above when you put reiserfs on the array.

LABEL=mirror_root   /mnt/mirror    reiserfs   relatime   0       2 


/dev/md1            /mnt/mirror    reiserfs   relatime   0       2 
UUID=1ab2c3d4-51b6-4471-b356-906cb9281293 /mnt/mirror    reiserfs   relatime   0       2

The same method can be used to create RAID5 or RAID0 arrays. take a look at he RAID Setup pages here.

Finally you will need to update mdadm.conf with the new drive adding it to the existing list. Too find out all the UUIDs on the system you can use

sudo blkid

/dev/sda1: UUID="a0b4a885-6d24-48c8-b7fc-0000395781f9" TYPE="reiserfs"  


/dev/sdb1: UUID=1ab2c3d4-51b6-4471-b356-906cb9281293"  TYPE="linux_raid_member"  
/dev/sdc1: UUID="89c286e1-79cc-bbfa-d62d-508b2fbf3d7b" TYPE="linux_raid_member"

Edit /etc/mdadm/mdadm.conf and add the new drive to the ARRAY that of disk you have added the new drive to. Do not just copy my UUIDs they will not be the same as yours &amp;#58;&amp;#68;D

sudo nano /etc/mdadm/mdadm.conf
ARRAY /dev/md0 uuid=1ab2c3d4-51b6-4471-b356-906cb9281293" uuid=" ...

Now you need to rebuild the RAM disk image initrd.

sudo update-initramfs -c -k `uname -r`

Take a look at the man pages for mdadm.conf and update-initramfs.


No feedback yet

Here are a collection of Mini-HOWTOs some of which are too short even for that grand title. I keep them around as it is easier to remember where to look these up that to remember the content of the mini-HOWTO

Search

Contents

blogging tool