3
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.

Linuxで外部ストレージの自動マウント@2018

Last updated at Posted at 2016-12-20

ネットワークドライブのマウント方法


まえがき

最新版を用意しましたので、よければリンク先ものぞいてみてください。

Linuxでログインしたときに、いちいちマウントコマンドを打つのも面倒なので、
指定のユーザーがログインした時に自動でマウントされるようにする。


マウント方法

  • マウント自体は以下のシェルスクリプトを実行
    • シェルスクリプトである必要はない
mount_foo.sh
# !/bin/sh
sudo mount -o username=who,password=hogehoge //192.168.xxx.xxx/home /mnt/foo

自動化

  • 上記のシェルスクリプトがログイン時に有効になるように、以下のディレクトリに格納
    • /etc/profile.d/
  • 上記に置いただけではダメだったので、.bash_profileに以下を記載
    • sh /etc/profile.d/mount_foo.sh
    • shファイルの場所はどこでも大丈夫です

アンマウント方法

  • umount /mnt/foo

シンボリックリンク

最後にせっかくなので、ホームディレクトリにシンボリックを作るともっと便利になる。
(/mntにマウントしなければいいだけなんですが…)

  • 作成
    • ln -s /mnt/foo foobar
    • シンボリックリンクの名前の最後に「/」をつけるとエラーになる
  • 解除
    • unlink bar
    • こちらもシンボリックリンクの最後に「/」をつけるとエラーになるので注意

以上です。

ブログ始めました、よかったら遊びに来てください
https://red-full-moon.com/

3
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
3
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?