pavement

RAID1, Software, How to setup

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
(software RAID1 mirroring (new article))
 
m (Reverted edits by 173.88.199.104 (talk) to last revision by 95.222.239.72)
 
(14 intermediate revisions by 9 users not shown)
Line 8: Line 8:
  
 
==Booting into the LiveCD filesystem==
 
==Booting into the LiveCD filesystem==
# Reboot from the Install CD (FreeBSD 5.4 or above) or with Install CD disc2 (FreeBSD 5.3)
+
Reboot from the Install CD (FreeBSD 5.4 or above) or from Install CD disc2 (FreeBSD 5.3), and enter Fixit mode. Then get the root filesystem and devfs running:
# Enter Fixit mode.
+
  
  # chroot /dist
+
  # '''chroot /dist'''
  # mount_devfs devfs /dev
+
Before FreeBSD 7
 +
  # '''mount_devfs devfs /dev'''
 +
FreeBSD 7 and newer
 +
# '''mount -t devfs devfs /dev'''
  
 
==Preparing to Create a Mirror==
 
==Preparing to Create a Mirror==
First, make sure the GEOM module is loaded:
+
Make ABSOLUTELY CERTAIN that you don't have any pre-existing GEOM module labels written to either of your drives - because if you do (for instance from having futzed about with this before finding this article, or trying the article once and then trying it again) it will prevent other things from working.  So, clean off any preexisting metadata from each drive:
  
  # gmirror load
+
  # '''gmirror clear /dev/ad0'''
 +
# '''gmirror clear /dev/ad2'''
  
Next, make ABSOLUTELY CERTAIN that you don't have any pre-existing GEOM module labels written to either of your drives - because if you do (for instance from having futzed about with this before finding this article, or trying the article once and then trying it again) it will prevent other things from working.  So, clean off any preexisting metadata from each drive:
+
Before we get started with the actual mirror procedures, we'll make sure the GEOM module is loaded:
  
  # gmirror clear /dev/ad0
+
  # '''gmirror load'''
# gmirror clear /dev/ad2
+
  
 
==Creating and Initializing the Mirror==
 
==Creating and Initializing the Mirror==
Now that we've got that sorted out, you've got a decision to make - do you want your new mirror to use round-robin device balancing, or load-based?  (''Split'' balancing is also available, but is beyond the scope of this article.  ''man gmirror'' for details.)
+
Now that we've got that sorted out, you've got a decision to make - do you want your new mirror to use round-robin device balancing, or load-based?  ('''Split''' balancing is also available, but is beyond the scope of this article.  '''man gmirror''' for details.)
  
Round-robin balancing simply makes each successive data access request to the next component in the mirror since the last one, whereas load-based tries to intelligently send data access requests to the least loaded component in the mirror.  I'm going to assume you want ''load'' balancing, but if you prefer ''round-robin'', simply substitute that in the label command below.
+
Round-robin balancing simply makes each successive data access request to the next component in the mirror since the last one, whereas load-based tries to intelligently send data access requests to the least loaded component in the mirror.  I'm going to assume you want '''load''' balancing, but if you prefer '''round-robin''' or '''split''' read requests simply substitute that in the label command below.
  
  # gmirror label -v -b load gm0 /dev/ad0
+
  # '''gmirror label -v -b load gm0 /dev/ad0'''
  # mount /dev/mirror/gm0s1a /mnt
+
  # '''mount /dev/mirror/gm0s1a /mnt'''
  
And we've created and mounted our mirror filesystem, currently with a single physical drive in it - our existing system drive.
+
And we've created and mounted our mirror filesystem, currently with a single physical drive in it - our existing system drive.
  
 
==Reconfiguring the System==
 
==Reconfiguring the System==
 
Now it's time to set things up so that we can boot the system to the GEOM mirror itself, not to /dev/ad0 directly.  The next two commands will make sure that the GEOM module will load automatically at boot time, and tell the system that the swap file will be on a mirror, not a raw drive.   
 
Now it's time to set things up so that we can boot the system to the GEOM mirror itself, not to /dev/ad0 directly.  The next two commands will make sure that the GEOM module will load automatically at boot time, and tell the system that the swap file will be on a mirror, not a raw drive.   
  
  # echo geom_mirror_load="YES" >> /mnt/boot/loader.conf
+
  # '''echo geom_mirror_load=\"YES\" >> /mnt/boot/loader.conf'''
  # echo swapoff="YES" >> /mnt/etc/rc.conf
