ZFS: Difference between revisions
| Line 26: | Line 26: | ||
=== Creating a ZFS Volume === | === Creating a ZFS Volume === | ||
When creating a new volume, we want to have it start after 1MB from the start, and end maybe 200MB from the end. Therefore, the total size of the volume will be the size of the disk less 201MB. (See http://www.freebsddiary.org/zfs-with-gpart.php) | |||
From <code>diskinfo -v</code>, we know that: | |||
* Each disk has 3907029168 sectors | |||
* We want to start 1MB in from the start. | |||
Since our disks contains 3907029168 sectors, we would need to create a partition on each disk that has 3907029168 - 411648 (that is 3906617520) sectors. | ** 1MB = 1024*1024 bytes. | ||
** 1024*1024 bytes / 512 bytes/sector = 2048 sectors | |||
* We want to have 200MB at the end. ie: in total, 201MB of the disk is not part of the partition | |||
** 201*1024*1024 bytes = 201*1024*1024 bytes / 512 bytes/sector = 411648 sectors | |||
** Therefore, the size of the zfs partition is 3906617520 sectors - 411648 sectors | |||
Since our disks contains 3907029168 sectors, we would need to create a partition on each disk that has 3907029168 - 411648 (that is 3906617520) sectors. Note that if you are using different disks with different sizes that you will need to adjust the calculation ( partition size = total sectors - 411648 ) accordingly. | |||
# gpart add -b 2048 -s 3906617520 -t freebsd-zfs -l disk00 ada0 | # gpart add -b 2048 -s 3906617520 -t freebsd-zfs -l disk00 ada0 | ||
| Line 58: | Line 64: | ||
errors: No known data errors | errors: No known data errors | ||
=== ZFS Snapshot === | === ZFS Snapshot === | ||
Revision as of 17:39, 15 April 2013
This will be a quick overview on how to manage ZFS snapshots and volumes on a FreeBSD 9.0 system, but it should apply to Solaris as well.
A Few Assumptions
Suppose that my system has the following drives.
- ada0 WDC WD20EARS-00J99B0
- 3907029168 512 byte sectors
- ada2 WDC WD20EARS-00J99B0
- 3907029168 512 byte sectors
- ada3 ST2000DM001-9YN164
- 3907029168 512 byte sectors
- ada4 ST2000DL003-9VT166
- 3907029168 512 byte sectors
- ada5 ST2000DM001-9YN164
- 3907029168 512 byte sectors
Note: To find out what your disks are by running camcontrol devlist and diskinfo -v *disk* to determine the sector size / sector count.
Creating a ZFS Volume
When creating a new volume, we want to have it start after 1MB from the start, and end maybe 200MB from the end. Therefore, the total size of the volume will be the size of the disk less 201MB. (See http://www.freebsddiary.org/zfs-with-gpart.php)
From diskinfo -v, we know that:
* Each disk has 3907029168 sectors * We want to start 1MB in from the start. ** 1MB = 1024*1024 bytes. ** 1024*1024 bytes / 512 bytes/sector = 2048 sectors * We want to have 200MB at the end. ie: in total, 201MB of the disk is not part of the partition ** 201*1024*1024 bytes = 201*1024*1024 bytes / 512 bytes/sector = 411648 sectors ** Therefore, the size of the zfs partition is 3906617520 sectors - 411648 sectors
Since our disks contains 3907029168 sectors, we would need to create a partition on each disk that has 3907029168 - 411648 (that is 3906617520) sectors. Note that if you are using different disks with different sizes that you will need to adjust the calculation ( partition size = total sectors - 411648 ) accordingly.
# gpart add -b 2048 -s 3906617520 -t freebsd-zfs -l disk00 ada0 # gpart add -b 2048 -s 3906617520 -t freebsd-zfs -l disk01 ada2 # gpart add -b 2048 -s 3906617520 -t freebsd-zfs -l disk02 ada3 # gpart add -b 2048 -s 3906617520 -t freebsd-zfs -l disk03 ada4 # gpart add -b 2048 -s 3906617520 -t freebsd-zfs -l disk04 ada5
Once created, you should be able to create your new ZFS volume by running:
# zpool create -f storage raidz1 gpt/disk00 gpt/disk01 gpt/disk02 gpt/disk03 gpt/disk04
# zpool status
pool: storage
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
storage ONLINE 0 0 0
raidz1-0 ONLINE 0 0 0
gpt/disk00 ONLINE 0 0 0
gpt/disk01 ONLINE 0 0 0
gpt/disk02 ONLINE 0 0 0
gpt/disk03 ONLINE 0 0 0
gpt/disk04 ONLINE 0 0 0
errors: No known data errors
ZFS Snapshot
A ZFS snapshot is a read-only copy of the file system. It can be listed using the zfs list -t snapshot command.
# zfs list -t snapshot NAME USED AVAIL REFER MOUNTPOINT storage@20120820 31.4G - 3.21T - storage@20120924 134G - 4.15T - storage@20121028 36.2G - 4.26T - storage@20121201 33.2M - 4.55T -
To create a new snapshot, run
zfs snapshot storage@today
Note that this will not consume additional space when created. It will however grow in size when data gets modified.
# zfs list -t snapshot NAME USED AVAIL REFER MOUNTPOINT storage@20120820 31.4G - 3.21T - storage@20120924 134G - 4.15T - storage@20121028 36.2G - 4.26T - storage@20121201 33.2M - 4.55T - storage@today 0 - 4.58T -
Snapshot contents can be accessed through a special .zfs/snapshot/ directory. Each snapshot will contain a read-only copy of the data that existed when the snapshot was taken.
# ls /storage/.zfs/snapshot/ 20120820/ 20120924/ 20121028/ 20121201/ today/
To roll back to a specific snapshot, run zfs rollback storage@yesterday. This will restore your volume to the snapshot state.
# zfs rollback storage@yesterday
To delete a specific snapshot, run zfs destroy storage@today. Note that this will not work if other volumes depend on it. eg: If you cloned it as another volume.
# zfs destroy storage@today
Data Integrity
One of the strengths of ZFS its resiliency thanks to its transactional file system. The only way data stored on a ZFS volume to be in an inconsistent state is through hardware failure or some sort of fault with the ZFS implementation. Similar to a fsck on ext file systems, a ZFS scrub provides a way to perform filesystem checking. To initiate a scrub, run:
# zpool scrub storage
Once the scrub process is underway, you can view its status by running:
# zpool status storage
pool: storage
state: ONLINE
scan: scrub in progress since Mon Dec 3 23:54:53 2012
18.3G scanned out of 6.05T at 211M/s, 8h20m to go
0 repaired, 0.30% done
config:
NAME STATE READ WRITE CKSUM
storage ONLINE 0 0 0
raidz1-0 ONLINE 0 0 0
gpt/disk00 ONLINE 0 0 0
gpt/disk01 ONLINE 0 0 0
gpt/disk02 ONLINE 0 0 0
gpt/disk03 ONLINE 0 0 0
gpt/disk04 ONLINE 0 0 0
errors: No known data errors
To stop a scrub process, run:
# zpool scrub -s storage