Sunday, July 26, 2009

Creating multiple ZFS file systems in a single pool

All of us have experienced the following scenario.
Developers ask for two file systems with specific sizes:
e.g.
/aaa 1GB
/bbb 5GB
Let’s assume that we only have 6GB available and we create file systems as requested.
A few days later /aaa is full and /bbb contains almost nothing. The developers ask for more space in /aaa.
Do you purchase new disk?
Do you backup, resize, and restore?

Or if you are running VXFS/VXVM do you start running convoluted commands to resize the file systems?

Let's look at what the situation would be like if we had used ZFS.

A ZFS pool is capable of housing multiple file systems… all file systems share the same underlying disk space.

• No rigid boundaries are created between file systems; the data from each file system is evenly distributed throughout the pool.
• By default, any file system is allowed to use any (or all) of the free space in the pool.
• If data is deleted from a file system, the space is returned to the pool as free space.

So in the example above, if we had created a 6GB pool housing both /aaa and /bbb, either file system could potentially grow to almost 6GB.

We would not get a report of a full file system until the entire pool is full. The pool won't fill up until the total data written to both file systems is roughly equal to the size of the pool.

Thus there would be nothing stopping the developers from placing 4GB in /aaa and 1GB in /bbb… this would leave approximately 1GB of space free for either file system to consume.

The behaviour can be adjusted with "reservations" and "quotas"… but lets leave that for another day.

So let's see how to create a ZFS pool with multiple file systems. Normally we would create the pool on one or more real disks, but for test purposes we can use a 64GB file . Try this on an unused server:

Create a 64MB temp file
# mkfile 64M /tmp/file1

Create a ZFS pool called "ttt" on top of the temp file.
# zpool create ttt /tmp/file1

Run df to make sure /ttt exists

# df -k | egrep 'ttt|Filesystem'
Filesystem 1024-blocks Used Available Capacity Mounted on
ttt 28160 24 28075 1% /ttt

Now create two new file systems within pool ttt

# zfs create ttt/xxx
# zfs create ttt/yyy

Now view all three file systems:

# df -k | egrep 'ttt|Filesystem'

Filesystem 1024-blocks Used Available Capacity Mounted on
ttt 28160 27 27971 1% /ttt
ttt/xxx 28160 24 27971 1% /ttt/xxx
ttt/yyy 28160 24 27971 1% /ttt/yyy

Note that ZFS file systems within a pool must be created in a hierarchical structure. The ZFS pool (in this case "ttt") is always the root of the pool.

The mount points by default will share the same name as the file systems (prefixed with a "/").

But nobody wants to use /ttt/xxx or /ttt/yyy as mount points, so lets change the mount points.

# zfs set mountpoint=/aaa ttt/xxx
# zfs set mountpoint=/hello/world ttt/yyy
# df -k | egrep 'ttt|Filesystem'

Filesystem 1024-blocks Used Available Capacity Mounted on
ttt 28160 24 27962 1% /ttt
ttt/xxx 28160 24 27962 1% /aaa
ttt/yyy 28160 24 27962 1% /hello/world

Note that we did not have to create mount points or set anything up in /etc/vfstab. ZFS takes care or everything for us and life is great.

And to clean up… the commands are the same as before… but you may have to manually remove some of the mount points.

# zpool destroy ttt
# rm /tmp/file1
# rmdir /aaa
# rmdir /hello/world
# rmdir /hello

Readers who read this page, also read:




Bookmark and Share My Zimbio http://www.wikio.com

0 comments: