Gice

Technology and General Blog

Unlike many other filesystems, ZFS mounts the pools and filesystems that you create automatically.

If you create a ZFS pool pool1, it will automatically mount it in the /pool1 directory of your computer.

If you create a ZFS filesystem documents on pool pool1, it will automatically mount it in the /pool1/documents directory of your computer.

In the same way, if you create another ZFS filesystem downloads on pool pool1, it will automatically mount it in the /pool1/downloads directory of your computer. You get the idea.

In this article, I am going to show you how to mount ZFS pools and filesystems in other directories of your computer. So, let’s get started.

Table of Contents

  1. Filesystem Properties for Configuring ZFS Mounting Behavior
  2. Changing Mount Path of ZFS Pools
  3. Changing Mount Path of ZFS Filesystems
  4. Disable Mounting for ZFS Pools
  5. Conclusion
  6. References

Filesystem Properties for Configuring ZFS Mounting Behavior

The mounted property of the ZFS filesystem is used to find out whether a ZFS pool/filesystem is mounted on your computer or not. If a ZFS pool/filesystem is mounted on your computer, the mounted property will be set to yes. If a ZFS pool/filesystem is not mounted on your computer, the mounted property will be set to no.

NOTE: mounted is a read-only property, and you can’t change that from one value to the other. ZFS will automatically change the value of the mounted property depending on whether a ZFS pool/filesystem is mounted or not.

The canmount and mountpoint properties of the ZFS filesystem are used to configure the mounting behavior of the ZFS pools and filesystems.

ZFS uses the canmount property of a pool/filesystem to determine whether the pool/filesystem can be mounted or not.

ZFS uses the mountpoint property of a pool/filesystem to determine the directory path where it will mount the pool/filesystem.

The canmount property can have the values: on, off, or noauto. The default is on for new ZFS pools and filesystems. If this property is set on a ZFS pool, it is not inherited by the filesystems created on that pool.

  • canmount=on — The ZFS pools and filesystems that have canmount set to on can be mounted automatically on the directory path set by the mountpoint property.
  • canmount=noauto — The ZFS pool/filesystem that has canmount set to noauto can be mounted on the directory path set by the mountpoint property of the pool/filesystem. However, ZFS won’t do it automatically. You will have to do it manually instead.
  • canmount=off — The ZFS pools and filesystems that have canmount set to off can’t be mounted.

When you create a ZFS pool pool1, the mountpoint of the pool pool1 is set to /pool1, and canmount is set to on. When you create a new ZFS filesystem documents on the pool pool1, the mountpoint for the filesystem is set to /pool1/documents, and its canmount is set to on by default. In the same way, if you create another ZFS filesystem downloads on the pool pool1, the mountpoint for the filesystem is set to /pool1/downloads, and its canmount is set to on by default.

You should know the basic theory to understand how the ZFS pools/filesystems mounting process works. In the next sections, I will show you several practical examples of what I have discussed in this section. Let’s move on.

Changing Mount Path of ZFS Pools

For the demonstration, I will create a new ZFS pool using the vda and vdb storage devices, as seen in the screenshot below:

To create a new ZFS pool pool1 using the vda and vdb storage devices in mirror configuration, run the following command:

$ sudo zpool create -f pool1 mirror vda vdb

A new ZFS pool pool1 should be created. The mountpoint should be set to /pool1, as seen in the screenshot below:

As you can see, the ZFS pool pool1 is mounted (mounted is yes). It can be mounted (canmount is on), and its mount directory path is /pool1 (mountpoint is /pool1).

$ sudo zfs get mounted,canmount,mountpoint pool1

You can verify that the ZFS pool pool1 is mounted on the /pool1 directory of your computer from the output of the df command:

To change the mount path of the ZFS pool pool1 to /mypool, set the mountpoint property of the ZFS pool pool1 as follows:

$ sudo zfs set mountpoint=/mypool pool1

As you can see, the mountpoint property of the ZFS pool pool1 is set to /mypool:

$ sudo zfs get mountpoint pool1

The mount path of the ZFS pool pool1 should be changed to /mypool, as seen from the output of the df command below:

Changing Mount Path of ZFS Filesystems

In this section, I am going to show you how to change the mount path of ZFS filesystems.

Create new ZFS filesystem documents on the ZFS pool pool1 with the following command:

$ sudo zfs create pool1/documents

A new ZFS filesystem documents should be created on the ZFS pool pool1, and its mountpoint should be set to /mypool/documents, as you’ve changed the pool pool1’s mountpoint to /mypool earlier:

As you can see, the ZFS filesystem documents are mounted (mounted is yes). It can be mounted (canmount is on), and its mount directory path is /mypool/documents (mountpoint is /mypool/documents):

$ sudo zfs get mounted,canmount,mountpoint pool1/documents

The ZFS filesystem documents should be mounted on the /mypool/documents directory of your computer, as seen from the output of the df command below:

To change the mount path of the ZFS filesystem documents to /mydocs, set the mountpoint property of the ZFS filesystem documents as follows:

$ sudo zfs set mountpoint=/mydocs pool1/documents

As you can see, the mountpoint property of the ZFS filesystem documents is set to /mydocs:

$ sudo zfs get mountpoint pool1/documents

The mount path of the ZFS filesystem documents should be changed to /mydocs, as seen from the output of the df command below:

Disable Mounting for ZFS Pools

At times, you may only want to mount the ZFS filesystems of a ZFS pool but not the pool itself. In that case, you can disable mounting for the said ZFS pool and only set mount paths for the filesystems on that ZFS pool.

I will create a new ZFS pool using the storage devices vdc and vdd to demonstrate it:

To create a new ZFS pool pool2 using the vdc and vdd storage devices in mirror configuration, run the following command:

$ sudo zpool create -f pool2 mirror vdc vdd

A new ZFS pool pool2 should be created and its mountpoint should be set to /pool2.

As you can see, the ZFS pool pool2 is mounted (mounted is yes). It can be mounted (canmount is on), and its mount directory path is /pool2 (mountpoint is /pool2):

$ sudo zfs get mounted,canmount,mountpoint pool2

The ZFS pool pool2 should be mounted on the /pool2 directory of your computer, as seen from the output of the df command:

Since you don’t want ZFS to mount the ZFS pool pool2, set the canmount property of the ZFS pool pool2 to off as follows:

$ sudo zfs set canmount=off pool2

As you can see, even though the ZFS pool pool2 is not mounted (mounted is no) and mounting is disabled (canmount is off) for the pool, the mountpoint property is set to /pool2. The ZFS filesystems you create on the pool pool2 will use it to set its mountpoint property. It will not inherit the mounted and canmount property from the pool pool2:

$ sudo zfs get mounted,canmount,mountpoint pool2

As you can see, the ZFS pool pool2 is not mounted anymore:

Now, create a new filesystem downloads on the ZFS pool pool2 with the following command:

$ sudo zfs create pool2/downloads

As you can see, the ZFS filesystem downloads set its mountpoint property using the mountpoint property of the ZFS pool pool2 only. So, its mountpoint is set to /pool2/downloads by default:

$ sudo zfs get mounted,canmount,mountpoint pool2/downloads

The ZFS filesystem downloads should also be mounted on the /pool2/downloads directory of your computer, as seen from the output of the df command:

If you don’t want the filesystems, you create on the ZFS pool pool2 to use the mountpoint property. You can set the mountpoint property of the ZFS pool pool2 to none. This way, the mountpoint property of the ZFS filesystems on the pool pool2 will also be set to none and will be unmounted by default. You will have to set a mountpoint value for the filesystems you want to mount manually.

You can set the mountpoint property of the ZFS pool pool2 to none as follows:

$ sudo zfs set mountpoint=none pool2

The mountpoint property of the ZFS pool pool2 should be set to none, as seen in the screenshot below:

$ sudo zfs get mounted,canmount,mountpoint pool2

The mountpoint property of the ZFS filesystem downloads should also be set to none as seen in the screenshot below:

$ sudo zfs get mounted,canmount,mountpoint pool2/downloads

Create a new ZFS filesystem videos on the pool pool2 as follows:

$ sudo zfs create pool2/videos

The mountpoint of the newly created filesystem videos should also be set to none, as seen in the screenshot below:

$ sudo zfs get mounted,canmount,mountpoint pool2/videos

Neither the downloads nor the videos filesystem of the ZFS pool pool2 should be mounted on your computer, as seen from the output of the df command:

To mount the downloads filesystem of the ZFS pool pool2 to /mydownloads directory of your computer, set the mountpoint property of the filesystem as follows:

$ sudo zfs set mountpoint=/mydownloads pool2/downloads

In the same manner, to mount the videos filesystem of the ZFS pool pool2 to /myvideos directory of your computer, set the mountpoint property of the filesystem as follows:

$ sudo zfs set mountpoint=/myvideos pool2/videos

The mountpoint property of the downloads and videos filesystem of the ZFS pool pool2 should be set to /mydownloads and /myvideos, respectively as seen in the screenshot below:

The downloads and videos filesystems of the ZFS pool pool2 should be mounted on the /mydownloads and /myvideos directory of your computer respectively, as shown from the output of the df command:

Conclusion

This article has shown you the effects of setting different values for the canmount, mounted, and mountpoint properties on ZFS pools and filesystems. I have also shown you how to mount ZFS pools and filesystems in different directories than their default ones. In addition, I presented how to disable mounting for the ZFS pools and manually mount filesystems from the mount-disabled ZFS pools.

References

[1] Ubuntu Manpage: zfs — configures ZFS file systems

Leave a Reply

Your email address will not be published. Required fields are marked *