Solaris Volume Manager Administration Guide

ProcedureHow to Create a RAID-1 Volume From a File System

Use this procedure to mirror an existing file system. If the file system can be unmounted, the entire procedure can be completed without a reboot. For file systems that cannot be unmounted, such as /usr and /swap, the system must be rebooted to complete the procedure.

When creating a RAID-1 volume from an existing file system built on a slice, only the single slice may be included in the primary RAID-0 volume (submirror). If you are mirroring system-critical file systems, all submirrors must consist of only a single slice.

For the procedures associated with mirroring the root (/) file system, see SPARC: How to Create a RAID-1 Volume From the root (/) File System and x86: How to Create a RAID-1 Volume From the root (/) File System by Using DCA.

In the example used in this procedure, the existing slice is c1t0d0s0. The second slice, c1t1d0s0, is available for the second half of the mirror. The submirrors are d1 and d2, respectively, and the mirror is d0.


Caution – Caution –

Be sure to create a one-way mirror with the metainit command then attach the additional submirrors with the metattach command. When the metattach command is not used, no resynchronization operations occur. As a result, data could become corrupted when Solaris Volume Manager assumes that both sides of the mirror are identical and can be used interchangeably.


Before You Begin

Check Prerequisites for Creating Solaris Volume Manager Components and Creating and Maintaining RAID-1 Volumes.

Steps
  1. Identify the slice that contains the existing file system to be mirrored This example uses the slice c1t0d0s0.

  2. Create a new RAID-0 volume on the slice from the previous step by using one of the following methods:

    • From the Enhanced Storage tool within the Solaris Management Console, open the Volumes node, then choose Action⇒Create Volume. Follow the onscreen instructions . For more information, see the online help.

    • Use the following form of the metainit command:


      # metainit -f  volume-name number-of-stripes components-per-stripe component-name
      
      -f

      Forces the command to continue. You must use this option when the slice contains a mounted file system.

      volume-name

      Specifies the name of the volume to create. For information on naming volumes, see Volume Names.

      number-of-stripes

      Specifies the number of stripes to create.

      components-per-stripe

      Specifies the number of components each stripe should have.

      component-names

      Specifies the names of the components that are used. This example uses the root slice, c0t0d0s0.

  3. Create a second RAID-0 volume (concatenation) on an unused slice (c1t1d0s0 in this example) to act as the second submirror. The second submirror must be the same size as the original submirror or larger. Use one of the following methods:

    • From the Enhanced Storage tool within the Solaris Management Console, open the Volumes node, then choose Action->Create Volume and follow the instructions on screen. For more information, see the online help.

    • Use the following form of the metainit command.


      # metainit volume-name number-of-stripes components-per-stripe component-name
      

      Note –

      See Step 2 for an explanation of the options.


  4. Create a one-way mirror by using one of the following methods:

    • From the Enhanced Storage tool within the Solaris Management Console, open the Volumes node, then choose Action⇒Create Volume. Follow the onscreen instructions . For more information, see the online help.

    • Use the following form of the metainit command.


      # metainit volume-name -m submirror-name
      
      volume-name

      Specifies the name of the volume to create.

      -m

      Specifies to create a mirror.

      submirror-name

      Specifies the name of the component that will be the first submirror in the mirror. In this example, it is the RAID-0 volume that contains the root slice.

    See the metainit(1M) man page for more information.


    Caution – Caution –

    When you create a mirror from an existing file system, you must follow the next two steps precisely to avoid data corruption.


  5. Edit the /etc/vfstab file so that the file system mount instructions refer to the mirror, not to the block device. For more information about the/etc/vfstab file, see Mounting File Systems in System Administration Guide: Devices and File Systems.

    For example, if the /etc/vfstab file contains the following entry for the file system:


    /dev/dsk/slice /dev/rdsk/slice /var ufs 2 yes -

    Change the entry to read as follows:


    /dev/md/dsk/mirror-name /dev/md/rdsk/mirror-name /var ufs 2 yes -
  6. Remount your newly mirrored file system according to one of the following procedures:

    • If you are mirroring a file system that can be unmounted, then unmount and remount the file system.


      # umount /filesystem
      # mount /filesystem
      
    • If you are mirroring a file system that cannot be unmounted, then reboot your system.


      # reboot
      
  7. Use the following form of the metattach command to attach the second submirror.


    # metattach volume-name submirror-name
    
    volume-name

    Specifies the name of the RAID-1 volume on which to add the submirror

    submirror-name

    Specifies the name of the component that will be the second submirror attached to the mirror

    See the metattach(1M) man page for more information.


Example 11–3 Creating a Two-Way Mirror From a File System That Can Be Unmounted


# metainit -f d1 1 1 c1t0d0s0
d1: Concat/Stripe is setup
# metainit d2 1 1 c1t1d0s0
d2: Concat/Stripe is setup
# metainit d0 -m d1
d0: Mirror is setup
# umount /master
(Edit the /etc/vfstab file so that the file system references the mirror)
# mount /master
# metattach d0 d2
d0: Submirror d2 is attached

In this example, the -f option forces the creation of the first concatenation, d1, which contains the mounted file system /master on /dev/dsk/c1t0d0s0. The second concatenation, d2, is created from /dev/dsk/c1t1d0s0. This slice must be the same size as , or larger than the size of d1.) The metainit command with the -m option creates the one-way mirror, d0, from d1.

Next, the entry for the file system should be changed in the /etc/vfstab file to reference the mirror. The following line in the /etc/vfstab file initially appears as follows:


/dev/dsk/c1t0d0s0 /dev/rdsk/c1t0d0s0 /var ufs 2 yes -

The entry is changed to the following:


/dev/md/dsk/d0 /dev/md/rdsk/d0 /var ufs 2 yes -

Finally, the file system is remounted and submirror d2 is attached to the mirror, causing a mirror resynchronization. The system confirms that the RAID-0 and RAID-1 volumes are set up, and that submirror d2 is attached.



Example 11–4 Creating a Two-way Mirror From a File System That Cannot Be Unmounted


# metainit -f d12 1 1 c0t3d0s6
d12: Concat/Stripe is setup
# metainit d22 1 1 c1t0d0s6
d22: Concat/Stripe is setup
# metainit d2 -m d12
d2: Mirror is setup
(Edit the /etc/vfstab file so that /usr references the mirror)
# reboot
...
# metattach d2 d22
d2: Submirror d22 is attached

This example creates a two-way mirror using a slice containing the /usr file system. The -f option forces the creation of the first concatenation, d12, which contains the mounted file system /usr on /dev/dsk/c0t3d0s6. The second concatenation, d22, is created from /dev/dsk/c1t0d0s6. This slice must be the same size as, or larger than the size of d12. The metainit command with the -m option creates the one-way mirror d2 using the concatenation that contains the /usr file system. Next, the /etc/vfstab file must be edited to change the entry for /usr to reference the mirror.

The /etc/vfstab file contains the following entry for the /usr file system:


/dev/dsk/c0t3d0s6 /dev/rdsk/c0t3d0s6 /usr ufs 1 yes -

Change the entry to read as follows:


/dev/md/dsk/d2 /dev/md/rdsk/d2 /usr ufs 1 yes -

After a reboot, the second submirror d22 is attached to the mirror, causing a mirror resynchronization.



Example 11–5 Creating a Mirror From the /swap Space


# metainit -f d11 1 1 c0t0d0s1
d11: Concat/Stripe is setup
# metainit d21 1 1 c1t0d0s1
d21: Concat/Stripe is setup
# metainit d1 -m d11
d1: Mirror is setup
(Edit the /etc/vfstab file so that swap references the mirror)
# reboot
...
# metattach d1 d21
d1: Submirror d21 is attached

In this example, the -f option forces the creation of the first concatenation, d11, which contains the mounted file system swap on /dev/dsk/c0t0d0s1. The second concatenation, d21, is created from /dev/dsk/c1t0d0s1. This slice must be the same size as, or larger than the size of d11. The metainit command with the -m option creates the one-way mirror d1 using the concatenation that contains swap. Next, if there is an entry for swap in the /etc/vfstab file, it must be edited to reference the mirror.

The /etc/vfstab file contains the following entry for the swap space:


/dev/dsk/c0t0d0s1 - - swap - no -

Change the entry to read as follows:


/dev/md/dsk/d1 - - swap - no -

After a reboot, the second submirror d21 is attached to the mirror, causing a mirror resynchronization.

To save the crash dump when you have mirrored the swap space, use the dumpadm command to configure the dump device as a volume. For instance, if the swap device is named /dev/md/dsk/d2, use the dumpadm command to set this device as the dump device.