Oracle Blog

How'd you know I was blogging at you if you weren't blogging at me?

How to Shrink a mirrored ZFS rpool

The other day I wanted to shrink the size of my OpenSolaris ZFS root pool.The root pool is generally pretty small, and when possible I try to keep real data out of the root pool. In the case of target system, it has 4 disks and I have separate mirrored data pool. So I've got nearly 1 TB on two disks (root pool mirroring) just sitting idle, which could be used for something like say installing other O/Ses on bare iron (yeah, sometimes I still like to do that).

Anyways, maybe I am pathetic at web searches but after a few minutes of searching I could not find an answer. So I thought about it for a while and came up with a plausible way to do it, without the need of a live CD or usb stick or anything (did I mention I'm lazy, and didn't really feel like burning a CD)

The method I came up with is this, I'll follow up a summary with more detailed steps. Note that although this procedure is to shrink a mirrored root pool, you can probably use the same method on a non-mirrored pool, as long as you have a spare hard drive or partition somewhere.

Break the root pool mirror

Create a temporary root pool, resized appropriately, and boot to it

Destroy the real root pool, resize it, and boot back to it

Destroy the temporary root pool.

Reattach the mirror to the resized root pool

It sounds pretty simple, but there are a lot of steps involved. So here are the details.

In my case, I have a mirrored root pool made of the two devices

c2t0d0s0c2t1d0s0

Break the root pool mirror.

zpool detach rpool c2t1d0s0

Create a temporary root pool, resized appropriately, and boot to it.

First, you need to resize the Solaris fdisk partition, I usually just use the fdisk option in format, the general outline for this procedure is the following:

Run format

Select the disk you just detached (c2t1d0)

Start fdisk

Delete the Solaris partition

Create a new Solaris partition with a smaller size (say 50% of the disk, for example)

Save and exit fdisk

Start the partition tool

Adjust the disk slices so that s0 contains the entire disk

Label the disk

Exit format.

Now, create a temporary root pool, I'll call it tpool

zpool create -f tpool c2t1d0s0

Copy the data from the root pool to the temporary pool with ZFS send & receive

Then type 'b' to boot. When the system has completed booting, you should be booted off the temporary pool. You can verify this by

df -h /

Destroy the real root pool, resize it, and boot back to it.

First off, before you can destroy the root pool, the system might have some active references into the pool, like for swap and dump, and maybe some datasets like /export, you need to deactivate these before destroying the rpool.