Ubuntu - How to Create Software RAID 1 in 12.04 Ubuntu Linux - Tutorial

Printer-friendly versionPDF version
Ubuntu - How to Create Software RAID 1 in 12.04 Ubuntu Linux - Tutorial

There are several guides for creating software RAID's on Ubuntu on the internet. Most of them we've found to be not very comprehensive or difficult to understand and follow. This is why we've created this tutorial as easy to use as we could. Pictures on every step and detailed instructions. In fact, it may be a little to comprehensive, but that's ok. At least you'll be confident you created the RAID correctly. If you do have any questions or run into a problem, feel free to leave a comment below and we'll try to help.

Linux software RAIDs work differently than normal hardware RAID's. They are partition based, instead of disk based. This means that you must create matching partitions on all disks before creating the RAID. Hardware RAIDs have you add the disks to the RAID and then create the partition.

This tutorial was created while installing Ubuntu 12.04 64 bit Server Edition. It's intended to be the first in a series of Linux software RAID tutorials. Future tutorials will cover topics such as how to recover from a failed disk.

This server has two 16GB disks installed. We will be creating 2 partitions: a 2GB swap partition and a 14GB root partition. After we are done, the server will stay in operation if one of the two disks fails. Most of the pictures in this tutorial are self-explanatory. The option you need to choose will be highlighted. We will provide comments on the picture if there is any special considerations.

To begin, run the Ubuntu installer. When you get the 'Partition disks' menu, choose 'Manual':

Ubuntu Linux - How to Configure Software RAID Tutorial 1

In this case, the disks are new and there are no partition tables on it. Select each disk to create a partition table:

Ubuntu Linux - How to Configure Software RAID Tutorial 2

Ubuntu Linux - How to Configure Software RAID Tutorial 3

Select the free space on the first disk to create partitions on it:

Ubuntu Linux - How to Configure Software RAID Tutorial 4

Ubuntu Linux - How to Configure Software RAID Tutorial 5

The first partition will be 2GB at the beginning of the disk (this will be used for swap space):

Ubuntu Linux - How to Configure Software RAID Tutorial 6

Ubuntu Linux - How to Configure Software RAID Tutorial 7

Ubuntu Linux - How to Configure Software RAID Tutorial 8

You can leave partition settings the default. After the RAID is created, these partitions will be overwritten, so there is no need to configure them here:

Ubuntu Linux - How to Configure Software RAID Tutorial 9

Select the remaining free space on the first disk to create the 2nd partition. In this case, we will be using the remaining free space for this partition:

Ubuntu Linux - How to Configure Software RAID Tutorial 10

Ubuntu Linux - How to Configure Software RAID Tutorial 5

Ubuntu Linux - How to Configure Software RAID Tutorial 11

Ubuntu Linux - How to Configure Software RAID Tutorial 7

Again, do not worry about configuring the partition here. Leave it at the defaults:

Ubuntu Linux - How to Configure Software RAID Tutorial 12

After creating the 2 partitions on the first disk, repeat the process and create identical partitions on the second disk.

You should now see identical partition sizes on both disks. Choose 'Configure software RAID' to begin creating the software RAID:

Ubuntu Linux - How to Configure Software RAID Tutorial 13

Ubuntu Linux - How to Configure Software RAID Tutorial 14

Again, the Linux software RAID is partition based, so we will need to create 2 RAIDs, 1 for each of our set of 2 partitions. Choose 'Create MD device' to begin creating the first:

Ubuntu Linux - How to Configure Software RAID Tutorial 15

Ubuntu Linux - How to Configure Software RAID Tutorial 16

This step can be confusing for some people. Our first RAID will consist of 2 partitions (the 2GB partitions on each of the disks), so choose 2 active devices:

Ubuntu Linux - How to Configure Software RAID Tutorial 17

We aren't using any spare devices in this example:

Ubuntu Linux - How to Configure Software RAID Tutorial 18

Only select the 2GB partitions. There should be one on each disk:

Ubuntu Linux - How to Configure Software RAID Tutorial 19

Ubuntu Linux - How to Configure Software RAID Tutorial 20

You'll be taken back to the RAID configuration menu. Choose 'Create MD device' to begin creating the 2nd RAID:

Ubuntu Linux - How to Configure Software RAID Tutorial 15

Ubuntu Linux - How to Configure Software RAID Tutorial 16

Ubuntu Linux - How to Configure Software RAID Tutorial 17

