Enhancing Disk Performance Using RAID and Vinum


Vinum is a software RAID tool built into FreeBSD, supported by a kernel module (geom_vinum.ko). It allows you to increase the efficiency of your ATA or SCSI disks (if you have more than one) by remapping their block device interfaces to a virtual set of "synthetic" drives (or volumes), which can contain plexes that comprise each volume's address space. A plex allows Vinum to automatically remap your data into arrangements such as RAID-1 (mirroring, which increases reliability), RAID-0 (striping, which increases performance), and RAID-5 (hybrid mirroring and striping) across the volumes constructed from your original hard disks.

Setting up Vinum is a procedure that involves a lot of manual calculations in several arcane steps, and requires a fair understanding of logical disk architectures and a willingness to dabble in areas of FreeBSD that are obscure and potentially dangerous. Advanced users who are interested in maximizing their disks' performance (especially in highavailability server applications) will want to at least consider using Vinum; but novices might want to avoid it for the time being.

Caution

Enabling Vinum also entails wiping your hard disks and reformatting them. You can't enable Vinum without erasing all your data and having to restore it from a backup. If your system doesn't have the option of being taken down to have its disk system entirely rebuilt from scratch, Vinum isn't in the cards.


To begin enabling Vinum, reboot your computer into single user mode (selecting the appropriate option at the loader menu). Mount the root partition read-write with the mount -u / command, and you're ready to proceed.

