マウント

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Mount and the translation is 100% complete.
Other languages:

マウント するとは、一般にコンピュータの現在アクセス可能な ファイルシステム に、追加のファイルシステムをつなぎ合わせることを指します。 [1]

インストール

mount コマンドは util-linux パッケージに含まれています。Gentoo Linux では、 sys-apps/util-linux パッケージは system 集合の一部であり、デフォルトですべての Gentoo システムにインストールされています。

もしなにか奇妙で普通ではない理由でパッケージが見当たらないのであれば、単純に emerge コマンドを実行すれば再インストールできます (必ず --oneshot オプションを使用してください)。これは USE フラグ を変更した場合にも使用できます:

root # emerge --ask --oneshot sys-apps/util-linux

使い方

root # mount --help
Usage:
 mount [-lhV]
 mount -a [options]
 mount [options] [--source] <source> | [--target] <directory>
 mount [options] <source> <directory>
 mount <operation> <mountpoint> [<target>]
 
Mount a filesystem.
 
Options:
 -a, --all               mount all filesystems mentioned in fstab
 -c, --no-canonicalize   don't canonicalize paths
 -f, --fake              dry run; skip the mount(2) syscall
 -F, --fork              fork off for each device (use with -a)
 -T, --fstab <path>      alternative file to /etc/fstab
 -i, --internal-only     don't call the mount.<type> helpers
 -l, --show-labels       show also filesystem labels
 -m, --mkdir[=<mode>]    alias to '-o X-mount.mkdir[=<mode>]'
 -n, --no-mtab           don't write to /etc/mtab
     --options-mode <mode>
                         what to do with options loaded from fstab
     --options-source <source>
                         mount options source
     --options-source-force
                         force use of options from fstab/mtab
 -o, --options <list>    comma-separated list of mount options
 -O, --test-opts <list>  limit the set of filesystems (use with -a)
 -r, --read-only         mount the filesystem read-only (same as -o ro)
 -t, --types <list>      limit the set of filesystem types
     --source <src>      explicitly specifies source (path, label, uuid)
     --target <target>   explicitly specifies mountpoint
     --target-prefix <path>
                         specifies path used for all mountpoints
 -v, --verbose           say what is being done
 -w, --rw, --read-write  mount the filesystem read-write (default)
 -N, --namespace <ns>    perform mount in another namespace
 
 -h, --help              display this help
 -V, --version           display version
 
Source:
 -L, --label <label>     synonym for LABEL=<label>
 -U, --uuid <uuid>       synonym for UUID=<uuid>
 LABEL=<label>           specifies device by filesystem label
 UUID=<uuid>             specifies device by filesystem UUID
 PARTLABEL=<label>       specifies device by partition label
 PARTUUID=<uuid>         specifies device by partition UUID
 ID=<id>                 specifies device by udev hardware ID
 <device>                specifies device by path
 <directory>             mountpoint for bind mounts (see --bind/rbind)
 <file>                  regular file for loopdev setup
 
Operations:
 -B, --bind              mount a subtree somewhere else (same as -o bind)
 -M, --move              move a subtree to some other place
 -R, --rbind             mount a subtree and all submounts somewhere else
 --make-shared           mark a subtree as shared
 --make-slave            mark a subtree as slave
 --make-private          mark a subtree as private
 --make-unbindable       mark a subtree as unbindable
 --make-rshared          recursively mark a whole subtree as shared
 --make-rslave           recursively mark a whole subtree as slave
 --make-rprivate         recursively mark a whole subtree as private
 --make-runbindable      recursively mark a whole subtree as unbindable
 
For more details see mount(8).

マウント状況を一覧表示する

マウントされているファイルシステムを表示するには、mountコマンドを引数やオプションなしで実行します:

root # mount
ヒント
sys-apps/util-linux が提供する findmnt を使用して、マウントされているファイルシステムをより視覚的に表示する方法も存在します。さらなる詳細については man 8 findmnt を確認してください。

ファイルシステムをマウントする

ファイルシステムをマウントするためには、 デバイスファイル 、 UUID またはラベル 、あるいは他の、パーティションやデータソースの場所を示す手段、そしてマウントポイントが必要です。システムに関係しないファイルシステムは通常 /mnt ディレクトリにマウントされます。ファイルシステムをマウントするための適切な文法は次のとおりです:

root # mount <デバイス> <ディレクトリ>

詳細については man 8 mount を参照してください。

/media ディレクトリは通常 USB ドライブや SD カードのようなリムーバブルデバイスをマウントするのに用いられます。USB ドライブがどのデバイスとして表示されているのかを確認した後、以下のようなコマンドを用いて、 /media の中にある、新しく作られた usb フォルダに USB ドライブの内容をマウントすることができます:

root # mkdir /media/usb
root # mount /dev/sdb1 /media/usb
ヒント
fstab に設定されているマウントは、マウントポイントかデバイス名を与えるだけでマウントすることができます。例えば:
root # mount /dev/sdb1

ファイルシステムをアンマウントする

ファイルシステムをアンマウントするときには、デバイスファイルかマウントポイントを指定することができます。

root # umount <デバイス>
root # umount <ディレクトリ>

使い方の情報:

user $ umount --help
Usage:
 umount [-hV]
 umount -a [options]
 umount [options] <source> | <directory>
 
