Crash course on zpool and zfs in Solaris

In this post we will have a look on how to use zpool and zfs in Solaris.

We will start after labeling a new disk c0t2d0.

Create zpool

  • Once we have labelled the disk let's add it in a zpool "cvpool" .
# zpool create cvpool c0t2d0
  • Let's see our new pool.
# zpool list
 NAME SIZE ALLOC FREE CAP HEALTH ALTROOT
 cvpool 4.97G 95.5K 4.97G 0% ONLINE -
 #

Create new ZFS

  • So our pool is ready now let's create a ZFS filesystem in it.
# zfs create cvpool/cldvdsfs
  • Ok that was easy. Have a look at what ZFS we have created.
# zfs list
NAME                USED   AVAIL    REFER   MOUNTPOINT
cvpool              104K   4.89G     21K   /cvpool
cvpool/cldvdsfs     21K    4.89G     21K   /cvpool/cldvdsfs
#
  • Check if our filesystem is mounted.
# df -h | grep -i cldvdsfs
 cvpool/cldvdsfs 4.9G 21K 4.9G 1% /cvpool/cldvdsfs
 #

Restrict ZFS

  • Above we can see that the filesystem is having 4.9GB which is actually the complete zpool size.
  • We don't want to give the full pool to one filesystem so let's restrict it to 500MB .
# zfs set quota=500m cvpool/cldvdsfs
# zfs set reservation=500m cvpool/cldvdsfs
  • Now if we check again the filesystem we can see it's now has total size of 500MB only.
# df -h | grep -i cldvdsfs
 cvpool/cldvdsfs 500M 21K 500M 1% /cvpool/cldvdsfs
 #

Grow or extend ZFS

  • What if you want to grow or extend the filesystem. Well that's also easy. If you have free space available you can increase the FS by just changing quota and reservation. If you want to know how to add new disks in a pool refer this post .
# zfs set quota=700m cvpool/cldvdsfs
# zfs set reservation=700m cvpool/cldvdsfs
  • So above we have increased the FS size to 700MB. Let's see if it reflects in "df -h" command.
 # df -h | grep -i cldvdsfs
 cvpool/cldvdsfs 700M 21K 700M 1% /cvpool/cldvdsfs
 #

Yes it does!!

View ZFS properties

  • You can see the properties assigned to a ZFS filesystem by running a zfs get.
# zfs get all cvpool/cldvdsfs

Rename ZFS mountpoint

  • Now if you don't like the mountpoint name of the ZFS filesystem and want to rename it to say  /cldvdsfs_new. You can do it by modifying the mountpoint property.
# zfs set mountpoint=/cldvdsfs_new cvpool/cldvdsfs
  • If we look in df command output we can see the mountpoint name changed.
# df -h | grep -i cldvdsfs
 cvpool/cldvdsfs 700M 21K 700M 1% /cldvdsfs_new
 #

Mirror zpool and zfs

  • If you want to mirror your ZFS filesystem you can do it by mirroring the zpool.
# zpool attach cvpool c0t2d0 c0t3d0
  • If we check status of the zpool we can see the disks are mirrored.
# zpool status cvpool
 pool: cvpool
 state: ONLINE
 scrub: resilver completed after 0h0m with 0 errors on Thu Sep 21 07:42:35 2017
config:

NAME STATE READ WRITE CKSUM
 cvpool ONLINE 0 0 0
 mirror-0 ONLINE 0 0 0
 c0t2d0 ONLINE 0 0 0
 c0t3d0 ONLINE 0 0 0 117K resilvered

errors: No known data errors

Delete zpool and ZFS

  • If you want to delete a zfs file system you can do it with destroy command. It will automatically unmount the filesystem if it's not in use.
zfs destroy cvpool/cldvdsfs
  • Finally delete the zpool.
# zpool destroy cvpool

Hope this post is helpful to you. Do let me know if you have any query.

No comments:

Post a Comment