Thursday, November 19, 2009

[Level 2] Tips on ZFS.

1. Is that possible to migrate root filesytem from smaller hard disk to larger one without shutdown the operation system? The answer is "Yes", if you use OpenSolaris.
You can use a larger disk to attach into the pool and make the hard disk be a part of mirror disk of the root file system. After join the pool, the zfs pool will reslivering the data from origin one to new hard disk. After reslivered, then deatch the old hard disk, then the zfs capacity will also increased.
The simulation output as the following.

# mkdir /temp

# mkfile 128m /temp/128m
# mkfile 256m /temp/256m
# ls /temp/*m
-rw-------   1 stanley  staff    134217728 Nov 19 09:06 /temp/128m
-rw-------   1 stanley  staff    268435456 Nov 19 09:06 /temp/256m
#

# pfexec zpool create myPool /temp/128m
# zpool status myPool
  pool: myPool
 state: ONLINE
 scrub: none requested
config:

    NAME          STATE     READ WRITE CKSUM
    myPool        ONLINE       0     0     0
      /temp/128m  ONLINE       0     0     0

errors: No known data errors

# zfs list myPool
NAME     USED  AVAIL  REFER  MOUNTPOINT
myPool  68.5K  90.9M    19K  /myPool

#

# pfexec zpool attach myPool /temp/128m /temp/256m
# zpool status myPool
  pool: myPool
 state: ONLINE
 scrub: resilver completed after 0h0m with 0 errors on Thu Nov 19 09:09:26 2009
config:

    NAME            STATE     READ WRITE CKSUM
    myPool          ONLINE       0     0     0
      mirror        ONLINE       0     0     0
        /temp/128m  ONLINE       0     0     0
        /temp/256m  ONLINE       0     0     0  71.5K resilvered


errors: No known data errors

# zfs list myPool
NAME     USED  AVAIL  REFER  MOUNTPOINT
myPool  80.5K  90.9M    19K  /myPool

#

# pfexec zpool detach myPool /temp/128mb
# zpool status myPool
  pool: myPool
 state: ONLINE
 scrub: resilver completed after 0h0m with 0 errors on Thu Nov 19 09:09:26 2009
config:

    NAME          STATE     READ WRITE CKSUM
    myPool        ONLINE       0     0     0
      /temp/256m  ONLINE       0     0     0  71.5K resilvered

errors: No known data errors

# zfs list myPool
NAME     USED  AVAIL  REFER  MOUNTPOINT
myPool    82K   219M    19K  /myPool



2. How to shrink virtual disk of VirtualBox?
Virtual disk will not shrink even you delete data in the virtual machine. So, is that possible to shrink the virtual disk of VirtualBox? The answer is yes, if your virtual disk is on ZFS file system.
The steps as the following.
a. Create a virtual disk with dynamic disk type.
b. Add virtual disk to the virtual machine.
c. Attach the new virtual to the old one, and make them be a mirror disk.
d. After disk reslivered, detach the old disk from the mirror.

The same way can may your disk from fix disk size type to dynamic disk size type.

Wish this helps.

regards,
Stanley Huang