Monday, December 04, 2006

ZFS Cheatsheet

The three primary goals of ZFS are:

  1. Highly scalable (128-bit) data repository
  2. Ease of administration
  3. Guaranteed on disk data integrity

Sample ZFS commands and usage


What You Do and See Why
$ man zpool
$ man zfs
Get familiar with command structure and options
$ su
Password:
# cd /
# mkfile 100m disk1 disk2 disk3 disk5
# mkfile 50m disk4
# ls -l disk*
-rw------T 1 root root 104857600 Oct 6 08:13 disk1
-rw------T 1 root root 104857600 Oct 6 08:13 disk2
-rw------T 1 root root 104857600 Oct 6 08:13 disk3
-rw------T 1 root root 52428800 Oct 6 08:13 disk4
Create some “virtual devices” or vdevs as described in the zpool documentation. These can also be real disk slices if you have them available.
# zpool create myzfs /disk1 /disk2
# zpool list

NAME SIZE USED AVAIL CAP HEALTH ALTROOT
myzfs 199M 24.0K 199M 0% FAULTED -
Create a storage pool and check the size and usage.
# zpool status -v
pool: myzfs
state: FAULTED
reason: Too many devices are damaged or missing for the pool
to function.
see: http://www.sun.com/msg/ZFS-XXXX-02
config:

NAME STATUS
/disk1 ONLINE
/disk2 ONLINE
Get more detailed status of the zfs storage pool.
# zpool destroy myzfs
# zpool list
no pools available
Destroy a zfs storage pool
# zpool create myzfs mirror /disk1 /disk4
invalid vdev specification
use '-f' to override the following errors:
mirror contains devices of different sizes
Attempt to create a zfs pool with different size vdevs fails. Using -f options forces it to occur but only uses space allowed by smallest device.
# zpool create myzfs mirror /disk1 /disk2
# zpool status -v
pool: myzfs
state: FAULTED
reason: Too many devices are damaged or missing for the pool
to function.
see: http://www.sun.com/msg/ZFS-XXXX-02
config:

NAME STATUS
mirror ONLINE
/disk1 ONLINE
/disk2 ONLINE
Create a mirrored pool. I’m not sure at this time why it is labeled as faulted.
# zpool iostat 5
capacity operations bandwidth
pool used avail read write read write
---------- ----- ----- ----- ----- ----- -----
myzfs 24.5K 99.5M 0 24 0 173
myzfs 24.5K 99.5M 0 0 0 0
myzfs 24.5K 99.5M 0 0 0 0
Get I/O statistics for the pool
# zfs create myzfs/jim
# df -k
Filesystem kbytes used avail capacity Mounted on
...
myzfs/jim 85478 8 85470 1% /zfs/myzfs/jim
Create a file system and check it with standard df -k command. Note the size is 83.5 MB from a
100 MB zpool (mirrored). File systems are automatically mounted by default under the /zfs location. See the Mountpoints section of the zfs man page for more details.
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
myzfs 33.5K 83.5M - /zfs/myzfs
myzfs/jim 8K 83.5M 8K /zfs/myzfs/jim
List current zfs file systems.
# zpool add myzfs /disk3
invalid vdev specification
use '-f' to override the following errors:
mismatched replication level: pool uses 2-way mirror
and new vdev uses 1-way file
Attempt to add a single vdev to a mirrored set fails
# zpool add myzfs mirror /disk3 /disk5
pool: myzfs
state: FAULTED
reason: Too many devices are damaged or missing for the pool
to function.
see: http://www.sun.com/msg/ZFS-XXXX-02
config:

NAME STATUS
mirror ONLINE
/disk1 ONLINE
/disk2 ONLINE
mirror ONLINE
/disk3 ONLINE
/disk5 ONLINE
Add a mirrored set of vdevs
# zfs create myzfs/jim2
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
myzfs 26.5M 156M - /zfs/myzfs
myzfs/jim 26.3M 156M 26.3M /zfs/myzfs/jim
myzfs/jim2 8K 156M 8K /zfs/myzfs/jim2
Create a second file system. Note that both file system show 156M available because no quotas are
set. Each “could” grow to file the pool.
# zfs set reservation=20m myzfs/jim
# zfs list -o reservation
RESERV
none
20.0M
Reserve a specified amount of space for a file system ensuring that other users don’t take up all the space.
# zfs set quota=20m myzfs/jim2
# zfs list -o quota myzfs/jim myzfs/jim2
QUOTA
none
20.0M
Set and view quotas
# zfs set compression=on myzfs/jim2
# zfs list -o compression
COMPRESS
off
off
on
Turn on compression
# zfs snapshot myzfs/jim@test
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
myzfs 20.0M 63.5M - /zfs/myzfs
myzfs/jim 8K 83.5M 8K /zfs/myzfs/jim
myzfs/jim@test 0 - 8K /zfs/myzfs/jim@test
Create a snapshot called test.
# zfs rollback myzfs/jim@test
Rollback to a snapshot.
# zfs clone myzfs/jim@test myzfs/jim3
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
myzfs 20.0M 63.5M - /zfs/myzfs
myzfs/jim 8K 83.5M 8K /zfs/myzfs/jim
myzfs/jim@test 0 - 8K /zfs/myzfs/jim@test
myzfs/jim3 0 63.5M 8K /zfs/myzfs/jim3
A snapshot is not directly addressable. A clone must be made.The target dataset can be located anywhere in the ZFS hierarchy, and will be created as the same type as the original.
# zfs destroy myzfs/jim2
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
myzfs 26.5M 157M - /zfs/myzfs
myzfs/jim 26.3M 157M 26.3M /zfs/myzfs/jim
Destroy a filesystem
# zpool destroy myzfs
cannot destroy 'myzfs': pool is not empty
use '-f' to force destruction anyway
Can’t destroy a pool with active filesystems.
# zfs unmount myzfs/jim
Unmount a ZFS file system
# zpool destroy -f myzfs
# zpool status -v
no pools available
Use the -f option to destroy a pool with files systems created.

No comments: