LoginSignup
7
4

More than 3 years have passed since last update.

ZFSのcanmountプロパティをデフォルトに戻す

Last updated at Posted at 2019-12-03

はじめに結論

zfs の canmount プロパティを、デフォルトに戻そうと inherit で指定してもエラーになる。しかし inherit-S オプションを指定すればデフォルトに戻せる。

$ zfs inherit -S ZFSファイルシステム

以下は解説である。

ZFS の canmount プロパティ

ZFS のプロパティの一つに canmount というマウントを制御するオプションがある。canmount は通常は on であるが、off にするとそのファイルシステムをマウントしない挙動となる。

次の例は FreeBSD のインストーラでルートファイルシステムを ZFS としてインストールした場合の。zroot/usr の MOUNTPOINT は /usr であるが、canmount が off となっている。

$ zfs list -o name,canmount,mountpoint -r zroot/usr 
NAME            CANMOUNT  MOUNTPOINT
zroot/usr            off  /usr
zroot/usr/home        on  /usr/home 
zroot/usr/src         on  /usr/src
$ 

この場合、zroot/usr は ファイルシステムとしては存在しマウントポイントも指定されているが、実際にはマウントされない。マウントされているかどうかは、/usr で
df を実行されるとわかりやすい。

$ df /usr
Filesystem         1K-blocks    Used    Avail Capacity  Mounted on
zroot/ROOT/default  94517338 5223747 89293590     6%    /
$

/usr の Filesystem は zroot/ROOT/default であり、またマウントポイントは / となっている。つまり zroot/usr は /usr にマウントされていない。

ところが ZFS 的に zroot/usr の 子にあたる zroot/usr/src は、次のように /usr/src にマウントされている。

$ df /usr/src
Filesystem    1K-blocks   Used    Avail Capacity  Mounted on
zroot/usr/src  89795577 498898 89296679     1%    /usr/src
$ 

このようにcanmountを off に指定すると、ファイルシステムとして存在し、子のZFSにプロパティを引き継ぐが、このファイルシステムそのものはマウントされないものとなる。

canmountプロパティの設定例

次の例は、ztest という ZFS プールを用意して、ztest/d1 と ztest/d1/d2 というファイルシステムを作成している。

$ zfs create ztest/d1
$ zfs create ztest/d1/d2
$ df
Filesystem   1K-blocks    Used    Avail Capacity  Mounted on
/dev/ada0s2a   7098396 2442064  4088464    37%    /
devfs                1       1        0   100%    /dev
ztest         18284205      23 18284182     0%    /ztest
ztest/d1      18284205      23 18284182     0%    /ztest/d1
ztest/d1/d2   18284205      23 18284182     0%    /ztest/d1/d2
$

ここで ztest/d1 の canmount を off に設定すると、ztest/d1 のマウントが解除されているのがわかる。

$ zfs canmount=off ztest/d1
$ df
Filesystem   1K-blocks    Used    Avail Capacity  Mounted on
/dev/ada0s2a   7098396 2442064  4088464    37%    /
devfs                1       1        0   100%    /dev
ztest         18284391      23 18284368     0%    /ztest
ztest/d1/d2   18284391      23 18284368     0%    /ztest/d1/d2
$

canmount プロパティの状態を確認してみる。

$ zfs  get -t filesystem -r canmount 
NAME         PROPERTY  VALUE     SOURCE
ztest        canmount  on        default
ztest/d1     canmount  off       local
ztest/d1/d2  canmount  on        default
$

ここで zroot/d1 の canmount を元の on に戻してみる。ただ canmount を on にするだけではそのファイルシステムはマウントされないので、アンマウントとマウントをやり直している。

$ zfs set canmount=on ztest/d1
$ df
Filesystem   1K-blocks    Used    Avail Capacity  Mounted on
/dev/ada0s2a   7098396 2442064  4088464    37%    /
devfs                1       1        0   100%    /dev
ztest         18284391      23 18284368     0%    /ztest
ztest/d1/d2   18284391      23 18284368     0%    /ztest/d1/d2
$ zfs unmount -a
$ zfs mount -a
$ df
Filesystem   1K-blocks    Used    Avail Capacity  Mounted on
/dev/ada0s2a   7098396 2442064  4088464    37%    /
devfs                1       1        0   100%    /dev
ztest         18284391      23 18284368     0%    /ztest
ztest/d1      18284391      23 18284368     0%    /ztest/d1
ztest/d1/d2   18284391      23 18284368     0%    /ztest/d1/d2
$

canmount プロパティのリセット

ここで canmount プロパティの一覧を表示してみると、SOURCE は local のままである。

$ zfs get -t filesystem -r canmount 
NAME         PROPERTY  VALUE     SOURCE
ztest        canmount  on        default
ztest/d1     canmount  on        local
ztest/d1/d2  canmount  on        default
$

多くのプロパティは inherit コマンド(親のファイルシステムの設定を引き継ぐ設定にするコマンド)を使うと、VALUE と SOURCE をデフォルトに設定できるが、canmount については inherit でデフォルトに戻そうとしても、以下のようにエラーになってしまう。

$ zfs inherit canmount ztest/d1
'canmount' property cannot be inherited
$

実際、zfs のマニュアルにも canmount プロパティは親のファイルシステムの設定を引き継ぐことはできないと記載がある。

 canmount=on | off | noauto
     If this property is set to off, the file system cannot be mounted,
     -----------> 中略 <---------
     This property is not inherited.

では一度 canmount の値を変更したら、SOURCE をdefaultに戻す術は無いのか?

もちろん手段はちゃんと用意されていて、inherit に -S オプションを指定するだけである。

$ zfs inherit -S canmount ztest/d1
$ zfs get canmount ztest/d1
NAME      PROPERTY  VALUE     SOURCE
ztest/d1  canmount  on        default
$

この通りVALUEは on で SOURDE は default に戻った。

マニュアルを読むと、-Sオプションは zfs receive で受信したプロパティで存在するものを、元の状態に戻すオプションとある。

7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4