Partitioning Lots of Drives in a Linux RAID

So, I had a really fun question and I’ll open this up for others to volunteer other solutions. But I ran into one of those tedious little jobs while prototyping some Linux-based storage solutions. Underneath it all is a RAID (Redundant Array of Independent Disks). But I wanted to mess around with some different tuning parameters to make the solution as fast possible while also making use of the most disk space. Make sense?Well, to do my little mad scientist tricks, I had to configure the partitions on 16 disk drives. And I had various iterations where I needed to tweak the sizes of each partition. Now, if you’ve ever used fdisk or parted for disk partitioning, you know this is a pain in the butt. Can you imagine trying to do all of this in a GUI? I’ve done that too. Forget it. It just takes way too long.

As common a task as this appears to me, I couldn’t find one solution for automating this across a number of drives. Most of the tools simply partition one drive at a time, and one partition at a time. Oh yeah, I loved how creating partitions within parted would typically result in partitions not ending on a cylinder boundary. I got all sorts of system complaints with that one, especially within fdisk.

Anyway, I digress. I didn’t have the time or patience to write this in a more comfortable language like perl or python, or C# which is my current favorite language. Rather I stuck with simple Bash (Bourne Again Shell) for the task.

So, after much digging, the best thing I found was that I could use redirection to feed a script to fdisk. Basically, it looks like this:

fdisk /dev/sda < myfdisk.script

Pretty simple, huh? The key here is to get the myfdisk.script right. Here’s a sample:

n
p
1
1
4
n
p
2
5
460
n
p
3
461

w

Now then, I’m hoping you’ll notice a pattern of n, p and then 1, 2, 3. This sets up new, primary partitions 1, 2 and 3. Okay?

The key is the size of the partitions. I plan to RAID together a couple of 30MB partitions for my /boot RAID1. That’s covered by blocks 1 through 4. Wondering how I came up with that? Well, (4 cylinders*16065 sectors/cylinder*512 bytes/sector)/(1024*1024). That’s how. Just in case you were wondering. ;) BTW, the blank space between the 461 and the w tells fdisk to accept the very last cylinder boundary as the ending one for partition 3.

But that only comes up with my partitioning scheme. There’s 16 drives, remember. I suppose I could do this 16 times. It would sure be a lot faster than manually going into fdisk to do this. It’s be a lot faster than parted too. But it’s still more work than I’d like. So, I need a simple loop. I did this in bash as well. This is what I came up with:

#!/bin/bash

DISKS = “/dev/sd[a-p]“

for disk in $DISKS; do
fdisk $disk < myfdisk.script
done

exit 0

That’s it. This creates a very simple list of 16 drives and ripples them through the fdisk routine. Simple and crude, perhaps. But it gets the job done without having to write any code.

If you’ve got another way of doing this more simply, I’d love to hear from you.

Update: 2/27/2007 => I went ahead and made a simple change to the script to make things a bit easier. Rather than typing out all 16 disk paths, I repaced it all with brackets, sd[a-p]. Easier, huh?

  • Trackback are closed
  • Comments (2)
  1. Huh?? Are you even speaking English?

    I bet your brain hurts from being so smart. Thanks for making a gal feel stupid. ;)

  2. you and my husband would have a fine time talking to each other…