Life in code, apps and OS's

Installing Ubuntu with a Software RAID1 configuration

Posted on: May 19, 2008

In this post I will be showing you how you can install a fresh copy of Ubuntu on a server using two Hard disk drives either ATA or SATA drives, I would recommend using proper server hardware as if one of the HDD controllers fail then you still wont be able to reboot your server immediately. For thoses who are not familiar RAID1 mirrors data identically over two (or more) hard disks.

1. Firstly enter your Ubuntu Server Compact disk into the CD-ROM tray and boot the server with it, When you get to the Partioning options menu you will need to select ‘Manual’ like shown below:

 

2. Next I created 3 partitions on both disks: 8 GB for /, 500 MB for swap and the remaining space for /home. Please note that at this stage the partition types must be “physical volume for RAID” (0xFD in fdisk) instead of “Ext3 journaling file system”. Also note how the first partitions of both disks are marked bootable (the B flag in picture 4). Without setting those partitions bootable you might not be able to boot your computer without a CD!

 

3. Setting partition type and bootable flag, Next I went up and selected “Configure software RAID” (picture 4).

 

4.Two disks with partitions for RAID1 volumes, Next I saved the modifications made to the partition tables (picture 5).

 

5.  Saving the changes, Next I created three (3) MD devices (each configured as RAID1 with 2 active and 0 hotspace disks — pictures 6-9).

 

6. Creating new MD devices.

 

7. RAID1 = mirror.

 

8. Two active devices.

 

9. No spare devices, Next I selected the physical disk partitions to be included in the RAID1 set (picture 10). It’s important to select two partitions with identical sizes so in my case md0=sda1+sbd1, md1=sda2+sdb2 and md2=sda3+sdb3.

 

10. Selecting MD components, Next I configured file systems and mount points for each RAID device. In my case “RAID device #0” is ext3 mounted on /, “RAID device #1” is swap and “RAID device #2” is ext3 mounted on /home (pictures 11-15).

 

11. File systems created on the RAID devices.

 

12. / filesystem created on the RAID device #0

 

13. swap created on the RAID device #1

 

14. /home filesystem created on the RAID device #2

 

15. All file systems configured, Finally I went down and selected “Done setting up the partitions” and selected “Yes” to write the changes made to the partition table (picture 16). From this point on the Ubuntu installation is a normal installation.

 

16. Saving the changes.

After installation and the first reboot I installed grub also on the second disk’s (/dev/sdb) master boot record (MBR). Without this the PC will not start if the first disk (/dev/sda) fails and is removed from the PC.

martti@ubuntu:~$ sudo grub-install /dev/sda

martti@ubuntu:~$ sudo grub
grub> device (hd0) /dev/sdb
grub> root (hd0,0)
grub> setup (hd0)
grub> quit

WARNING: There is a serious bug in Ubuntu 7.10 (see this and this for details) which makes the boot fail if one of the physical disks in the RAID1 set is missing.

Testing it out..

After installation I verified that all file systems (/, swap and /home) are really on the RAID1 disks.

martti@ubuntu:~$ grep /dev/md /etc/fstab
/dev/md0        /               ext3    defaults,errors=remount-ro 0       1
/dev/md2        /home           ext3    defaults        0       2
/dev/md1        none            swap    sw              0       0

martti@ubuntu:~$ df -h / /home
Filesystem            Size  Used Avail Use% Mounted on
/dev/md0              7.4G  586M  6.4G   9% /
/dev/md2               12G  159M   12G   2% /home

The status of all RAID devices can be checked from the /proc/mdstat file. Each mdN device contains two sdXN disks and each mdN device should have “2/2” and “UU”. More details can be seen with the mdadm utility.

martti@ubuntu:~$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md2 : active raid1 sda3[0] sdb3[1]
      12659136 blocks [2/2] [UU]

md1 : active raid1 sda2[0] sdb2[1]
      489856 blocks [2/2] [UU]

md0 : active raid1 sda1[0] sdb1[1]
      7815488 blocks [2/2] [UU]

unused devices: <none>

martti@ubuntu:~$ sudo mdadm --query --detail /dev/md0
/dev/md0:
        Version : 00.90.03
  Creation Time : Wed Oct 17 16:45:59 2007
     Raid Level : raid1
     Array Size : 7815488 (7.45 GiB 8.00 GB)
  Used Dev Size : 7815488 (7.45 GiB 8.00 GB)
   Raid Devices : 2
  Total Devices : 2
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Wed Oct 17 15:16:18 2007
          State : active
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           UUID : 1760de71:d6ca4125:8324c8dc:300ec7e1
         Events : 0.11

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1

 Recovering from a failed disk..

Next I simulated a disk failure by disconnecting /dev/sdb. The system still boots but the status shows /dev/sdb1, /dev/sdb2 and /dev/sdb3 have disappeared from the system and how the /dev/mdN is marked as “degraded” in the status field.

martti@ubuntu:~$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md2 : active raid1 sda3[0]
      12659136 blocks [2/2] [U_]

md1 : active raid1 sda2[0]
      489856 blocks [2/2] [U_]

md0 : active raid1 sda1[0]
      7815488 blocks [2/2] [U_]

unused devices: <none>

martti@ubuntu:~$ sudo mdadm --query --detail /dev/md0
/dev/md0:
        Version : 00.90.03
  Creation Time : Wed Oct 17 16:45:59 2007
     Raid Level : raid1
     Array Size : 7815488 (7.45 GiB 8.00 GB)
  Used Dev Size : 7815488 (7.45 GiB 8.00 GB)
   Raid Devices : 2
  Total Devices : 1
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Wed Oct 17 15:16:18 2007
          State : active, degraded
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0

           UUID : 1760de71:d6ca4125:8324c8dc:300ec7e1
         Events : 0.11

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       0        0        -      removed

Next I reconnected the disk and instructed the system to rebuild itself. After rebuild everything was ok again.

martti@ubuntu:~$ sudo mdadm --add /dev/md0 /dev/sdb1
mdadm: hot added /dev/sdb1

martti@ubuntu:~$ sudo mdadm --add /dev/md1 /dev/sdb2
mdadm: hot added /dev/sdb2

martti@ubuntu:~$ sudo mdadm --add /dev/md2 /dev/sdb3
mdadm: hot added /dev/sdb3

martti@ubuntu:~$ cat /proc/mdstat
Personalities : [raid1]
md2 : active raid1 sdb3[2] sda3[0]
      12659136 blocks [2/1] [U_]
      	resync=DELAYED

md1 : active raid1 sda2[0] sdb2[1]
      489856 blocks [2/2] [UU]

md0 : active raid1 sdb1[2] sda1[0]
      7815488 blocks [2/1] [U_]
      [>....................]  recovery =  2.8% (215168/7815488) finish=16.2min speed=9780K/sec

unused devices: <none>

That’s it.

4 Responses to "Installing Ubuntu with a Software RAID1 configuration"

Thanks a lot for a great tutorial! It is the best I have found about how to install the raid.

I have succeeded in making it work in my computer, except for the times when I halt it. I don’t know why, when I reboot it works perfectly good, but when halting the machine my disks are shown by the bios as “offline member” and no OS is found. The only way to start it then is to load up the live cd and making a reboot from there, which corrects the problem until the next halt.

Any ideas on how to fix this?

I think I found the solution, or at least my intuition tells me so.

The problem seems to be in the bios. The Raid array is given a smaller size than in Ubuntu, so I tried changing the setting in the bios of my motherboard (Gigabyte EP35C-S3R)from RAID to AHCI and everything seems to be working fine:
Running
sudo mdadm --detail /dev/md*

Gives me:
/dev/md0:
Version : 00.90.03
Creation Time : Fri Jan 30 19:07:05 2009
Raid Level : raid1
Array Size : 19631296 (18.72 GiB 20.10 GB)
Used Dev Size : 19631296 (18.72 GiB 20.10 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Thu Feb 12 17:28:31 2009
State : active
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

UUID : c031503c:a0481358:c9c7cb55:8db4e538
Events : 0.9

Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 8 17 1 active sync /dev/sdb1
/dev/md1:
Version : 00.90.03
Creation Time : Fri Jan 30 19:07:46 2009
Raid Level : raid1
Array Size : 390628416 (372.53 GiB 400.00 GB)
Used Dev Size : 390628416 (372.53 GiB 400.00 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 1
Persistence : Superblock is persistent

Update Time : Thu Feb 12 17:28:28 2009
State : clean, recovering
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

Rebuild Status : 37% complete

UUID : 9a5262b1:3ee23754:a09c7648:1aacb58d
Events : 0.20

Number Major Minor RaidDevice State
0 8 2 0 active sync /dev/sda2
1 8 18 1 active sync /dev/sdb2
/dev/md2:
Version : 00.90.03
Creation Time : Fri Jan 30 19:08:06 2009
Raid Level : raid1
Array Size : 69039232 (65.84 GiB 70.70 GB)
Used Dev Size : 69039232 (65.84 GiB 70.70 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 2
Persistence : Superblock is persistent

Update Time : Thu Feb 12 16:54:26 2009
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

UUID : 4417b9b7:8171282f:4c4da224:3c9d7028
Events : 0.8

Number Major Minor RaidDevice State
0 8 3 0 active sync /dev/sda3
1 8 19 1 active sync /dev/sdb3
/dev/md3:
Version : 00.90.03
Creation Time : Fri Jan 30 19:08:19 2009
Raid Level : raid1
Array Size : 9084672 (8.66 GiB 9.30 GB)
Used Dev Size : 9084672 (8.66 GiB 9.30 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 3
Persistence : Superblock is persistent

Update Time : Thu Feb 12 16:55:49 2009
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

UUID : 695daa0c:50b26d73:23bcfd41:67ef2725
Events : 0.10

Number Major Minor RaidDevice State
0 8 4 0 active sync /dev/sda4
1 8 20 1 active sync /dev/sdb4

Everything looks OK to me, even the recovery message (the light went out in my building today.)

Or maybe I am just being over optimistic, who knows…

Thanks for the in-depth tutorial on RAID. Your site has quite a bit of useful and interesting material.

Mark

thanks soo much for the tutoriel, it was very useful for me to install and configure a RAID1 software.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


  • How To Dyndns Ubuntu | Order Goods: […] DynDNS Client Setup on Ubuntu | Life in code, apps and OS’s – May 18, 2008  · 7 Responses to "DynDNS Client Setu
  • lizrandolph10886: Wonderful article! We are linking to this particularly great post on our website.nKeep up the great writing. Click
  • waseem Ahmad: Dear. i have a separate application server and a separate mysql database server. when i want to access the application server to login from the local
%d bloggers like this: