Converting a volume with data on it to a mirrored RAID volume in MacOS X

Since the days of Panther, Apple has included the ability to create and boot from Apple software RAIDs.  Unfortunately, regardless of how you ordered your XServe (RIP) or MacPro or mini server, the system comes with two drives, one with a clean system installed, the other completely empty.  While it is easy to reinstall and reformat the system from scratch, I find more beneficial to simply add that second empty drive to a “hot” RAID set that can be created on the fly.  This can be done fairly easily with a few simple command line arguments.

First things first, we need to promote our current volume to a RAID set.  We can’t do that while we are booted from the volume, so the best bet is to boot from a diagnostic drive or the system install DVD.  Once you have booted into your diagnostic system of choice, open up a terminal so we can get down to business.

We will be using the built in “diskutil” command to do all of our operations.  For more info on the tool, simply type “man diskutil”.

The first command we are going to run is going to tell us what disks we have in the system and their identifiers.  We will need some of this info for future tasks.

MikesMacbookPro17:~ szumlins$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS System_Drive            499.8 GB   disk0s2
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *4.0 GB     disk1
   1:                        EFI                         209.7 MB   disk1s1
   2:                  Apple_HFS New RAID Member         3.6 GB     disk1s2
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *2.0 GB     disk2
   1:                  Apple_HFS Volume With Data On It  1.9 GB     disk2s1

You will notice I have a couple of volumes created for this tutorial. The first is a volume labeled “Volume With Data On It”, the other is “New RAID Member”. I am using small thumb drives for this, so you can see the volume size is small. It is important to remember that you can’t add a member to a RAID set that is smaller than the existing volume size. The next thing we need to do is convert our standard HFS+ volume into a RAID set using the “appleRAID” command set in diskutil.

MikesMacbookPro17:~ szumlins$ diskutil appleraid enable mirror disk2s1
Started RAID operation on disk2s1 Volume With Data On It
Resizing disk
Unmounting disk
Adding booter for disk
Creating RAID set
Bringing RAID partition online
Waiting for new RAID to spin up "3301DE90-DF2C-4EF7-B0A6-8467D0ADE8AE"
Finished RAID operation on disk2s1 Volume With Data On It

Lets break down the command. First we call “diskutil”. The next command enters into the RAID command set using “appleraid”. We are going to enable a RAID set, so we call “enable “. Our options for RAID type or mirror or concatenated disk set. We can’t do RAID0 here as that would require a reformat. After that, we call out our partition with existing data on it, in this case “disk2s1”. To find this info, refer to our first command. Don’t forget to make note of the RAID UUID, we will use it later.

Lets run that first command command again.

MikesMacbookPro17:~ szumlins$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS System_Drive            499.8 GB   disk0s2
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *4.0 GB     disk1
   1:                        EFI                         209.7 MB   disk1s1
   2:                  Apple_HFS New RAID Member         3.6 GB     disk1s2
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *2.0 GB     disk2
   1:                 Apple_RAID                         1.9 GB     disk2s1
   2:                 Apple_Boot Boot OSX                134.2 MB   disk2s2
/dev/disk3
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Volume With Data On It *1.9 GB     disk3

You will see that we now have an Apple_RAID disk at disk2. Note that now our disk labeling may have changed since we started. If we got this far, we can run one more command to verify our RAID set is set up.

MikesMacbookPro17:~ szumlins$ diskutil appleraid list
AppleRAID sets (1 found)
===============================================================================
Name:                 Volume With Data On It
Unique ID:            3301DE90-DF2C-4EF7-B0A6-8467D0ADE8AE
Type:                 Mirror
Status:               Degraded
Size:                 1.9 GB (1877934080 Bytes)
Rebuild:              manual
Device Node:          disk3
-------------------------------------------------------------------------------
#   Device Node       UUID                                   Status
-------------------------------------------------------------------------------
0   disk2s1           694F3618-0317-4DC3-A8F1-44B4D5961E5C   Online
===============================================================================

At this point, it is safe to restart back into our system install to complete the process. You can continue on from the diagnostic drive, but you will have to wait until the RAID rebuilds itself otherwise it will enter a failure state. If you enter a failure state at this stage, you will have to remove your secondary failed drive and re-add it.

After the reboot, fire up another Terminal session so we can complete the process.

Run “diskutil appleraid list” again as well as “diskutil list” to get all of your important info, and then it is time to add our new RAID member.

MikesMacbookPro17:~ szumlins$ diskutil appleraid add member disk1 3301DE90-DF2C-4EF7-B0A6-8467D0ADE8AE
Started RAID operation on disk3 Volume With Data On It
Unmounting disk
Repartitioning disk1 for RAID
The added target disk is larger than the RAID set. This will result in unused disk space on the target disk 'disk1s2'
Adding disk1s2 to RAID Set
Finished RAID operation on disk3 Volume With Data On It

It is important to note that disk1 is the actually root device, not the partition of our secondary disk. All the data on the disk will be deleted when your run this command. We are in our “appleraid” command subset, but this time we use the “add” command. The first variable is the root disk of our new mirror member, the second command is the UUID of the RAID set we are adding it to. If all goes well, you now have a live RAID1 set!

Run our “diskutil appleraid list” command one more time and you can see our volume is rebuilding. Launching /Applications/Disk Utility.app will also bring up a GUI meter of the rebuild process.

MikesMacbookPro17:~ szumlins$ diskutil appleraid list
AppleRAID sets (1 found)
===============================================================================
Name:                 Volume With Data On It
Unique ID:            3301DE90-DF2C-4EF7-B0A6-8467D0ADE8AE
Type:                 Mirror
Status:               Degraded
Size:                 1.9 GB (1877934080 Bytes)
Rebuild:              manual
Device Node:          disk3
-------------------------------------------------------------------------------
#   Device Node       UUID                                   Status
-------------------------------------------------------------------------------
0   disk2s1           694F3618-0317-4DC3-A8F1-44B4D5961E5C   Online
1   disk1s2           22DCB47D-081E-4843-9483-4EAA02D3A9F7   4% (Rebuilding)
===============================================================================

One last note: Don’t restart the system until the RAID is finished rebuilding and shows online. Doing a little command line piping we can pretty quickly see from a Terminal how far along we are and can monitor remotely.

MikesMacbookPro17:~ szumlins$ diskutil appleraid list | tail -2 | head -1
1   disk1s2           22DCB47D-081E-4843-9483-4EAA02D3A9F7   4% (Rebuilding)

The tail command takes the last two lines, the head command takes only the first line from that. Doing this just returns the line we care about. You could use something like “cut” to even refine further if you wanted.

3 thoughts on “Converting a volume with data on it to a mirrored RAID volume in MacOS X

Leave a Reply to chris thacker (@alternapop)Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.