+
  # '''echo swapoff=\"YES\" >> /mnt/etc/rc.conf'''
  
 
Now we need to fix fstab to refer to the mirror, not to /dev/ad0 itself.  You can either manually edit it using [[ee]] or [[vi]] and change all references to /dev/ad0? to /dev/mirror/gm0? - ie /dev/ad0s1b becomes /dev/mirror/gm0s1b - or you can use a [[sed]] command to do it for you:
 
Now we need to fix fstab to refer to the mirror, not to /dev/ad0 itself.  You can either manually edit it using [[ee]] or [[vi]] and change all references to /dev/ad0? to /dev/mirror/gm0? - ie /dev/ad0s1b becomes /dev/mirror/gm0s1b - or you can use a [[sed]] command to do it for you:
  
  # sed “s%ad0%mirror/gm0%/mnt/etc/fstab > /mnt/etc/fstab.new
+
  # '''sed "s%ad0%mirror/gm0%g" /mnt/etc/fstab > /mnt/etc/fstab.new'''
  # mv /mnt/etc/fstab /mnt/etc/fstab.old
+
  # '''mv /mnt/etc/fstab /mnt/etc/fstab.old'''
  # mv /mnt/etc/fstab.new /mnt/etc/fstab
+
  # '''mv /mnt/etc/fstab.new /mnt/etc/fstab'''
  
And now we're ready to reboot!  So pull the live CD out of the drive, issue a ''shutdown -r now'', and you should come back up nicely with everything just as it was.
+
And now we're ready to reboot!  So pull the live CD out of the drive, issue a '''shutdown -r now''', and you should come back up nicely with everything just as it was.
  
 
==Adding the New Drive==
 
==Adding the New Drive==
 
The only thing left to do now is to add the physical /dev/ad2 device to your shiny new /dev/mirror/gm0 mirror.
 
The only thing left to do now is to add the physical /dev/ad2 device to your shiny new /dev/mirror/gm0 mirror.
  
  # gmirror insert gm0 /dev/ad2
+
  # '''gmirror insert gm0 /dev/ad2'''
  
And that should be all she wrote - the system should automatically start synchronizing the new device into the mirror without any further prompting from you.  You can issue a ''gmirror list'' to see both components and make sure everything looks good, and from here on out everything should get handled automagically by the system - monitor [[/var/log/messages]] for any errors or info as needed.
+
And that should be all she wrote - the system should automatically start synchronizing the new device into the mirror without any further prompting from you.  You can issue a '''gmirror list''' to see both components and make sure everything looks good, and from here on out everything should get handled automagically by the system - monitor [[/var/log/messages]] for any errors or info as needed.
  
 
==External links==
 
==External links==
Line 59: Line 61:
 
http://dannyman.toldme.com/2005/01/24/freebsd-howto-gmirror-system/  the original how-to this article was based upon.
 
http://dannyman.toldme.com/2005/01/24/freebsd-howto-gmirror-system/  the original how-to this article was based upon.
  
[[Category:Common Tasks]]
+
[[Category:FreeBSD Terminology]]
 +
[[Category:FreeBSD for Servers]]
 +
[[Category:RAID]]

Latest revision as of 16:55, 25 August 2012

Contents

[edit] Intro

This is a quick and dirty tutorial on setting up gmirror software-based RAID1 mirroring on an existing FreeBSD system. The goal is to convert all system partitions - including / and swap - from using the original system drive to running on a mirror consisting of the original drive and a physically identical mirror drive, safely and without losing any data. This will allow faster data read times as well as provide a measure of data and uptime security against individual drive failure.

[edit] Prerequisites

You MUST be running FreeBSD 5.3 or newer to use gmirror. For the purposes of this walkthrough, you will also need two IDENTICAL drives. We will be assuming that those drives are /dev/ad0 and /dev/ad2, with FreeBSD installed and working on /dev/ad0, and /dev/ad2 being either blank and brand-new or having data you no longer care about on it.

If you are using FreeBSD 5.3, you will also need a copy of Install CD Disc2.

[edit] Booting into the LiveCD filesystem

Reboot from the Install CD (FreeBSD 5.4 or above) or from Install CD disc2 (FreeBSD 5.3), and enter Fixit mode. Then get the root filesystem and devfs running:

# chroot /dist

Before FreeBSD 7

# mount_devfs devfs /dev

FreeBSD 7 and newer

# mount -t devfs devfs /dev

[edit] Preparing to Create a Mirror

Make ABSOLUTELY CERTAIN that you don't have any pre-existing GEOM module labels written to either of your drives - because if you do (for instance from having futzed about with this before finding this article, or trying the article once and then trying it again) it will prevent other things from working. So, clean off any preexisting metadata from each drive:

# gmirror clear /dev/ad0
# gmirror clear /dev/ad2

Before we get started with the actual mirror procedures, we'll make sure the GEOM module is loaded:

# gmirror load

[edit] Creating and Initializing the Mirror

Now that we've got that sorted out, you've got a decision to make - do you want your new mirror to use round-robin device balancing, or load-based? (Split balancing is also available, but is beyond the scope of this article. man gmirror for details.)

Round-robin balancing simply makes each successive data access request to the next component in the mirror since the last one, whereas load-based tries to intelligently send data access requests to the least loaded component in the mirror. I'm going to assume you want load balancing, but if you prefer round-robin or split read requests simply substitute that in the label command below.

# gmirror label -v -b load gm0 /dev/ad0
# mount /dev/mirror/gm0s1a /mnt

And we've created and mounted our mirror filesystem, currently with a single physical drive in it - our existing system drive.

[edit] Reconfiguring the System

Now it's time to set things up so that we can boot the system to the GEOM mirror itself, not to /dev/ad0 directly. The next two commands will make sure that the GEOM module will load automatically at boot time, and tell the system that the swap file will be on a mirror, not a raw drive.

# echo geom_mirror_load=\"YES\" >> /mnt/boot/loader.conf
# echo swapoff=\"YES\" >> /mnt/etc/rc.conf

Now we need to fix fstab to refer to the mirror, not to /dev/ad0 itself. You can either manually edit it using ee or vi and change all references to /dev/ad0? to /dev/mirror/gm0? - ie /dev/ad0s1b becomes /dev/mirror/gm0s1b - or you can use a sed command to do it for you:

# sed "s%ad0%mirror/gm0%g" /mnt/etc/fstab > /mnt/etc/fstab.new
# mv /mnt/etc/fstab /mnt/etc/fstab.old
# mv /mnt/etc/fstab.new /mnt/etc/fstab

And now we're ready to reboot! So pull the live CD out of the drive, issue a shutdown -r now, and you should come back up nicely with everything just as it was.

[edit] Adding the New Drive

The only thing left to do now is to add the physical /dev/ad2 device to your shiny new /dev/mirror/gm0 mirror.

# gmirror insert gm0 /dev/ad2

And that should be all she wrote - the system should automatically start synchronizing the new device into the mirror without any further prompting from you. You can issue a gmirror list to see both components and make sure everything looks good, and from here on out everything should get handled automagically by the system - monitor /var/log/messages for any errors or info as needed.

[edit] External links

http://people.freebsd.org/~rse/mirror/ a more complicated approach, involving possibly mismatched disks, etc. http://dannyman.toldme.com/2005/01/24/freebsd-howto-gmirror-system/ the original how-to this article was based upon.

Personal tools