Thursday, 1 December 2011

Solaris - Root disk mirroring by using SVM


Prerequisites
First, you need to identify the disks that you want to create mirrors with. You can do this by using the format command to find the disks in question.
AVAILABLE DISK SELECTIONS:
0. c0t0d0 <DEFAULT cyl 17845 alt 2 hd 255 sec 63>
/pci@7b,0/pci1022,7458@11/pci1000,3060@2/sd@0,0
1. c0t1d0 <DEFAULT cyl 17845 alt 2 hd 255 sec 63>
/pci@7b,0/pci1022,7458@11/pci1000,3060@2/sd@1,0
In my example, I'm mirroring the root partitions along with the other partitions from the disk drive. My drives are c0t0d0 and c0t1d0.
Procedure for Mirroring root
First, partition your primary drive, typically the one that the Solaris OS is currently running on. (In my case, this is drive 0, c0t0d0.)
You will need one partition that is about 10 Mbyte for the meta database.
Once you are satisfied with the partition that you have created, ensure that you label the disk, and then perform the following steps to transfer the same partitioning table.
Transfer the partition table from one drive to another.
# prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s - /dev/rdsk/c0t1d0s2
Note: Notice the use of s2, which is typically the overlap partition; if you changed this on the disk, please substitute the proper slice in its place.
Now that you have the two disks looking the same, execute the following:
# metadb -a -c 3 -f c0t0d0s7 c0t1d0s7
The -c 3 creates three copies of the metastat database in this space, just in case a single copy gets corrupted (which is never good).
We will initialize the disk that makes up the root partition by doing the following. I'm using s0 because this is my root partition; you can substitute where appropriate.
# metainit -f d11 1 1 c0t0d0s0
# metainit -f d12 1 1 c0t1d0s0
Now we will create the actual mirror:
# metainit d10 -m d11
After you have completed the preceding steps, you need to run the following command, which will automatically update /etc/system and /etc/vfstab to let it know that you are using a metadevice as your root disk.
# metaroot d10
Once command finished, reboot the machine:

# metattach d10 d12
To check on the status of the mirror, you can do the following:
# metastat d10
You will want to update the Openboot with the prior alias for the boot devices. You can do this by doing the following:
# ls -l /dev/dsk/c0t0d0s0
You output will look similar to the following
lrwxrwxrwx 1 root root 42 Jul 12 2007 /dev/dsk/c0t0d0s0 -> ../../devices/pci@1e,600000/ide@d/sd@0,0:a
You will need to update the bold part above, with your output. You will then run the following command from the OS
# eeprom "nvramrc=devalias mirror /pci@1e,600000/ide@d/disk@0,0:a devalias mirror-a /pci@1e,600000/ide@d/disk@1,0:a"
# eeprom boot-device="mirror mirror-a"
# eeprom "use-nvramrc?=true"
The below commands for doing this are from the OK prompt, don't do this else wise.
OK> nvalias mirror /pci@1e,600000/ide@d/disk@0,0:a mirror-a /pci@1e,600000/ide@d/disk@1,0:a
OK> setenv boot-device mirror mirror-a
If you are mirroring just the two internal drives, you will want to add the following line to /etc/system to allow it to boot from a single drive. This will bypass the SVM Quorum rule
set md:mirrored_root_flag = 1
# installboot /usr/platform/`uname -i`/lib/fs/ufs/bootblk /dev/rdsk/c0t1d0s