Ubuntu Linux - How to Configure Software RAID Tutorial 18

Choose both of the 14GB partitions (again, there should be one on each disk):

Ubuntu Linux - How to Configure Software RAID Tutorial 21

Ubuntu Linux - How to Configure Software RAID Tutorial 20

Choose 'Finish' to complete the RAID configuration.

Now we partition the 2 RAIDs. You'll see 'RAID1 device #0' and 'RAID1 device #1'. These are the only to we need to partition.

To configure the swap RAID partition, select the 2GB RAID device listed under 'RAID1 device #0':

Ubuntu Linux - How to Configure Software RAID Tutorial 23

For 'Use as', select 'swap area' and then choose 'Done setting up the partition':

Ubuntu Linux - How to Configure Software RAID Tutorial 24

You will be taken back to the partitioning menu. Select the 2nd RAID device (in this case, it's the 14GB one) from the menu. You can configure the RAID device with whatever file system you need, but we are going with the default, Ext4. For the 'Mount point', make it the root by selecting "/". Now choose 'Done setting up the partition':

Ubuntu Linux - How to Configure Software RAID Tutorial 26

Your RAID devices should be partitioned similar to what is listed below. Choose 'Finish partitioning and write changes to disk':

Ubuntu Linux - How to Configure Software RAID Tutorial 27

Typically, the reason why RAID is implemented is so the operating system will continue to operate in the event of a single disk failure. Choose 'Yes' here so you will not see any interruptions when booting with a failed disk:

Ubuntu Linux - How to Configure Software RAID Tutorial 28

Ubuntu Linux - How to Configure Software RAID Tutorial 29

Almost done! The operating system will continue to install on the RAID you setup:

Ubuntu Linux - How to Configure Software RAID Tutorial 30

After the operating system installs, you will be prompted to install GRUB. Choose YES to install it to the Master Boot Record:

Ubuntu - How to Create Software RAID 1 in 12.04 Ubuntu Linux

As you can see, installing GRUB to the Master Boot Record will install it to both hard disks, (/dev/sda & /dev/sdb).

Ubuntu - How to Create Software RAID 1 in 12.04 Ubuntu Linux

That's it! After the install is complete, you should be able to boot into the OS. If you loose a hard disk, the OS will continue to run without interuption.

Here are some links that you may find useful if you have questions about this process (or leave a comment below and we can try to help):

https://help.ubuntu.com/community/Installation/SoftwareRAID

https://help.ubuntu.com/lts/serverguide/advanced-installation.html

 

Hi,
thanks for the detailed howto, what happens to grub later on? Do I install it to one drive, to both, to the MBR or partition?

Having the same issue

I've updated the article with screenshots and instructions for the GRUB installation. You install GRUB to the Master Boot Record. This will install it to both hard disks. It needs to be on both, otherwise, if you loose the disk with GRUB, it will not boot.

I've gone through this process 4 times with the same result - a non-booting system. I can't remember the exact error message, but it dumps me to a very limited grub prompt.
There are tutorials online for manually taking some steps to install the grub boot-loader to each drive, some that talk about creating a bios-grub partition, etc.
I wasn't satisfied and still wanted to find a way to get it working straight out of the box after a fresh install without needing to perform extra steps afterwards. I found an obscure mention by someone saying that they had the same issue and then they finally got it working by choosing to creating a separate /boot partition during the fresh install.
I tried that, and IT WORKED! Not sure what the bug/issue is with trying to set up just a SWAP and a "/" partition, but I've proven to myself that (at least under 12.04.3 server) it doesn't work. Once I created a SWAP, a "/boot" and a "/" RAID partition (on top of each of the correctly sized and matching sd* hard drive partitions) then it worked.
I did create the /boot partition first, then the SWAP, then the remaining disk space under "/"
Your mileage may vary, but it worked for me.

If you are still having this trouble, please boot to a live CD (or the OS if it's bootable) and list the partitions by running:

lsblk

Also, run the following command on both disks to make sure GRUB is installed on each:

dd if=/dev/sda bs=512 count=1 | xxd

You should see the word 'GRUB' in the output. Please post the output from these and I will try to help. I've used this method on multiple physical and virtual machines, so it definitely should work.

hey, very nice docu! the ubuntu installation is not the best :-)
Thank you very much for you work! its 23:30 in germany and now can i make ready the customer server - puhhh.

Regards
Thomas

Post new comment

Error | http://www.itswapshop.com

Error

The website encountered an unexpected error. Please try again later.