Unmount filesystems.
 
Options:
 -a, --all               unmount all filesystems
 -A, --all-targets       unmount all mountpoints for the given device in the
                           current namespace
 -c, --no-canonicalize   don't canonicalize paths
 -d, --detach-loop       if mounted loop device, also free this loop device
     --fake              dry run; skip the umount(2) syscall
 -f, --force             force unmount (in case of an unreachable NFS system)
 -i, --internal-only     don't call the umount.<type> helpers
 -n, --no-mtab           don't write to /etc/mtab
 -l, --lazy              detach the filesystem now, clean up things later
 -O, --test-opts <list>  limit the set of filesystems (use with -a)
 -R, --recursive         recursively unmount a target with all its children
 -r, --read-only         in case unmounting fails, try to remount read-only
 -t, --types <list>      limit the set of filesystem types
 -v, --verbose           say what is being done
 -q, --quiet             suppress 'not mounted' error messages
 -N, --namespace <ns>    perform umount in another namespace
 
 -h, --help              display this help
 -V, --version           display version
 
For more details see umount(8).

マウントオプション

時々、ファイルシステムをマウントする時に特別なオプションを必要とすることがあります:

root # mount [オプション] <デバイス> <ディレクトリ>
コマンドオプション:
オプション 説明
-f マウントのシミュレーションを行います
-t ファイルシステムを指定します (例: ext4 )
-o オプション1,オプション2,... マウントオプションを指定します (下記参照)
-a /etc/fstab 内のすべてのファイルシステムをマウントします

使用されるファイルシステムは、渡されるマウントオプションをサポートしていなければなりません。多くのオプションは共通ですが、 いくつかは ファイルシステム特有です。

メモ
mount と、各ファイルシステムの両方の man ページ (例えば、 ext4(5) や xfs(5) ) を確認することを常におすすめします。
マウントオプション:
オプション 説明
defaults デフォルトのマウントオプションを使用します: rw 、 suid 、 dev 、 exec 、 auto 、 nouser 、 async 。
auto ブート時に自動でファイルシステムをマウントします。
noauto ブート時に自動でファイルシステムをマウントしません。
ro ファイルシステムを読み込み専用でマウントします。
rw ファイルシステムを読み書き可能な状態でマウントします。
sw スワップ パーティションをマウントします。
atime 読み込み時に毎回 inode のアクセス時間を更新します。
relatime 入出力のパフォーマンスを向上させるために、書き込み時のみ inode のアクセス時間を更新します。
noatime 入出力のパフォーマンスを最高にするために、inode のアクセス時間を一切更新しません。
sync 書き込み後に毎回ドライブを sync (訳注: メモリ上にあるキャッシュを実際にドライブに書き出すこと) します。一部のフラッシュドライブなどでは寿命を縮めることがあります。
async 非同期的にドライブを sync します。
discard Linux における trim サポート と同等のものです。
exec バイナリの実行を許可します。
noexec バイナリの実行を許可しません。
suid SUID ビットや SGID ビットに従います。
nosuid SUID ビットや SGID ビットに従いません。
user ユーザーにファイルシステムのマウントを許可します。明示的に dev 、 exec 、または suid を設定しない限り、それぞれ nodev 、 noexec 、そして nosuid オプションが暗に含まれます。
users すべてのユーザーにファイルシステムのマウントを許可します。
nouser "root" だけにファイルシステムのマウントを許可します。

すでにマウントされているファイルシステムのマウントオプションは、 remount オプションを使用して変更することができます。例えば、 /dev/foo 上のファイルシステムを、読み書き可能としてマウントするには、以下のようにして行えます:

root # mount -o remount,rw /dev/foo /dir

ヒント

非スーパーユーザーとしてマウントする

man mount によると、スーパーユーザーだけがファイルシステムをマウント可能です。しかし、 /etc/fstab の行中に user オプションが含まれている場合、すべてのユーザーが対応するパーティション、デバイスあるいはドライブなどをマウントすることが可能になります。

リムーバブルメディアのマウント

リムーバブルメディア のページ内の関連するセクションを参照してください。

Windows ファイル共有 (CIFS) のマウント

/etc/fstab へ登録しているにもかかわらず、非ルートユーザが Windows との共有ファイルシステムをマウントしようとすると失敗するでしょう (セキュリティの理由のため)。以下の例は、Windows との共有ファイルシステムの fstab の項目です。 cifs オプションに注目してください:

ファイル /etc/fstab
[...]
//server/folder /home/larry/winmount cifs noauto,user 0 0
[...]
user $ mount /home/larry/winmount
This program is not installed setuid root -  "user" CIFS mounts not supported.

解決策として、パスワードなしでマウントするために、 /etc/sudoers に対応するエントリを書いて、 sudo mount /home/larry/winmount を使用します。

警告
/etc/sudoers ファイルを編集する前に必ず、 sudo の設定 を理解しておいてください!
ファイル /etc/sudoers
[...]
larry    ALL = NOPASSWD: /bin/mount  /home/larry/winmount/, /bin/mount  /home/larry/winmount
larry    ALL = NOPASSWD: /bin/umount /home/larry/winmount/, /bin/umount /home/larry/winmount
[...]

関連項目

参照