Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Building a software RAID1 from an existing single drive?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
m00dawg
Tux's lil' helper
Tux's lil' helper


Joined: 27 Jan 2003
Posts: 145
Location: Texas

PostPosted: Sun May 22, 2005 5:19 pm    Post subject: Building a software RAID1 from an existing single drive? Reply with quote

I am curious: if I want to build a software RAID-1 setup is there a way to do this using my current (live) single drive and just adding another drive? I am using mdadm and I had limited success with my /boot partiition, but after I rebooted the system, I could no longer mount /boot using the raid device (but I could mount it using /dev/hda1 like I did before the RAID). In any case, I don't exactly know what I am doing and I would hate to wipe out all my data because of a stupid mistake :)
_________________
www.moocowproductions.org
Back to top
View user's profile Send private message
adaptr
Watchman
Watchman


Joined: 06 Oct 2002
Posts: 6730
Location: Rotterdam, Netherlands

PostPosted: Sun May 22, 2005 7:28 pm    Post subject: Reply with quote

If the drives are identical you could start by duplicating the data:
Code:
dd if=/dev/hda of=/dev/hdb bs=512

just make sure you copy the right drive! ;-)

But yes - since mdadm can rebuild a mirror when a drive fails, of course it can also create a mirror starting from one drive.

That's what rebuilding a failed mirror does...

If there are separate partitions on the drive then you can't do this directly, since you should end up with one mirror for each partition, not with an entire mirrored drive.

And you are responsible for creating partitions in that case; mdadm won't create any.

Again, assuming the drives are identical (and I do mean identical, not just the same size!) you can copy over the partition table from the first drive and let mdadm rebuild the second - it is perfectly legal to start a failed raid drive, i.e. a mirror that has only one drive.

If the drives are not identical, or you don't want to mirror every partition (especially swap; mirroring swap is worse than pointless!) then you'll have to set it up by hand:

1. create partitions on the second drive that can accomodate the original partitions; they don't need to be the same partition (number), but you'll save yourself quite some headaches by using the same numbering...
2. set these partitions to partition type FD == linux raid autodetect; mdadm won't work without it.
3. create an appropriate mdadm.conf; the minimal form only needs to contain a DEVICE line for every partition involved, and an ARRAY line for each mirror to tie them together.
4. do a rebuild

Here's a link for the commands, but beware of messing up your data!
http://www.macmegasite.com/node/1731

The most important thing to remember is that the raid drive will be /dev/md0, and not /dev/hda1 anymore...
Broken down:
1. install the new drive
2. make partitions to accommodate the raid set
3. start the failed raid drives, one mdadm -C for each partition
4. edit boot config to point to md0, and reboot
5. edit fstab
6. now add in the mirror partitions, and all should be underway.

You can check on the rebuilding process with
Code:
cat /proc/mdstat

It's completely transparent to the OS.
_________________
>>> emerge (3 of 7) mcse/70-293 to /
Essential tools: gentoolkit eix profuse screen
Back to top
View user's profile Send private message
m00dawg
Tux's lil' helper
Tux's lil' helper


Joined: 27 Jan 2003
Posts: 145
Location: Texas

PostPosted: Mon May 23, 2005 4:13 am    Post subject: Reply with quote

Great! Thank you very much! This is exactly what I needed. I haven't been brave enough to try it yet but I will as soon as I get some extra time (about to move to another city so, well, I guess now was not the time to try and mess with this :) )

As an update, the drives are not identical but they are of the same size. However, I can't create the partitions exactly right. Perhaps I just need to guess until I get it, but it should still be ok if the partitions aren't exactly the same size right (since it's software RAID)?
_________________
www.moocowproductions.org
Back to top
View user's profile Send private message
adaptr
Watchman
Watchman


Joined: 06 Oct 2002
Posts: 6730
Location: Rotterdam, Netherlands

PostPosted: Mon May 23, 2005 8:56 am    Post subject: Reply with quote

That is not a problem, as long as the new partitions are larger than the original ones, and definitely not smaller.
You'd be prone to losing data otherwise...
Or completely b0rking your system in a worst-case scenario.

You also want to install grub on both drives - or you won't be able to boot when the primary drive fails.
_________________
>>> emerge (3 of 7) mcse/70-293 to /
Essential tools: gentoolkit eix profuse screen
Back to top
View user's profile Send private message
sfp-a7x
n00b
n00b


Joined: 16 Nov 2004
Posts: 47

PostPosted: Thu Jul 28, 2005 3:46 pm    Post subject: Reply with quote

I'm trying to get something similar working. I have a working drive that's already set up with three partitions of type FD. I created single-drive RAID1 arrays with commands like:
Code:
mdadm --create --verbose /dev/md1 --level=1 --force --raid-devices=1 /dev/hda1

The "--force" parameter is necessary because mdadm thinks that "--raid-devices=1" is a typo. Anyway, all of my /dev/md devices are happy and my fstab is using /dev/md1 through 3 for the boot, swap, and root partitions. Now I want to add a second (identitcal) drive to the RAID1 array. I've partitioned it identically and set the types to FD. I tried mdadm --add, but it just creates a spare drive (not an actively synced drive). How do I add the second drive while ensuring the first drive is copied to the second? (It would be very bad if the second drive was copied to the first.)

Thanks!

edit: I just discovered the "--grow" option. The man page doesn't say how to use "--grow", but fortunately "mdadm --grow --help" does.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum