Oracle Solaris 11 ZFS Lab

7
12/17/12 Oracle Solaris 11 ZFS Lab 1/7 file:///Users/pavelanni/Projects/SolarisLab/lab/ZFS Lab.html Oracle Solaris 11 ZFS Lab Table of Contents Exercise Z.1: ZFS Pools Exercise Z.2: ZFS File Systems Exercise Z.3: ZFS Compression Exercise Z.4: ZFS Deduplication Exercise Z.5: ZFS Snapshots Exercise Z.6: ZFS Clones Exercise Z.1: ZFS Pools Task: You have several disks to use for your new file system. Create a new disk pool and a file system on top of it. Lab: We will check the status of disk pools, create our own pool and expand it. Our Solaris 11 installation already has a ZFS pool. It's your root file system. Check this: root@solaris:~# zpool list NAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT rpool 15.9G 5.64G 10.2G 35% 1.00x ONLINE This is our root system ZFS pool. In Solaris 11 the root file system must be ZFS created on top of ZFS pool. What do we know about this pool? root@solaris:~# zpool status rpool pool: rpool state: ONLINE scan: none requested config: NAME STATE READ WRITE CKSUM rpool ONLINE 0 0 0 c3t0d0s0 ONLINE 0 0 0 errors: No known data errors Let's now create our own ZFS pool. What do we need for that? Just several disks and one command. We will create several files in /dev/dsk directory; they will act as disks in our lab: root@solaris:~# cd /dev/dsk root@solaris:~# mkfile 200m disk{0..9} We'll take four disks and create a ZFS pool with RAIDZ protection: root@solaris:~# zpool create labpool raidz disk0 disk1 disk2 disk3

description

Oracle Solaris 11 ZFS

Transcript of Oracle Solaris 11 ZFS Lab

Page 1: Oracle Solaris 11 ZFS Lab

12/17/12 Oracle Solaris 11 ZFS Lab

1/7file:///Users/pavelanni/Projects/SolarisLab/lab/ZFS Lab.html

Oracle Solaris 11 ZFS LabTable of ContentsExercise Z.1: ZFS PoolsExercise Z.2: ZFS File SystemsExercise Z.3: ZFS CompressionExercise Z.4: ZFS DeduplicationExercise Z.5: ZFS SnapshotsExercise Z.6: ZFS Clones

Exercise Z.1: ZFS PoolsTask: You have several disks to use for your new file system. Create a new disk pool and a file system ontop of it.

Lab: We will check the status of disk pools, create our own pool and expand it.

Our Solaris 11 installation already has a ZFS pool. It's your root file system. Check this:

root@solaris:~# zpool list

NAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT

rpool 15.9G 5.64G 10.2G 35% 1.00x ONLINE ­

This is our root system ZFS pool. In Solaris 11 the root file system must be ZFS created on top of ZFSpool. What do we know about this pool?

root@solaris:~# zpool status rpool pool: rpool

state: ONLINE

scan: none requested

config:

NAME STATE READ WRITE CKSUM

rpool ONLINE 0 0 0

c3t0d0s0 ONLINE 0 0 0

errors: No known data errors

Let's now create our own ZFS pool. What do we need for that? Just several disks and one command. Wewill create several files in /dev/dsk directory; they will act as disks in our lab:

root@solaris:~# cd /dev/dsk root@solaris:~# mkfile 200m disk0..9

We'll take four disks and create a ZFS pool with RAID­Z protection:

root@solaris:~# zpool create labpool raidz disk0 disk1 disk2 disk3

Page 2: Oracle Solaris 11 ZFS Lab

12/17/12 Oracle Solaris 11 ZFS Lab

2/7file:///Users/pavelanni/Projects/SolarisLab/lab/ZFS Lab.html

That was easy, wasn't it? And fast, too! Check our ZFS pools again:

root@solaris:~# zpool list NAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT

labpool 780M 194K 780M 0% 1.00x ONLINE ­

rpool 15.9G 7.57G 8.30G 47% 1.00x ONLINE ­

By the way, the file system was also created and mounted automatically:

root@solaris:~# zfs list labpool NAME USED AVAIL REFER MOUNTPOINT

labpool 97.2K 551M 44.9K /labpool

Do you need more space? Adding disks to the existing ZFS pool is as easy as creating it:

root@solaris:~# zpool add labpool raidz disk4 disk5 disk6 disk7

Check it again:

root@solaris:~# zfs list labpool NAME USED AVAIL REFER MOUNTPOINT

labpool 97.2K 1.11G 44.9K /labpool

Note the increased file system's size. Also note there are two disk groups in this pool both protected withRAID­Z. ZFS has many options to protects your data, you can learn and experiments with them later.

Back to top

Exercise Z.2: ZFS File SystemsTask: You have to create home directories for your users; use file system quota to limit their space.

Lab: We'll create a user "joe" and set a disk quota for him.

Creating a user is pretty similar to most Unix/Linux systems. What's different is what's going on behind thescenes.

root@solaris:~# useradd ­m joe root@solaris:~# passwd joe New Password: oracle1 Re­enter new Password: oracle1passwd: password successfully changed for joe

In Solaris 11 behind the scenes we create a separate ZFS file system for the user (parameter ­m) in/export/home. Check it:

root@solaris:~# zfs listNAME USED AVAIL REFER MOUNTPOINT

labpool 97.2K 1.11G 44.9K /labpool

rpool 7.65G 7.97G 39K /rpool

rpool/ROOT 5.59G 7.97G 31K legacy

rpool/ROOT/solaris 5.59G 7.97G 5.17G /

Page 3: Oracle Solaris 11 ZFS Lab

12/17/12 Oracle Solaris 11 ZFS Lab

3/7file:///Users/pavelanni/Projects/SolarisLab/lab/ZFS Lab.html

rpool/ROOT/solaris/var 330M 7.97G 183M /var

rpool/dump 1.03G 8.01G 1.00G ­

rpool/export 1.48M 7.97G 32K /export

rpool/export/home 1.44M 7.97G 33K /export/home

rpool/export/home/joe 686K 7.97G 686K /export/home/joe

rpool/export/home/lab 760K 7.97G 760K /export/home/lab

rpool/swap 1.03G 8.01G 1.00G ­

What does it mean for us, system administrators? That means we can use all kinds of ZFS features(compression, deduplication, encryption) on a per­user basis. We can create snapshots and performrollbacks on a per­user basis. More about that later. Now we'll set a disk quota for joe's home directory.

root@solaris:~# zfs set quota=200m rpool/export/home/joe

Now change user to "joe" and check how much space you can use:

root@solaris:# su ­ joe joe@solaris$ mkfile 110m file1 joe@solaris$ mkfile 110m file2

First file was created OK, but with the second one we've got an error: "Disk quota exceeded".

Change the quota for joe in the other window:

root@solaris:~# zfs set quota=300m rpool/export/home/joe

Then change back to the joe's window and try again:

joe@solaris$ /usr/sbin/mkfile 110m file2

Success! As you can see, it's pretty easy to create and manage ZFS filesystems. Remember, by defaultSolaris 11 creates a separate ZFS file system for each user.

Back to top

Exercise Z.3: ZFS CompressionTask: You are becoming low on your disk space. Now you know how to add more disks to your pool andexpand your file system. What other ZFS features can help you to solve this problem?

Lab: In our lab we will compress our Solaris manuals directory and see if we are able to use it after that.Create a separate filesystem for this on our 'labpool' ZFS pool:

root@solaris:~# zfs create labpool/zman root@solaris:~# zfs list | grep zman labpool/zman 31K 7.78G 31K /labpool/zman

Set compression to "gzip" (there are options to gzip and other algorithms too­­check the manual). You cando that also while creating the filesystem.

root@solaris:~# zfs set compression=gzip labpool/zman

Page 4: Oracle Solaris 11 ZFS Lab

12/17/12 Oracle Solaris 11 ZFS Lab

4/7file:///Users/pavelanni/Projects/SolarisLab/lab/ZFS Lab.html

Copy the first part of Solaris manuals there (it will take some time, be patient):

root@solaris:~# cp ­rp /usr/share/man/man1 /labpool/zman/

Compare the sizes:

root@solaris:~# du ­sh /usr/share/man /labpool/zman 15.2M /usr/share/man

6.8M /labpool/zman

We just have saved about 55% of disk space. Not bad! Check if you are able to use the manuals aftercompression:

root@solaris:~# export MANPATH=/labpool/zman ; man ls

Back to top

Exercise Z.4: ZFS DeduplicationTask: Users tend to keep a lot of similar files in their archives. Is it possible to save space by deduplication?

Lab: We will create a ZFS file system with deduplication turned on and see if it helps.

Let's model the following situation: we have a file system which is used as an archive. We'll create separatefile systems for each user and imagine that they store similar files there.

We will use the ZFS pool called labpool that we have created in the first exercise.

Create a file system with deduplication and compression:

root@solaris:~# zfs create ­o dedup=on ­o compression=gzip labpool/archive

Create users' file systems (we'll call them a, b, c, d for simplicity):

root@solaris:~# zfs create labpool/archive/aroot@solaris:~# zfs create labpool/archive/broot@solaris:~# zfs create labpool/archive/croot@solaris:~# zfs create labpool/archive/d

Check their "dedup" parameter:

root@solaris:~# zfs get dedup labpool/archive/aNAME PROPERTY VALUE SOURCE

labpool/archive/a dedup on inherited from labpool/archive

Children file systems inherit parameters from their parents.

Create an archive from /usr/share/man/man1, for example.

root@solaris:~# tar czf /tmp/man.tar.gz /usr/share/man

And copy it four times to the file systems we've just created. Don't forget to check deduplication rate after

Page 5: Oracle Solaris 11 ZFS Lab

12/17/12 Oracle Solaris 11 ZFS Lab

5/7file:///Users/pavelanni/Projects/SolarisLab/lab/ZFS Lab.html

each copy.

root@solaris:~# cd /labpool/archiveroot@solaris:/labpool/archive# ls ­lh /tmp/man.tar.gz ­rw­r­­r­­ 1 root root 3.1M Dec 13 17:03 /tmp/man.tar.gz

root@solaris:/labpool/archive# zpool list labpoolNAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT

labpool 1.52G 1.05M 1.52G 0% 1.00x ONLINE ­

root@solaris:/labpool/archive# cp /tmp/man.tar.gz a/root@solaris:/labpool/archive# zpool list labpoolNAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT

labpool 1.52G 40.5M 1.48G 2% 1.00x ONLINE ­

root@solaris:/labpool/archive# cp /tmp/man.tar.gz b/root@solaris:/labpool/archive# zpool list labpoolNAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT

labpool 1.52G 40.7M 1.48G 2% 2.00x ONLINE ­

root@solaris:/labpool/archive# cp /tmp/man.tar.gz c/root@solaris:/labpool/archive# zpool list labpoolNAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT

labpool 1.52G 41.5M 1.48G 2% 3.00x ONLINE ­

root@solaris:/labpool/archive# cp /tmp/man.tar.gz d/root@solaris:/labpool/archive# zpool list labpoolNAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT

labpool 1.52G 41.2M 1.48G 2% 4.00x ONLINE ­

It might take a couple of seconds for ZFS to commit those changes and report the correct dedup ratio. Justrepeat the command if you don't see the results listed above.

Remember, we set compression to "on" as well when we created the file system? Check the compressionratio:

root@solaris:/labpool/archive# zfs get compressratio labpool/archiveNAME PROPERTY VALUE SOURCE

labpool/archive compressratio 1.01x ­

The reason is simple: we placed in the file system files that are compressed already. Sometimescompression can save you some space, sometimes deduplication can help.

Back to top

Exercise Z.5: ZFS SnapshotsTask: A user has accidentally deleted her file. How to restore it without getting to the tape backup?

Lab: Create a snpashot of our archive filesystem:

root@solaris:~# zfs snapshot ­r labpool/archive@snap1

Note the '­r' parameter telling ZFS that we want to snapshot all dependent filesystems as well. Check yourwork:

Page 6: Oracle Solaris 11 ZFS Lab

12/17/12 Oracle Solaris 11 ZFS Lab

6/7file:///Users/pavelanni/Projects/SolarisLab/lab/ZFS Lab.html

root@solaris:~# zfs list ­r ­t all labpoolNAME USED AVAIL REFER MOUNTPOINT

labpool 18.5M 1.10G 47.9K /labpool

labpool/archive 12.7M 1.10G 52.4K /labpool/archive

labpool/archive@snap1 0 ­ 52.4K ­

labpool/archive/a 3.17M 1.10G 3.17M /labpool/archive/a

labpool/archive/a@snap1 0 ­ 3.17M ­

labpool/archive/b 3.17M 1.10G 3.17M /labpool/archive/b

labpool/archive/b@snap1 0 ­ 3.17M ­

labpool/archive/c 3.17M 1.10G 3.17M /labpool/archive/c

labpool/archive/c@snap1 0 ­ 3.17M ­

labpool/archive/d 3.17M 1.10G 3.17M /labpool/archive/d

labpool/archive/d@snap1 0 ­ 3.17M ­

labpool/zman 5.41M 1.10G 5.41M /labpool/zman

