Problem

We have two 1TB disk drives. The goal is to setup LVM2 over md (software) RAID1 (mirror). These drives are not the boot drives, the system boots from other drive.

Analysis

We will first use mdadm  to join the two disks into RAID1 configuration. Than we will create a Volume Group and Volume Label over this RAID1 device (/dev/md0). We will leva some space for LVM snapshots.

Solution

First we need to create partitions on both disks, using fdisk program:

# fdisk /dev/sdb
# fdisk /dev/sdc

Partition type must be Linux RAID

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000408ac Device Boot      Start         End      Blocks   Id  System /dev/sdb1           1      121601   976760001   fd  Linux raid autodetect
# aptitude install mdadm
# mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sdb1 /dev/sdc1

It takes a while to initialize RAID1 on two 1TB disks (expect more than 2 hours):

# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
976758841 blocks super 1.2 [2/2] [UU]
[=>...................]  resync =  9.0% (88310784/976758841) finish=121.7min speed=121657K/sec

unused devices: <none>

Check the device:

# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Apr 17 22:58:18 2012
Raid Level : raid1
Array Size : 976758841 (931.51 GiB 1000.20 GB)
Used Dev Size : 976758841 (931.51 GiB 1000.20 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent

Update Time : Tue Apr 17 23:14:28 2012
State : clean, resyncing
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

Rebuild Status : 17% complete
Name : proxmox:0  (local to host proxmox)
UUID : ...
Events : 2

Number   Major   Minor   RaidDevice State
0       8       17        0      active sync   /dev/sdb1
1       8       33        1      active sync   /dev/sdc1
# pvcreate /dev/md0
Writing physical volume data to disk "/dev/md0"
Physical volume "/dev/md0" successfully created

# vgcreate vz /dev/md0
Volume group "vz" successfully created

Create Volume Group and Logical Volume on the RAID1:

# vgcreate vz /dev/md0
# vgdisplay vz
--- Volume group ---
VG Name               vz
System ID
Format                lvm2
Metadata Areas        1
Metadata Sequence No  4
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               1
Max PV                0
Cur PV                1
Act PV                1
VG Size               931.51 GiB
PE Size               4.00 MiB
Total PE              238466
Alloc PE / Size       212480 / 830.00 GiB
Free  PE / Size       25986 / 101.51 GiB
VG UUID               ...

Next we create a LV. We want to be able to do LVM snapshots, therefore we do not use the whole disk space. We leave about 100G for snapshoting.

# lvcreate -L 830G vz -n data
# lvdisplay
--- Logical volume ---
LV Name                /dev/vz/data
VG Name                vz
LV UUID                ...
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                830.00 GiB
Current LE             212480
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:3




Create partition on the created LV:

# mkfs.ext3 /dev/vz/data
# parted /dev/vz/data
GNU Parted 2.3
Using /dev/dm-3
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: Linux device-mapper (linear) (dm)
Disk /dev/dm-3: 891GB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number  Start  End    Size   File system  Flags
1      0.00B  891GB  891GB  ext3

Next we need to umount the old /var/lib/vz directory and mount the new one:

# umount /var/lib/vz; umount /vz
# mount /dev/mapper/vz-data /var/lib/vz
# mount /dev/mapper/pve-data /opt 

Create a snapshot

# vzdump 173 -dumpdir /backup/dump -mode snapshot

Resources

  1. http://tldp.org/HOWTO/Software-RAID-HOWTO-5.html
  2. http://www.howtoforge.com/linux_lvm
  3. http://www.gagme.com/greg/linux/raid-lvm.php
  4. https://wiki.archlinux.org/index.php/LVM
  5. http://wiki.openvz.org/Backup_of_a_running_container_with_vzdump
Creating RAID1 (Mirror) with mdadm for OpenVZ

Leave a Reply

Your email address will not be published. Required fields are marked *