Creative Training Solutions

Salix Training Limited

This page shows an example of using the ZFS filesystem.

The ZFS Filesystem

Install Solaris 10 Update 2 (06/06) to have the required packages.

This exercise will walk you through the process of creating virtual disks. The advantage of this method, is that you can create a huge number of disks and more realistic ZFS pools.

 

A. Creating Virtual Disks

A1. Locate a filesystem with at least 2G of free space.

(for example /export or /zones or create a new filesystem)

 

A2. Create ten large files to use as virtual disks. Some will be used in the pool and some will be spare:

 

Text Box: # mkfile 200m /virtualdisks/disk1
# mkfile 200m /virtualdisks/disk2
# mkfile 200m /virtualdisks/disk3
# mkfile 200m /virtualdisks/disk4
# mkfile 200m /virtualdisks/disk5
# mkfile 200m /virtualdisks/disk6
# mkfile 200m /virtualdisks/disk7
# mkfile 200m /virtualdisks/disk8
# mkfile 200m /virtualdisks/disk9
# mkfile 200m /virtualdisks/disk10

 

B. Creating A Simple 2-Way Mirror

B1. Create the following ZFS pool which will have two disks in it. These will be the two sub-mirrors. When created, check the pool configuration and size with zpool commands:

 

Text Box: # zpool create pool mirror /virtualdisks/disk1 /virtualdisks/disk2
# zpool status
  pool: mypool
 state: ONLINE
 scrub: none requested
config:

        NAME                     STATE     READ WRITE CKSUM
        mypool                   ONLINE       0     0     0
          mirror                 ONLINE       0     0     0
            /virtualdisks/disk1  ONLINE       0     0     0
            /virtualdisks/disk2  ONLINE       0     0     0
errors: No known data errors
# zpool list
NAME                    SIZE    USED   AVAIL    CAP  HEALTH     ALTROOT
mypool                  195M   78.5K    195M     0%  ONLINE     -

 

B2. Check where the pool has been mounted.

 

Text Box: # df -F zfs 
Filesystem             size   used  avail capacity  Mounted on
mypool                 163M    24K   163M     1%    /mypool

 

The pool will be mounted to a directory at the top of the filesystem, in this example /mypool.


C. Mount Points and Filesystems

C1. Multiple filesystems can be created in the pool and the mount-points for these filesystems do not have to be the same as the pool mount point.

 

In ZFS, creating a hierarchy of filesystems is encouraged. Properties assigned to one file system (like compression) are inherited by sub-filesystems. In this example, a filesystem is created for all user's homes and then sub filesystems for two users. Follow this example:

 

Text Box: # zfs create mypool/home
# zfs set mountpoint=/export/home mypool/home
# zfs create mypool/home/dave
# zfs create mypool/home/phil
# zfs create mypool/home/sam
# df -F zfs
Filesystem             size   used  avail capacity  Mounted on
mypool                 163M    24K   163M     1%    /mypool
mypool/home            163M    28K   163M     1%    /export/home
mypool/home/dave       163M    24K   163M     1%    /export/home/dave
mypool/home/phil       163M    24K   163M     1%    /export/home/phil
mypool/home/sam        163M    24K   163M     1%    /export/home/sam

 

Notice that each user appears to have access to all the space in the pool (163M).

 

C2. Copy a large file into Dave's home and see what effect it has in the free space in the pool:

 

Text Box: # cp /var/sadm/install/contents /export/home/dave
# df -F zfs
Filesystem             size   used  avail capacity  Mounted on
mypool                 163M    24K   150M     1%    /mypool
mypool/home            163M    28K   150M     1%    /export/home
mypool/home/dave       163M    13M   150M     8%    /export/home/dave
mypool/home/phil       163M    24K   150M     1%    /export/home/phil
mypool/home/sam        163M    24K   150M     1%    /export/home/sam

 

Notice that the free space has gone down for all filesystems. Carious options can be enabled for particular zfs filesystems to reduce the amount of disk space used or prevent one user depriving other users of disk space.

D. Filesystem Options

D1. Use zfs set commands to enable compression for Phil and check the results:

 

Text Box: # zfs set compression=on mypool/home/phil
# cp /var/sadm/install/contents /export/home/phil
# df -F zfs
Filesystem             size   used  avail capacity  Mounted on
mypool                 163M    24K   147M     1%    /mypool
mypool/home            163M    28K   147M     1%    /export/home
mypool/home/dave       163M    13M   147M     8%    /export/home/dave
mypool/home/phil       163M   3.2M   147M     3%    /export/home/phil
mypool/home/sam        163M    24K   147M     1%    /export/home/sam

 

Notice that Phil's home directory is only using 3.2M of disk space when it has the same file in it as Dave (who is using 13M of disk space).


D2. You may think that enabling compression will make the filesystem slower. Run some tests copying files to compressed and non-compressed ZFS file systems:

 

Text Box: # time for loop in 1 2 3 4 5 
> do
> cp /var/sadm/install/contents /export/home/dave/file${loop}
> done

real    0m38.67s
user    0m0.00s
sys     0m1.84s

# time for loop in 1 2 3 4 5 
> do
> cp /var/sadm/install/contents /export/home/phil/file${loop}
> done

real    0m20.21s
user    0m0.00s
sys     0m2.09s

 

The real time is the time elapsed from when the command was started to when it ended. The sys time is the amount of CPU time assigned to the process. How can you explain the time differences shown above and when wouldn't it be more efficient to enable compression?

 

____________________________________________________________________

 

____________________________________________________________________

 

D3. Before looking at the next option, clear out all the large files created during compression performance testing from the user's file systems:

 

Text Box: # rm /export/home/dave/file[0-9]
# rm /export/home/phil/file[0-9]
# rm /export/home/sam/file[0-9] 
# df -F zfs
Filesystem             size   used  avail capacity  Mounted on
mypool                 163M    24K   147M     1%    /mypool
mypool/home            163M    28K   147M     1%    /export/home
mypool/home/dave       163M    13M   147M     8%    /export/home/dave
mypool/home/phil       163M   3.2M   147M     3%    /export/home/phil
mypool/home/sam        163M    24K   147M     1%    /export/home/sam

 

Dave and Phil have one copy of the large file in their homes. Phil's home is showing less used disk space because he still has compression turned on.

 


D4
. Enabling disk quotas will prevent one user from starving other users of disk space. Follow this example to restrict the amount of disk space available to Sam:

 

Text Box: # zfs set quota=50m mypool/home/sam
# df -F zfs 
Filesystem             size   used  avail capacity  Mounted on
mypool                 163M    24K   147M     1%    /mypool
mypool/home            163M    28K   147M     1%    /export/home
mypool/home/dave       163M    13M   147M     8%    /export/home/dave
mypool/home/phil       163M   3.2M   147M     3%    /export/home/phil
mypool/home/sam         50M    24K    50M     1%    /export/home/sam

 

Notice that the size and available column shows only 50M whereas other filesystems have the full pool size of 163M. Copy in the large file to see the usage change:

 

Text Box: # cp /var/sadm/install/contents /export/home/sam
# df -F zfs                                     
Filesystem             size   used  avail capacity  Mounted on
mypool                 163M    24K   139M     1%    /mypool
mypool/home            163M    28K   139M     1%    /export/home
mypool/home/dave       163M    13M   139M     9%    /export/home/dave
mypool/home/phil       163M   3.2M   139M     3%    /export/home/phil
mypool/home/sam         50M   8.3M    42M    17%    /export/home/sam

 

ZFS—Page 1

Phone:    +44 (0)20 8144 6944

Fax:        +44 (0)870 913 0007