I thought it'd be a good idea to do a dry run using files instead of disks just to have a clear idea of what needs to be done.
There's a excellent walkthrough over at http://www.gagme.com/greg/linux/raid-lvm.php and that's what I based my configuration on, so check it out for a little more background info.
Create three zero-filled 1GB files:
for d in a b c; doNext, set up the loopback devices:
dd if=/dev/zero of=/var/tmp/hd${d}.img bs=1024 count=1048576
done
losetup /dev/loop0 /var/tmp/hda.imgNow we're going to use fdisk to create a 'Linux raid autodetect' partition on each 'disk':
losetup /dev/loop1 /var/tmp/hdb.img
losetup /dev/loop2 /var/tmp/hdc.img
fdisk /dev/loop0The output should look like this, my commands in bold. Don't forget to do a partprobe once you're done.
fdisk /dev/loop1
fdisk /dev/loop2
[root@canard ~]# fdisk /dev/loop0
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-127, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-127, default 127):
Using default value 127
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 22: Invalid argument.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
partprobeNow we're going to set up our RAID5 array on the md0 device with the 3 disks we just prepared:
mdadm --create /dev/md0 --level=5 --raid-devices=3 \And that's pretty much it for the RAID part. You can view that status of your md device using mdadm or viewing the proc entry, examples follow.
/dev/loop0 /dev/loop1 /dev/loop2
[root@canard ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 loop2[3] loop1[1] loop0[0]
2047872 blocks level 5, 64k chunk, algorithm 2 [3/2] [UU_]
[=========>...........] recovery = 46.5% (476544/1023936) finish=4.3min speed=2112K/sec
[root@canard ~]# mdadm --detail /dev/md0As you can see, md is in the process of building the array. Now it's time to configure the LVM side of things.
/dev/md0:
Version : 00.90.03
Creation Time : Wed Jul 29 11:46:47 2009
Raid Level : raid5
Array Size : 2047872 (2000.21 MiB 2097.02 MB)
Used Dev Size : 1023936 (1000.11 MiB 1048.51 MB)
Raid Devices : 3
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Wed Jul 29 11:46:47 2009
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 64K
Rebuild Status : 53% complete
UUID : 1744c4be:0566a9ee:8a056ff6:bd165eb4
Events : 0.1
Number Major Minor RaidDevice State
0 7 0 0 active sync /dev/loop0
1 7 1 1 active sync /dev/loop1
3 7 2 2 spare rebuilding /dev/loop2
First create a PV (physical volume), then a VG (volume group) consisting of your PV, then a LV (logical volume) on top of your VG.
It's probably a good idea to check out the LVM docs prior to commencing this step to gain a good understanding of what it is and does.
You could just as easily leave things here and format the md0 device as ext3, mount it, and you'd be done. But we're not doing that just yet. So, onwards:
pvcreate /dev/md0Now display some info on your VG - the output should look a little like this - pay special attention to the number of PE (physical extents) you have available:
vgcreate vg_media /dev/md0
[root@canard ~]# vgdisplay vg_mediaOK so now we can go ahead and create the LV using the value for logical extents we obtained from the previous command:
--- Volume group ---
VG Name vg_media
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
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 1.95 GB
PE Size 4.00 MB
Total PE 499
Alloc PE / Size 499 / 1.95 GB
Free PE / Size 0 / 0
VG UUID 2rsx3T-C1Lx-uMRf-kz1g-UyBP-tbTz-iC7K1f
lvcreate -l 499 vg_media -n lv_mediaAnd again, display some information:
[root@canard ~]# lvdisplay /dev/vg_media/lv_mediaWe're nearly done! All that's left to do is format and mount the LV:
--- Logical volume ---
LV Name /dev/vg_media/lv_media
VG Name vg_media
LV UUID iS01Vt-Hyo7-GIiA-Sxlu-rc5J-bX5g-Trd9Ln
LV Write Access read/write
LV Status available
# open 1
LV Size 1.95 GB
Current LE 499
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
mkfs.ext3 /dev/vg_media/lv_mediaYou'll notice that df reports the parity space as being used already, so out of the 3GB we should have around 2GB available for use:
mkdir /mnt/lvtest
mount /dev/vg_media/lv_media /mnt/lvtest
[root@canard ~]# df -h /mnt/lvtest/Next I'll be failing a disk and expanding the LV to incorporate a second RAID5 array. As ever, stay tuned.
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_media-lv_media
2.0G 35M 1.8G 2% /mnt/lvtest
0 comments:
Post a Comment