Adding 2 new drives, build a RAID1 with it, and create a new VG space in it

In this tutorial, just right after adding physically 2 new HDD to a server (/dev/sdc and /dev/sdd), we will create a new /dev/md2 RAID1 software device and a new volume group (VG) running over it.

1 Partition the hard drives

I like using cfdisk, and I used it to create sdc1 and sdd1. For example:

   cfdisk /dev/sdc

Then go in "NEW", add a partition of the size of the HDD minus a reasonable 5 GB (because if it fails, and the replacement HDD is just few megs smaller, you'll be fucked...). Like, if you have a 1.5 TB hdd, then make a partition of 1495 GB, and leave 5 GB of free space.

Then go in "TYPE" and select "linux raid autodetect" (type FD).

Redo the work with cfdisk /dev/sdd

2 Create a new RAID1 devices

With mdadm, something like this will do:

   mdadm --create /dev/md2 --level=1 --raid-devices=2 /dev/sdc1 /dev/sdd1

As this doesn't start the resync, I remove then re-add one of the partitions:

   mdadm /dev/md2 -f /dev/sdc1
   mdadm /dev/md2 --remove /dev/sdc1
   mdadm /dev/md2 --add /dev/sdc1

then I add the UUID of /dev/md2. To see it, I do:

   mdadm --detail /dev/md2

then I add the below line in /etc/mdadm/mdadm.conf:

   ARRAY /dev/md2 level=raid1 num-devices=2 UUID=<UUID that you just saw with mdadm --detail /dev/md2>

so that at next reboot it the RAID1 device is started automatically. You can check the state of the RAID1 device that is now rebuilding using:

   cat /proc/mdstats

3 Creating a new volume group (VG) over the new RAID1

Everything here is taken from what's written here: http://tldp.org/HOWTO/LVM-HOWTO/commontask.html(approve sites) just browse it, it's a very good documentation.

We start by initializing the PV on /dev/md2:

   pvcreate /dev/md2

In return the system will tell:

   Physical volume "/dev/md2" successfully created

Then we create the volume group:

   vgcreate vgcreate HOSTNAMEvg1 /dev/md2

It's my administrator habits to prefix each vg name with the hostname, to make sure all of my servers have unique vgnames (which is more easy for maintenance). The system will in return tell:

   Volume group "HOSTNAMEvg1" successfully created

which you can check with:

   vgdisplay

You can now create new partitions on it:

   lvcreate -L20G -ndata HOSTNAMEvg1

will create a 20G partition on /dev/mapper/HOSTNAMEvg1-data. There's normally nothing to do in the lvm.conf, and at next reboot the volume group will be activated.

Editing this page means accepting its license.

Page last modified on March 23, 2010, at 04:11 AM EST