The first step in setting up Vinum is figuring out the exact sizes of your disks. You need to use the fdisk command for this (substitute da0 for ad0 if you're using SCSI disks):

# fdisk ad0 ******* Working on device /dev/ad0 ******* parameters extracted from in-core disklabel are: cylinders=8908 heads=255 sectors/track=63 (16065 blks/cyl) Figures below won't work with BIOS for partitions not in cyl 1 parameters to be used for BIOS calculations are: cylinders=8908 heads=255 sectors/track=63 (16065 blks/cyl) Media sector size is 512 Warning: BIOS sector numbering starts with sector 1 Information from DOS bootblock is: The data for partition 1 is: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)     start 63, size 143106957 (69876 Meg), flag 80 (active)         beg: cyl 0/ head 1/ sector 1;         end: cyl 1023/ head 254/ sector 63 The data for partition 2 is: <UNUSED> The data for partition 3 is: <UNUSED> The data for partition 4 is: <UNUSED>


As you can see from the middle of the fdisk output, the ad0 disk is 69876MB in size. This is important to remember. Repeat this command for all your disks (ad1, ad3, and so on) and write down their sizes.

Next, you need to convert your disks to the Vinum filesystem type. This involves changing their partition formats and creating new filesystems, which destroys your data. Be sure to back up your important data at this point and be sure you can restore it properly! See Chapter 21, "FreeBSD Survival Guide," for more information on backup techniques.

Use the bsdlabel -e command to enter an editing session (using vi, or whatever editor is specified in your shell's EDITOR variable) where you modify the partition layout of your disk's primary slice:

# bsdlabel -e ad0s1 # /dev/ad0s1: 8 partitions: #        size   offset    fstype   [fsize bsize bps/cpg]   a:  1048576        0    4.2BSD     2048 16384     8   b:  8336656  1048576      swap   c: 143106957        0    unused        0     0         # "raw" part, don't edit   d:  6264832  9385232    4.2BSD     2048 16384 28552   e:  2097152 15650064    4.2BSD     2048 16384 28552   f: 125359741 17747216    4.2BSD     2048 16384 28552


The important thing to note is the size of the c partition, which is a pseudo-partition whose size is the sum of all the rest of the partitions on the disk. (Bear in mind that all the sizes you'll be working with here are in 512-byte blocks.) What you need to do is add another partition (h) of nearly the same size as the entire rest of the disk, but of type vinum instead of 4.2BSD. This allows the two partitions to coexist and overlap. The h partition will need to be the size of the c partition minus 16 blocks, which in this case would be 143106941. Add this line to the end of the configuration:

  h: 143106941 16    vinum


Additionally, change the b partition as shown here, reducing the size of the swap partition by 281 sectors and changing the offset where it begins so it doesn't overlap its neighbor partitions once Vinum is in place:

  b: 8336375 1048857     swap


Finally, adjust the size of the root partition by 16 blocks:

  a: 1048560     16     4.2BSD     2048 16384     8


Save the file and exit. You now need to repeat this step for each additional drive.

Tip

For mirroring purposes, you should format additional drives with the same structure as your first one, so you might want to set up a partition structure using Sysinstall's disk label editor to match the one on your primary disk. This will allow you to use the same technique to add a vinum partition to the disk as you did with ad0.


Next, you need to set up a Vinum configuration file, which is fed into Vinum's "create" command when you set up the Vinum volumes. Listing 20.1 shows a sample configuration file. Call this file /etc/vinum.conf.

Listing 20.1. A Vinum Configuration Input File (/etc/vinum.conf)

drive DriveName device /dev/ad0s1h volume root   plex org concat     sd len 1048560s driveoffset 0s drive DriveName volume swap   plex org concat     sd len 8336675s driveoffset 265s drive DriveName volume var   plex org concat     sd len 6264832s driveoffset 9385216s drive DriveName volume tmp   plex org concat     sd len 2097152s driveoffset 15650048s drive DriveName volume usr   plex org concat     sd len 125359741s driveoffset 17747200s drive DriveName

The bold parts of the listing show the areas that you will have to adjust to your own configuration. The name of the drive (DriveName) can be any name you choose, though it shouldn't contain any spaces or special characters, nor should it refer to any particular device namethe drive's name should be device-independent. Additionally, the driveoffset value for each partition needs to be reduced by 16 from the corresponding number in the bsdlabel configuration. (These 16 sectors are used for bootstrapping code by Vinum.)

Tip

These examples show how to set up a RAID-1 (mirrored) drive array. To create a RAID-0 (striped) array, replace concat in the configuration file with striped.


Add a similar drive directive and set of volume directives for each of your other disks, and save the file. Give the additional drives' volumes the same names as the ones in your first disk because you'll be adding them together, coalescing them into combined virtual filesystems spanning multiple disks.

You next need to start Vinum, using the gvinum command, and create the Vinum configuration:

# gvinum gvinum -> create -f /etc/vinum.conf gvinum: drive DriveName is up gviunm: root.p0.s0 is up gviunm: root.p0 is up gvinum: root is up gvinum: swap.p0.s0 is up gvinum: swap.p0 is up gvinum: swap is up gvinum: var.p0.s0 is up gvinum: var.p0 is up gvinum: var is up gvinum: tmp.p0.s0 is up gvinum: tmp.p0 is up gvinum: tmp is up gvinum: usr.p0.s0 is up gvinum: usr.p0 is up gvinum: usr is up 1 drives: D DriveName              State: up       /dev/ad0s1h     A: 0/69876 MB (0%) 5 volumes: V root                  State: up       Plexes:       1 Size:        511 MB V swap                  State: up       Plexes:       1 Size:       4070 MB V var                   State: up       Plexes:       1 Size:       3059 MB V tmp                   State: up       Plexes:       1 Size:       1024 MB V usr                   State: up       Plexes:       1 Size:      61210 MB 5 plexes: P root.p0             C State: up       Subdisks:     1 Size:        511 MB P swap.p0             C State: up       Subdisks:     1 Size:       4070 MB P var.p0              C State: up       Subdisks:     1 Size:       3059 MB P tmp.p0              C State: up       Subdisks:     1 Size:       1024 MB P usr.p0              C State: up       Subdisks:     1 Size:      61210 MB P root.p1             C State: faulty   Subdisks:     1 Size:        511 MB P swap.p1             C State: faulty   Subdisks:     1 Size:       4070 MB P var.p1              C State: faulty   Subdisks:     1 Size:       3059 MB P tmp.p1              C State: faulty   Subdisks:     1 Size:       1024 MB P usr.p1              C State: faulty   Subdisks:     1 Size:      61210 MB 5 subdisks: S root.p0.s0            State: up       D: DriveName    Size:        511 MB S swap.p0.s0            State: up       D: DriveName    Size:       4070 MB S var.p0.s0             State: up       D: DriveName    Size:       3059 MB S tmp.p0.s0             State: up       D: DriveName    Size:       1024 MB S usr .p0.s0            State: up       D: DriveName    Size:      61210 MB S root.p1.s0            State: stale    D: Drive2       Size:        511 MB S swap.p1.s0            State: stale    D: Drive2       Size:       4070 MB S var.p1.s0             State: stale    D: Drive2       Size:       3059 MB S tmp.p1.s0             State: stale    D: Drive2       Size:       1024 MB S usr .p1.s0            State: stale    D: Drive2       Size:      61210 MB


In another terminal, check inside /dev for the existence of a vinum directory, and devices named usr, var, tmp, and so on inside them. These are your new disk devices. You can check that the virtual drives are working properly using the fsck -n -t ufs /dev/vinum/root command (and similar ones for your other drive devices, omitting the swap partition). You should see all your drives' names listed under the subdisks section, showing each disk's contribution to each volume separately. (Remember, this is a mirrored setup, so the two contributions to each volume don't add to its sizejust to its reliability.)

Tip

You should now configure /etc/fstab to use the new disk devices (/dev/vinum/usr instead of /dev/ad0s1f, for example).


Now you need to copy each original partition's data to the new subdisk of each volume. Within gvinum, issue start commands for each subdisk marked with State: stale.

gvinum -> start root.p1.s0 GEOM_VINUM: sd root.p1.s0 is initializing GEOM_VINUM: plex root.p1 is degraded


Allow each start process to complete before moving on to the next one. When you're finished, press Ctrl+D to exit the gvinum shell, and reboot the system in multiuser mode.

This completes the process for setting up a mirrored (RAID-1) disk system. For more information on using Vinum to create RAID-0 or RAID-5 arrays, consult the man vinum page, or seek assistance from cutting-edge FreeBSD administrators on the freebsd-questions mailing list.




FreeBSD 6 Unleashed
FreeBSD 6 Unleashed
ISBN: 0672328755
EAN: 2147483647
Year: 2006
Pages: 355
Authors: Brian Tiemann

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net