Imagine user 'a' had deleted her archive stored in /labpool/archive/a.

root@solaris:~# rm /labpool/archive/a/*

And she comes to you asking for help. "Can you restore my archive before tomorrow?", she asks. Ofcourse, you can! In a matter of seconds, not hours, her archive files will be back! Just rollback thesnapshot!

root@solaris:~# zfs rollback labpool/archive/a@snap1

You may ask "How often should I make snapshots? Do snapshots take a lot of space? The answer is here:

root@solaris:~# zfs list ­r ­t all labpool NAME USED AVAIL REFER MOUNTPOINT

labpool 18.5M 1.10G 47.9K /labpool

labpool/archive 12.7M 1.10G 52.4K /labpool/archive

labpool/archive@snap1 0 ­ 52.4K ­

labpool/archive/a 3.17M 1.10G 3.17M /labpool/archive/a

labpool/archive/b 3.17M 1.10G 3.17M /labpool/archive/b

labpool/archive/c 3.17M 1.10G 3.17M /labpool/archive/c

labpool/archive/d 3.17M 1.10G 3.17M /labpool/archive/d

labpool/zman 5.41M 1.10G 5.41M /labpool/zman

The snapshot uses 0 bytes because we have not changed anything in your home directory. When youmake changes to your filesystem, it will take more space. Try to change something in the /labpool/archivedirectory and check the sizes again. Learn more about how snapshots work from our OTN technicalpresentations and articles.

Food for thought: How can snapshots be used in the real life environment? Backup is the first idea thatcomes to mind. What else?

Exercise Z.6: ZFS ClonesTask: We need to create a copy of our transactional data to do some analysis and modifications. In otherwords, we need a writeable snapshot.

Page 7: Oracle Solaris 11 ZFS Lab

12/17/12 Oracle Solaris 11 ZFS Lab

7/7file:///Users/pavelanni/Projects/SolarisLab/lab/ZFS Lab.html

Lab: In this lab we will use ZFS cloning feature. Clones are similar to snapshots, but you can modify them.Similarly to snapshots, it takes seconds to create them and they take almost no space until you startchanging your files.

Clones can't be created from a live filesystem. To create a clone we have to have a snapshot first. In thislab we can use a snapshot '@snap1' we have just created.

root@solaris:~# zfs clone labpool/archive/a@snap1 labpool/a_workroot@solaris:~# zfs list ­r ­t all labpoolNAME USED AVAIL REFER MOUNTPOINT

labpool 18.6M 1.10G 49.4K /labpool

labpool/a_work 26.9K 1.10G 3.17M /labpool/a_work

labpool/archive 12.8M 1.10G 52.4K /labpool/archive

labpool/archive@snap1 0 ­ 52.4K ­

labpool/archive/a 3.20M 1.10G 3.17M /labpool/archive/a

labpool/archive/a@snap1 26.9K ­ 3.17M ­

labpool/archive/b 3.17M 1.10G 3.17M /labpool/archive/b

labpool/archive/b@snap1 0 ­ 3.17M ­

labpool/archive/c 3.17M 1.10G 3.17M /labpool/archive/c

labpool/archive/c@snap1 0 ­ 3.17M ­

labpool/archive/d 3.17M 1.10G 3.17M /labpool/archive/d

labpool/archive/d@snap1 0 ­ 3.17M ­

labpool/zman 5.41M 1.10G 5.41M /labpool/zman

Check if the archive is in place in the clone filesystem:

root@solaris:~# cd /labpool/a_workroot@solaris:/labpool/a_work# lsman.tar.gz

Unpack the archive and then check the original directory.

root@solaris:/labpool/a_work# tar xzvf man.tar.gz ....................

tar: Removing leading '/' from '/usr/share/man/man1/tracker­services.1'

x usr/share/man/man1/tracker­services.1, 1938 bytes, 4 tape blocks

root@solaris:/labpool/a_work# ls ­l total 6413

­rw­r­­r­­ 1 root root 3257177 Dec 13 17:05 man.tar.gz

drwxr­xr­x 3 root root 3 Dec 13 18:04 usr

root@solaris:/labpool/a_work# cd ../archive/a

root@solaris:/labpool/archive/a# ls ­l

total 6409

­rw­r­­r­­ 1 root root 3257177 Dec 13 17:05 man.tar.gz

This powerful cloning feature can be used for your regular data. Oracle Solaris uses it internally to createboot environments and zone clones. They will be described in the following lab exercises.

Back to top