0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Linux】起動時にサーバ上のファイルを自動マウントする

Last updated at Posted at 2024-05-28

普通にfstabに記載すればいいだろうと思っていたらマウント出来なかったのでautofsを使用しました。OSはUbuntu22.04です。

autofsとは

NFS マウントはアクセスの頻度に関わらずマウントされるため常にリソースが消費される。それに対しautofsではアクセスする際に自動的にマウント、アクセスがなければアンマウントしてくれるためリソースの消費が少ない。

設定方法

まずはautofsをインストールします。

$ sudo apt update
$ sudo apt install autofs

続いて好きな場所にマウントポイントを作成します。このフォルダを開いたらサーバに繋がるように設定していきます。

$ mkdir /マウントポインㇳのパス

マスタを開いて2行目の内容を一番下に追記します。nanoエディタはctrt+oで保存、ctr+xで閉じる事ができます。

$ sudo nano /etc/auto.master
-/    /etc/auto.files #これを追記

/etc/auto.filesに設定を書き込んで行きます。

# uid ,gidを確認
$ id 

# auto.filesを開く
$ sudo nano /etc/auto.files 

#auto.filesに書き込む内容
/マウントポイントのパス     -fstype=cifs,uid=1000,gid=1000,username=ユーザーネーム,password=パスワード  ://サーバのパス 

# サービス再起動
$ sudo systemctl restart autofs.service 

/data/Files:マウントポイントのパス
-fstype:ファイルのタイプ。cifsでいい
uid ,gid:確認したid
username,password:サーバにログインする時のもの
://以降:マウントするサーバのパス

正しく書き込めていればこれでマウント出来ているはずです。

デフォルトで「5分間アクセスがなかったら自動的にマウントを解除する」という設定が入ってるんですが、この設定が効いているのかどうか分からないので確認方法分かる方いたら教えてください。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?