Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Software RAID-1 on existing partition.
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
Headrush
Watchman
Watchman


Joined: 06 Nov 2003
Posts: 5597
Location: Bizarro World

PostPosted: Tue Aug 24, 2004 5:15 pm    Post subject: Software RAID-1 on existing partition. Reply with quote

I have an existing Gentoo installation on /dev/hde
I have an identical HD on /dev/hdg

Is it possible to create a level-1 mirrored software raid partition without losing the installed system?

The kernel has all required raid features already.

If not, is it possible to create the software raid on /dev/hdg only? (1 disk)
Start off the partition and then modify the raid settings to add /dev/hde to the mirror?
Back to top
View user's profile Send private message
msalerno
Veteran
Veteran


Joined: 17 Dec 2002
Posts: 1338
Location: Sweating in South Florida

PostPosted: Wed Aug 25, 2004 6:36 pm    Post subject: Reply with quote

You could use the LiveCD to boot, copy all of the data off of the partition, setup the mirror, then copy the data back. I don't know if this is the best way to accomplish this, but I know that it is possible to do without losing any data.

You might find some pointers in the following topic.
https://forums.gentoo.org/viewtopic.php?t=8813&highlight=software+raid
Back to top
View user's profile Send private message
Headrush
Watchman
Watchman


Joined: 06 Nov 2003
Posts: 5597
Location: Bizarro World

PostPosted: Wed Aug 25, 2004 7:02 pm    Post subject: Reply with quote

That's what I was asking.

Can I set up the raid (/etc/raid or whatever it is) only containing one disk, transfer the data on the non-raid drive to the raid drive, then erase the non-raid drive and add it to the raid?
Back to top
View user's profile Send private message
lwithers
Guru
Guru


Joined: 31 Dec 2003
Posts: 300
Location: Reading, UK

PostPosted: Wed Aug 25, 2004 7:24 pm    Post subject: Reply with quote

Yes, you can do this without much hassle. I did it a couple of weeks ago without problems. The list of instructions is rather complicated; would you like me to type them up, or are you OK trying it for yourself?
Back to top
View user's profile Send private message
Headrush
Watchman
Watchman


Joined: 06 Nov 2003
Posts: 5597
Location: Bizarro World

PostPosted: Wed Aug 25, 2004 8:41 pm    Post subject: Reply with quote

If it's not too much trouble I would appreciate that and it might help others too.

I have it partly working. For some reason because it is only on 1 disk so far, it made the partition half the size, and if I don't put noauto in fstab, /etc/init.d/checkfs crashes on boot.
Back to top
View user's profile Send private message
Headrush
Watchman
Watchman


Joined: 06 Nov 2003
Posts: 5597
Location: Bizarro World

PostPosted: Wed Aug 25, 2004 9:01 pm    Post subject: Reply with quote

I think I have found the problem.

I have the proper RAID function built-in the kernel. (gentoo-dev-sources-2.6.8 )

When the kernel loads, it sees the raid and I believe starts it. The output is:

Code:

md: Autodetecting RAID arrays.
md: autorun ...
md: considering hda2 ...
md:  adding hda2 ...
md: created md0
md: bind<hda2>
md: running: <hda2>
raid1: raid set md0 active with 1 out of 1 mirrors
md: ... autorun DONE.


Then, the script /etc/init.d/checkfs runs.
It checks /proc/mdstat which show my active raid, but then it tries again to start the raid.

Code:

if [ "${retval}" -gt 0 -a -x /sbin/raidstart ]
     then
     /sbin/raidstart "${i}"
     retval=$?
fi

if [ "${retval}" -gt 0 -a -x /sbin/raid0run ]
      then
      /sbin/raid0run "${i}"
      retval=$?
fi
 
if [ "${retval}" -gt 0 -a -x /sbin/raidadd -a -x /sbin/raidrun ]
      then
      /sbin/raidadd "${i}"
      /sbin/raidrun "${i}"
      retval=$?
fi


Of course this causes errors and aborts the bootup.

Does the output from the first listing above show the raid is step up and ready?
Is the second section of code redundant?
Back to top
View user's profile Send private message
lwithers
Guru
Guru


Joined: 31 Dec 2003
Posts: 300
Location: Reading, UK

PostPosted: Wed Aug 25, 2004 10:53 pm    Post subject: Reply with quote

The output above says "1 out of 1 mirrors". A RAID array with only a single drive is pretty pointless, right? :-)

Well, here is the list of instructions you can use to convert your system over to RAID1. It might seem quite a bit, but feel free to ask questions.

For the sake of argument, I'm assuming that you've got a system installed on /dev/hde and that your identical drive is on /dev/hdg . You might need to change that. I've also assumed that you will be partitioning the disks according to the following scheme:
Boot: /dev/hdg1 (partition type fd -- linux raid autodetect) (ext3fs) (bootable)
Swap: /dev/hdg2 (partition type 82)
Root: /dev/hdg3 (partition type fd) (ext3fs)

1. You'll need a kernel with the raid1 option built in (not a module).

2. If you haven't already got mdadm, emerge it.

3. Run "cfdisk /dev/hdg" and set up the partitions.

4. Set up the swap partition: "mkswap /dev/hdg2"

5. Set up the RAID1 arrays, and format them. These are known as "degraded" arrays -- they are started off with a missing device (will be added later).
Code:
mdadm --create /dev/md0 --level=raid1 -n2 missing /dev/hdg1
mdadm --create /dev/md1 --level=raid1 -n2 missing /dev/hdg3
mke2fs -j /dev/md0
mke2fs -j /dev/md1


6. If mdadm complained about having a missing device and didn't create /dev/md?, rerun the command with "--run" in there somewhere. You'll need to do this before you can create the filesystems.

7. Now mount the partitions so that you can copy over your filesystem:
Code:
mkdir /mnt/xxx
mount /dev/md1 /mnt/xxx
cd /mnt/xxx
mkdir boot
mount /dev/md0 boot


8. Copy across your boot partition (we'll have to run grub/lilo later):
Code:
mount /boot
cd /mnt/xxx/boot
cp -a /boot/* .
umount /boot


9. Copy across your root partition (note that we specifically exclude /proc, /sys, /dev from the cp command):
Code:
cd /mnt/xxx
cp -a /bin /etc /home /lib /opt /root /sbin /usr /var .
mkdir dev mnt proc sys tmp


10. Edit the relevant configuration files. Your boot partition is now /dev/md0, and your root partition is now /dev/md1. This needs to be changed in the new /etc/fstab, and in the new grub/lilo config file. Also in fstab, you'll have swap on /dev/hde2 and /dev/hdg2.

At this point, you need to reboot, because we're about to erase the current filesystem. You can either set up the new filesystem so that you can boot straight into it, or (easier) boot off a Knoppix CD or LiveCD. I'm assuming that you're going to use a CD, so:

1. Run "cfdisk /dev/hde", and set it up exactly the same as /dev/hdg.

2. Set up the swap partition: "mkswap /dev/hde2"

3. Run "modprobe raid1" to insert the RAID1 module.

4. Reassemble the array in degraded mode (remember to use --run if you need it):
Code:
mdadm --assemble /dev/md0 /dev/hdg1
mdadm --assemble /dev/md1 /dev/hdg3


5. Now you can hot-add the new devices to the array with:
Code:
mdadm --add /dev/md0 /dev/hde1
mdadm --add /dev/md1 /dev/hde3


6. Wait for the array to rebuild. You can do "cat /proc/mdstat" to see progress.

Now you need to make the system bootable. I don't know how to do this with lilo (shouldn't be tricky), but with grub:

1. chroot into the system and get the grub commandline up:
Code:
mkdir /mnt/xxx
mount /dev/md1 /mnt/xxx
cd /mnt/xxx
mount /dev/md0 boot
chroot /mnt/xxx /bin/bash
grub


2. Enter these commands in grub, which will make the array boot if both disks are present or if either disk is down:
Code:
root (hd0,0)
setup (hd0)
device (hd0) /dev/hdg
root (hd0,0)
setup (hd0)


I've assumed that /dev/hde is the first bootable device (i.e. (hd0)); if not, you'll need to rejig that a little.

At this point, the system should boot into the new raid array. Good luck!
Back to top
View user's profile Send private message
Headrush
Watchman
Watchman


Joined: 06 Nov 2003
Posts: 5597
Location: Bizarro World

PostPosted: Wed Aug 25, 2004 11:05 pm    Post subject: Reply with quote

Thanks for that HOW-TO. I think that will help people a lot.

I did get my working.

The reason my raid says 1 of 1 is because I setup up the raid to only have 1 drive. I mounted it, copied my current system over. Once I rebooted off the raid, I just erased the orginal, and then added it to the raid and it worked.

There is a problem with the current /etc/init.d/checkfs in that the kernel starts the raid and then this scripts tries to start it also. When it fails because it is already started, the script forces a reboot. I hard coded around this code and I'm currently looking to properly fix it. Checking at bugs.gentoo.org this problem has been around awhile and no perfect fix has yet to be designed.

For anyone that may be wondering, if you're using a new 2.6 kernel your raid drive is /dev/md/#. You may or may not have a symbolic link to /dev/md0. So if your missing /dev/md0, lookin /dev/md/
Back to top
View user's profile Send private message
lwithers
Guru
Guru


Joined: 31 Dec 2003
Posts: 300
Location: Reading, UK

PostPosted: Wed Aug 25, 2004 11:18 pm    Post subject: Reply with quote

Ah, I see what you mean about the checkfs script. I don't have an /etc/mdadm.conf so I never got bitten. And thanks for the info about /dev/md/* :-)
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