Results 1 to 2 of 2

Thread: [How-To] RAID1 LVM to RAID5 LVM (Tutorial)

  1. #1
    Join Date
    Sep 2008
    Location
    Netherlands
    Beans
    369
    Distro
    Ubuntu 12.04 Precise Pangolin

    [How-To / Tutorial] RAID1 LVM --> RAID5 LVM

    Information from http://ubuntuforums.org/showthread.php?t=990045 that uses information from http://scottwallace.posterous.com/tag/mdadm that uses information from http://www.n8gray.org/blog/2006/09/0...vms-and-mdadm/ is used for this tutorial.
    But...I did not like the steps saying 'to destroy all configurationfiles and building new' so I find out a solution.

    This worked twice for me with Ubuntu 10.04 setups.

    Before proceeding:
    - Don't be stupid, backup important data first.
    - Don't kill commands used in this tutorial.
    - Do not proceed with this tutorial if you can't prevent /boot from becoming RAID5 also. This may kill GRUB.
    - Try to understand what you are doing. Preventing and fixing mistakes is much easier than.
    - Run all commands as superuser/root.
    - Everything shown in code boxes are commands, no output information will be there.
    - Use the "cat /proc/mdstat" command any moment to see the RAID status.

    RAID1 with LVM --> RAID5 with LVM

    In this tutorial:
    RAID1 array: "/dev/mdx," containing: "/dev/sda" and "/dev/sdb."
    We will add "/dev/sdc" to create a RAID5 setup.

    Part 1 - Converting the RAID1 array to a RAID5 array
    Step 1
    Copy partition structures from the current disks to the new disk:
    Code:
    dd if=/dev/sda of=/dev/sdc count=1 bs=512
    sfdisk -d /dev/sda > sda.sf
    sfdisk --force /dev/sdc < sda.sf
    Reload the disk.
    Code:
    partprobe /dev/sdc
    Check if the partition structure is the same as on the disk in the RAID1 setup. For example, compare these two outputs:
    Code:
    fdisk -l /dev/sda
    fdisk -l /dev/sdc
    Step 2
    Switch to Live CD. Preferable the same version of the same distro you have installed. (Unless, you know how to stop an array being used or your array isn't in use*. Tn that case skip this step).
    Install mdadm.
    Code:
    apt-get install mdadm
    Find arrays.
    Code:
    partprobe
    Step 3
    Stop the RAID1 array.
    Code:
    mdadm --stop /dev/mdx
    Overwrite meta data and combine one old disk with the new disk, starting with the old one.
    Code:
    mdadm --create /dev/mdx --level=5 -n 2 /dev/sda /dev/sdc
    Recovery will start, wait until it is finished.

    Check the process.
    Code:
    cat /proc/mdstat
    Afterwards you should have a degraded RAID5 setup.
    '(UU_)' is indicating this.

    Add the third disk. (This is the second one of the old RAID1 setup.)
    Code:
    mdadm --add /dev/mdx /dev/sdb
    Tell the array to not use it as spare.
    Code:
    mdadm --grow /dev/mdx --raid-disks=3 --backup-file=/mnt/tmp/raid1-5.backup.file
    Reshaping will start. This takes more time than recovery. (The backup argument apparently is a option in case grow fails.)
    Wait until it is done.

    Part 2 - Editing the configuration data
    Step 4
    The LVM part. Now we've got a RAID5 setup but the OS inside the LVM does not know this. We will get inside LVM. (If you do not use the Live CD method, skip this step.)
    Install LVM2.**
    Code:
    apt-get install lvm2
    partprobe
    Find LVM stuff.
    Code:
    vgscan
    Activate the Volume Group(s).
    Code:
    vgchange -ay
    Now you also know where they are. Mount the one containing the operating system.
    Code:
    mount /dev/mapper/OS-LV /mnt/OS
    Step 5
    Get the new array information.
    Code:
    mdadm --detail --scan
    Only catch the lines that talk about the array we are working with.
    It looks something like this:
    ARRAY /dev/mdx level=raid5 num-devices=3 metadata=00.90 UUID=a5241471:51b928ef:92045851:c654ebbf
    Put this into the /etc/mdadm/mdadm.conf of the operating system. This would be /mnt/OS/etc/mdadm/mdadm.conf in this tutorial when using the Live CD method.
    Be sure to replace the correct old information talking about a raid1 array and save.

    This actually means nothing yet. The info needs to go into the boot image.

    Step 6
    (Non Live CD method users want to skip this step also.)
    Chroot to the LV.
    Code:
    chroot /mnt/OS
    Specific commands that have kind of relative paths in it will now work like as if you are booted into the OS-LV we mounted earlier.

    Step 7
    Update the boot image.
    Code:
    update-initramfs -u
    Reboot to OS.

    You should get into the OS like it was the case with the raid1 array.

    Check if everything is fine.
    Code:
    cat /proc/mdstat
    You should have a double amount of blocks now.

    Part 3 - Assigning the new bits
    Step 8
    Give the new space to the physical volume.
    Code:
    pvresize /dev/mdx
    This won't take much time.

    Check if it is there.
    Code:
    vgdisplay
    Look at the line saying 'Free PE / Size.'

    Give it to members of the group, for this tutorial let's say /home is in a group called 'home-dirs' and needs to get extended with 500GB.
    Code:
    lvextend -L+500G /dev/mapper/home-dirs
    See manuals for other kinds of extend commands.
    This could take some time.

    Check if they got it.
    Code:
    lvdisplay
    Look at the line saying 'LV Size.'

    Finally, resize the filesystem so the space becomes useable
    Code:
    resize2fs /dev/mapper/home-dirs
    This takes some time also but less than the previous operation.

    Check out your new space.
    Code:
    df -h
    Done!

    __________________________________________________ __________________________________________________



    *My array broke right at this moment (this must have been coincidence) so I continued in the OS itself. However, the first successful attempt took place using a Live CD.
    **I don't know for sure whether this 'partprobe' command is needed now. It won't harm anyways...
    Last edited by SaturnusDJ; October 20th, 2011 at 10:20 PM.

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Beans
    369
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: [How-To] RAID1 LVM to RAID5 LVM (Tutorial)

    Critical update, just before part 2:

    Code:
    mdadm --grow /dev/mdx --raid-disks=3 --backup-file=/mnt/raid1-5.backup.file
    The location of the backup-file should be a place somewhere save. Placing the file at the array itself is not a good idea (however it worked for me).

    Place the backup-file at an usb drive or hard disk. (Remember when using a live cd, saving in that environment just saves it to ram, if a power outage happens, it's gone.)
    Last edited by SaturnusDJ; March 10th, 2013 at 12:11 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •