2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FreeNAS 9.3 jail で bash のプロセス置換を使う

Last updated at Posted at 2016-04-23

問題

FreeNAS の jail では、bash のプロセス置換の機能が使えません。

# cat <(find /root -type f)
cat: /dev/fd/63: No such file or directory

これはインストール時の最後のメッセージが関係します。

Message from bash-4.3.42_1:                                                     
======================================================================          
                                                                                
bash requires fdescfs(5) mounted on /dev/fd                                     
                                                                                
If you have not done it yet, please do the following:                           
                                                                                
        mount -t fdescfs fdesc /dev/fd                                          
                                                                                
To make it permanent, you need the following lines in /etc/fstab:               
                                                                                
        fdesc   /dev/fd         fdescfs         rw      0       0               
                                                                                
======================================================================     

こいつが曲者なんですね。jail ではこの mount を実行するとエラーになります。

# mount -t fdescfs fdesc /dev/fd
mount: fdesc: Operation not permitted

対応

この mount の実行に関して参考にしたページ:
jail環境でJenkinsを動かす

jail起動と終了の際に、自動的に実行する事になります。その手段は偶然見つけました。FreeNASのjailの構造を御存知の方なら常識なのだと思いますが。

ホストの /mnt/tank/jails にjailが配置されていますが、ここに .<jail名>.meta というディレクトリがあります。この中に色々なスクリプトがありました。

# pwd
/mnt/tank/jails/.bash.meta
# ls -l
total 15
-rw-r--r--  1 root  wheel   0 Apr 24 00:03 autostart
-rw-r--r--  1 root  wheel   0 Apr 24 00:03 fstab
-rw-r--r--  1 root  wheel   5 Apr 24 00:03 host
-rw-r--r--  1 root  wheel   3 Apr 24 00:03 id
-rw-r--r--  1 root  wheel   5 Apr 24 00:03 ipv4
-rw-r--r--  1 root  wheel  23 Apr 24 00:03 jail-flags
-r-xr-xr-x  1 root  wheel  61 Apr 24 00:03 jail-post-delete
-r-xr-xr-x  1 root  wheel  60 Apr 24 00:03 jail-post-start
-r-xr-xr-x  1 root  wheel  59 Apr 24 00:03 jail-post-stop
-r-xr-xr-x  1 root  wheel  60 Apr 24 00:03 jail-pre-delete
-r-xr-xr-x  1 root  wheel  59 Apr 24 00:03 jail-pre-start
-r-xr-xr-x  1 root  wheel  58 Apr 24 00:03 jail-pre-stop
-rw-r--r--  1 root  wheel   9 Apr 24 00:03 jailtype
-rw-r--r--  1 root  wheel  18 Apr 24 00:03 mac
-rw-r--r--  1 root  wheel   0 Apr 24 00:03 vnet

これらの中身を少し調べて、最終的にうまくいった結果がこちらです。

# diff -U0 jail-post-start.org jail-post-start
--- jail-post-start.org 2016-04-23 12:04:51.858708196 +0900
+++ jail-post-start     2016-04-23 23:54:27.123699907 +0900
@@ -4,0 +5,3 @@
+# 2016.04.23. added by Katz
+mount -t fdescfs fdesc /mnt/tank/jails/${JAILNAME}/dev/fd
+
# diff -U0 jail-pre-stop.org jail-pre-stop
--- jail-pre-stop.org   2016-04-23 12:04:51.857695746 +0900
+++ jail-pre-stop       2016-04-23 23:56:19.192699426 +0900
@@ -5,0 +6,3 @@
+
+# 2016.04.23. added by Katz.
+umount /mnt/tank/jails/${JAILNAME}/dev/fd

今度はプロセス置換がうまくいきます。

# cat <(find /root -type f)
/root/.bash_history
/root/.profile
/root/.cshrc
/root/.k5login
/root/.lesshst
/root/.login
/root/.history

やった!:thumbsup:

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?