![]() |
![]() |
|
|
|
|
|
Like my work? Check out HexaLex, my game for iPhone & iPod Touch. It's a crossword game like Scrabble, but played with hexagonal tiles. http://www.hexalex.com (Note: I’ve gone back and forth about posting this article. I really am not an expert in this area and I don’t want to advise people to do something stupid. OTOH, this is something that I’ve never seen described before. I’ve decided to post it, but it’s probably best treated as a curiosity, not a data storage strategy.) Let’s do a little Linux magic. We’re going to create a RAID 1 (mirrored) pair, transform it to a 2-disk RAID 5 array (you know, the kind that “requires” 3 or more disks), then grow it to a 3-disk RAID 5 array.
Just so nobody gets too confused, I’m using a fairly fresh install of Ubuntu 6.06 Dapper Drake, which includes EVMS 2.5.4. First let’s make some 10MB “disks” to play with. $ mkdir disks $ cd disks $ dd if=/dev/zero of=img0 bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10 MB) copied, 0.734714 seconds, 14.3 MB/s $ # These produce similar output: $ dd if=/dev/zero of=img1 bs=1M count=10 $ dd if=/dev/zero of=img2 bs=1M count=10 And let’s mount them as loopback devices: $ sudo su # From here on out we'll need root privileges # losetup /dev/loop0 img0 # losetup /dev/loop1 img1 # losetup /dev/loop2 img2 Now we’re ready to work in evms. Launch the NCurses interface to evms with the command Next, we will build our first RAID, a level 1 mirrored pair. Select Now if this were a real storage array we were building we would probably put an LVM2 container on top of Select Let’s put a filesystem on it, so we can save some test data to the volume. Select At this point your logical volumes list (hit zero to show it if it’s not there already) should look something like this: Name Size Modified Active R/O Plug-in Mountpoint ----------------------------------------------------------------------------------------- /dev/evms/RaidVol 9.9 MB X Ext2/3 EVMS is a cautious system and doesn’t actually change anything until you save your changes. At this point we need to save our progress, so select It’s easy for me to tell you this works, but if you want to have confidence in this procedure you’ll want to verify it for yourself. Copy some files to # ls -l /mnt/raidvol/zeros -rw-r--r-- 1 root root 8971264 2006-06-30 00:03 /mnt/raidvol/zeros # md5sum /mnt/raidvol/zeros 37e6cfefc792d550d54f0422c8521fea /mnt/raidvol/zeros You might also want to
$ cat /proc/mdstat
Personalities : [raid1] [raid5]
md0 : active raid1 loop1[1] loop0[0]
10176 blocks [2/2] [UU]
unused devices: <none>
Now we’re ready to start making magic. (Hint: You might want to back up We’re going to be doing some things behind the back of The next bit is somewhat voodoo. It’s based on the semi-obscure fact that the RAID 5 algorithm can indeed be applied to two disks, and when you do so the disks end up mirrored! This works because the parity of a single block is equal to the block itself, though the normal way of setting up RAID 5 arrays involves computing the parity of at least two blocks. As a consequence, the only difference between a 2-disk RAID 1 pair and 2-disk RAID 5 array is the metadata! By rewriting the RAID metadata, we can instantly convert our array to RAID 5. We’re going to use # mdadm --stop /dev/evms/md/md0 Now we’re going to “create” a RAID 5 array using our existing loopback devices. In effect, this should just change the metadata and give us a functional array.
# mdadm --create /dev/md0 --level=5 -n 2 /dev/loop0 /dev/loop1
mdadm: /dev/loop0 appears to contain an ext2fs file system
size=10172K mtime=Fri Jun 30 00:28:04 2006
mdadm: /dev/loop0 appears to be part of a raid array:
level=1 devices=2 ctime=Thu Jun 29 23:20:15 2006
mdadm: /dev/loop1 appears to contain an ext2fs file system
size=10172K mtime=Fri Jun 30 00:28:04 2006
mdadm: /dev/loop1 appears to be part of a raid array:
level=1 devices=2 ctime=Thu Jun 29 23:20:15 2006
Continue creating array? y
mdadm: array /dev/md0 started.
Now the moment of truth! Let’s try mounting # mount /dev/md0 /mnt/raidvol # ls /mnt/raidvol lost+found zeros Hooray! Let’s make sure nothing got corrupted: # ls -l /mnt/raidvol/zeros -rw-r--r-- 1 root root 8971264 2006-06-30 00:03 /mnt/raidvol/zeros # md5sum /mnt/raidvol/zeros 37e6cfefc792d550d54f0422c8521fea /mnt/raidvol/zeros And let’s convince ourselves that we really have a RAID 5 array:
# cat /proc/mdstat
Personalities : [raid1] [raid5]
md0 : active raid5 loop0[0] loop1[1]
10176 blocks level 5, 64k chunk, algorithm 2 [2/2] [UU]
unused devices: <none>
Part II: Growing the ArrayHot-damn, it worked! Now let’s add another disk to the RAID 5 array. First we unmount the volume, then go back to evms: # umount /mnt/raidvol/ # evmsn Growing a RAID 5 array is actually quite easy in evms, but the documentation gives one little-to-no help understanding how it’s done. Trial-and-error led me to the following procedure:
Actions > Convert > Compatibility Volume to EVMS Volume
use the name RaidVol and select /dev/evms/md/md0
Actions > Expand > Volume
choose RaidVol
choose md/md0 as the "expand point"
choose loop2 as the object
Actions > Save
You should get a list of messages that the procedure has produced, and, with luck, none of them should be error messages! Choose # ls /mnt/raidvol/ lost+found zeros # df -h /mnt/raidvol/ Filesystem Size Used Avail Use% Mounted on /dev/evms/RaidVol 20M 9.7M 9.0M 52% /mnt/raidvol # ls -l /mnt/raidvol/zeros -rw-r--r-- 1 root root 8971264 2006-06-30 00:03 /mnt/raidvol/zeros # md5sum /mnt/raidvol/zeros 37e6cfefc792d550d54f0422c8521fea /mnt/raidvol/zeros Nifty, eh? Now before you run down to your data center and try this procedure on your client’s drives, you should be aware that I’m pretty clueless about all this stuff and there may very well be extremely good reasons not to do this. If you do attempt it, make sure you have recent backups, and don’t say I didn’t warn you!
|
|
![]() |
![]() |




Well, I tried your RAID1 to RAID5 conversion this weekend on my home workstation and it worked a treat.
I’ve blogged about the experience at, http://scott.wallace.sh/node/1521.
I just wanted to drop you a note thanking you for making my life that little bit easier. I didn’t have to reinstall my entire workstation to double my disk space!
Thanks!