From: www.itworld.com

Setting Up RAID Volumes with Solaris Volume Manager, Part 2

by Sandra Henry-Stocker

May 25, 2005 —

 

In last week's column, we examined the process of setting up RAID volumes on a Solaris 9 server. The process is surprisingly straightforward when there are no file systems on the target disks or partitions. When file systems occupy the target space, they have to be backed up and then reloaded for RAID 5. For mirrored volumes, on the other hand, you can set up your volume in such a way as to preserve the initial partition's contents. In this column, we'll look at how these things are done.



RAID 5 for File Systems



Let's says that we want to turn the /var partition on our new Solaris 9 server into a RAID 5 volume. One way to back up its contents is to use a ufsdump command to copy the file system to another location on the disk. A command such as this will copy /var quite expediently (you need to create /var-bkp first):




# ufsdump 0f - /dev/rdsk/c0t0d0s5 | (cd /var-bkp/; ufsrestore xf -)



The 0f argument in this command specifies that we want a full dump and that we will specify the device that we are writing to. The - argument says that we're not really writing to a device at all; instead we are going to pipe the dump output to another command. The /dev/rdsk/c0t0d0s5 argument is, of course, our /var partition.



On the right side of the pipe, we have grouped two commands -- one to move into the /var-bkp directory and another to extract the contents from the dump. When this command completes, /var-bkp looks the same as /var.



Since the system won't allow us to unmount /var, we'll just make some changes to /etc/vfstab and reboot the system to use the backup as /var. To do this, we first comment out the mount line for /var from /etc/vfstab. Then, we move /var to /var-orig (to get the mount out of the way), move /var-bkp to /var and reboot:


# mv /var /var-orig
# mv /var-bkp /var
# reboot


At this point, /var is simply a subdirectory in root and partition 5 is not mounted. We can, therefore, proceed with our construction of the new RAID 5 volume using a metainit command such as this:


# metainit d5 -r c0t0d0s5 c0t1d0s5 c0t2d0s5d5: RAID is setup


Again, metainit has not completed the configuration of the volume when it spits out "RAID is setup". It will take a while longer and we can use the metastat command to watch its progress. The new volume will be ready when the state is "Okay":



# metastat | grep State
    State: Okay



Once the RAID volume is ready, we can build a new file system with newfs, mount the volume on a temporary mount and then copy the contents of /var-bkp (now /var) back to what will become the new /var. The newfs and mount commands will look like this:



# newfs /dev/md/rdsk/d5
# mkdir /var-new
# mount /dev/md/dsk/d5 /var-new


We then have some choices on how to copy the original contents of /var to the new RAID volume. One choice is to use a tar-to-tar command such as this:

# cd /var; tar cpBf - * | (cd /var-new; tar xf -)



Another is to use a ufsdump command similar to the one we used to back up /var in the first place. Using a ufsdump like that shown below, however, our files will end up in /var-new/var and will then have to be moved up one level when we're done:



# ufsdump 0f - /var | (cd /var-new; ufsrestore xf -)
# cd /var-new/var
# mv * ..


Once we have moved our files into our new partition, we are ready to uncomment the old /var mount line in /etc/vfstab and change it to look like this:



/dev/md/dsk/d5    /dev/md/rdsk/d5    /var    ufs    3    yes    -


We can then move /var back to /var-bkp, /var-new to /var and reboot.


Once we've verified that our RAID volume is working properly (check the mount and the output of metastat), we can remove the contents of /var-bkp entirely and delete the /var-orig mount point.

# rm -rf /var-bkp
# rmdir /var-orig



Mirrors for File Systems


Creating mirrors for file systems that you want to preserve (even root and swap) turns out to be surprisingly easy, especially if you have a copy of the "Solaris Volume Manager Administration Guide" by your side. The meta-commands (metadb, metainit, metastat) can be a little intimidating if you have never used them or rarely use them, but the inch-thick book has a good number of examples to serve as "recipes" while you're cooking up your own RAID volumes.


One naming convention for mirrors seems to be to use numbers divisible by 10, such as 10 and 20, for volumes and intervening numbers such as 11 and 12 for the individual mirror components. The components for mirror d10, for example, would be d11 and d12 while those for mirror d20 would be d21 and d22.


When you set up a drive to be mirrored, you must first create the RAID 0 (stripe or concatenation) volumes that will serve as the individual mirrors.


For partitions that contain file systems, you would issue the commands to set up the individual mirrors, attach the first to the mirrored volume (this is called a one-way mirror) and then reboot before attaching the second mirror. Let's look at this process in detail.


First, prepare the individual components (the commands below set up what are called one-on-one concatenations):


# metainit -f d11 1 1 c0t0d0s0
d11: Concat/Stripe is setup
# metainit d12 1 1 c0t1d0s0
d12: Concat/Stripe is setup


You then use another metainit command to create the one-way mirror:


# metainit d10 -m d11
d1: Mirror is setup



If you're mirroring root (as we are in this example), your next step would be to run the metaroot command:




# metaroot d10


This command makes the changes needed in the /etc/vfstab and /etc/system files that allow the system to boot with a metadevice root file system. For non-root file systems, you will have to edit /etc/vfstab by hand. You must then reboot the system.



# reboot



Only after the reboot will you add the second component to the mirror. You do this with the metattach command:


# metattach  d10 d12
d10: submirror d11 is attached


Setting up the mirror for swap is the same as for any other non-root file system. There is no equivalent of the metaroot command to run. So you need to edit the /etc/vfstab file by hand to specify that swap is to be mounted from the metadevice. Your new entry will look something like this:


/dev/md/dsk/d20  -       -       swap    -       no      -


For disks or partitions that do not contain data, the process of setting up a mirror doesn't require a reboot. Instead, you would issue a set of meta commands such as those shown below, modify /etc/vfstab, build your new file system and then mount it.

# metainit -f d31 1 1 c0t2d0s3
# metainit d32 1 1 c0t3d0s3
# metainit d30 -m d31
# metattach d30 d32
# newfs /dev/md/rdsk/d30


These commands for setting up a mirrored volume complete very quickly. You can then add a line like this to your /etc/vfstab file and mount your new partition:

/dev/md/dsk/d30 /dev/md/rdsk/d30        /data   ufs     3       yes     -


To mount the new volume, you simply need to create the mount point and issue the mount command:

# mkdir /data
# mount /data


Software volume managers will not give you the same performance as hardware RAID, but provide a considerable level of reliability for valuable data and at a modest cost (the price of the extra disks) and small investment of your time in setting up and administering the RAID and mirrored volumes.