linux command

mount

Linux Command – mount ใช้ในการติดตั้งใช้งานอุปกรณ์ที่เชื่อมต่อ

 

คำสั่ง

1. แสดง mount list

$ mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=1964668k,nr_inodes=491167,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=396944k,mode=755)
/dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)

 

2. การ mount อุปกรณ์

mount <device> <path>

$ mount /dev/foo /dir

 

3. การ mount CDROM

$ mount /dev/cdrom
or
$ mount cd

 

4. การ remount

$ mount --bind olddir newdir

 

5. การย้าย mount point

$ mount --move olddir newdir

 

โครงสร้างคำสั่ง

 mount [-l|-h|-V]

 mount -a [-fFnrsvw] [-t fstype] [-O optlist]

 mount [-fnrsvw] [-o options] device|dir

 mount [-fnrsvw] [-t fstype] [-o options] device dir

 

รายละเอียด

เป็นคำสั่งที่ติดตั้งใช้งานอุปกรณ์ที่เชื่อมต่อ โดยการนำเอา อุปกรณ์ที่เชื่อมต่ออยู่ เชื่อมต่อเข้ากับ file system ซึ่งตรงข้ามกับ unmount ที่เอาไว้ถอดการติดตั้งหรือเชื่อมต่อ

 

Option

 Command-line options available for the mount command are:

 -a, --all
 Mount all filesystems (of the given types) mentioned in fstab (except for those whose line contains the noauto keyword). The filesystems are mounted following their order
 in fstab.

 -B, --bind
 Remount a subtree somewhere else (so that its contents are available in both places). See above.

 -c, --no-canonicalize
 Don't canonicalize paths. The mount command canonicalizes all paths (from command line or fstab) by default. This option can be used together with the -f flag for already
 canonicalized absolute paths. The option is designed for mount helpers which call mount -i. It is strongly recommended to not use this command-line option for normal mount
 operations.

 Note that mount(8) does not pass this option to the /sbin/mount.type helpers.

 -F, --fork
 (Used in conjunction with -a.) Fork off a new incarnation of mount for each device. This will do the mounts on different devices or different NFS servers in parallel.
 This has the advantage that it is faster; also NFS timeouts go in parallel. A disadvantage is that the mounts are done in undefined order. Thus, you cannot use this option
 if you want to mount both /usr and /usr/spool.

 -f, --fake
 Causes everything to be done except for the actual system call; if it's not obvious, this ``fakes'' mounting the filesystem. This option is useful in conjunction with the
 -v flag to determine what the mount command is trying to do. It can also be used to add entries for devices that were mounted earlier with the -n option. The -f option
 checks for an existing record in /etc/mtab and fails when the record already exists (with a regular non-fake mount, this check is done by the kernel).

 -i, --internal-only
 Don't call the /sbin/mount.filesystem helper even if it exists.

 -L, --label label
 Mount the partition that has the specified label.

 -l, --show-labels
 Add the labels in the mount output. mount must have permission to read the disk device (e.g. be suid root) for this to work. One can set such a label for ext2, ext3 or
 ext4 using the e2label(8) utility, or for XFS using xfs_admin(8), or for reiserfs using reiserfstune(8).

 -M, --move
 Move a subtree to some other place. See above.

 -n, --no-mtab
 Mount without writing in /etc/mtab. This is necessary for example when /etc is on a read-only filesystem.

 -O, --test-opts opts
 Limit the set of filesystems to which the -a option applies. In this regard it is like the -t option except that -O is useless without -a. For example, the command:

 mount -a -O no_netdev

 mounts all filesystems except those which have the option _netdev specified in the options field in the /etc/fstab file.

 It is different from -t in that each option is matched exactly; a leading no at the beginning of one option does not negate the rest.

 The -t and -O options are cumulative in effect; that is, the command

 mount -a -t ext2 -O _netdev

 mounts all ext2 filesystems with the _netdev option, not all filesystems that are either ext2 or have the _netdev option specified.

 -o, --options opts
 Use the specified mount options. The opts argument is a comma-separated list. For example:

 mount LABEL=mydisk -o noatime,nodev,nosuid

 For more details, see the FILESYSTEM-INDEPENDENT MOUNT OPTIONS and FILESYSTEM-SPECIFIC MOUNT OPTIONS sections.

 -R, --rbind
 Remount a subtree and all possible submounts somewhere else (so that its contents are available in both places). See above.

 -r, --read-only
 Mount the filesystem read-only. A synonym is -o ro.

 Note that, depending on the filesystem type, state and kernel behavior, the system may still write to the device. For example, ext3 and ext4 will replay the journal if the
 filesystem is dirty. To prevent this kind of write access, you may want to mount an ext3 or ext4 filesystem with the ro,noload mount options or set the block device itself
 to read-only mode, see the blockdev(8) command.

 -s Tolerate sloppy mount options rather than failing. This will ignore mount options not supported by a filesystem type. Not all filesystems support this option. Currently
 it's supported by the mount.nfs mount helper only.

 --source device
 If only one argument for the mount command is given then the argument might be interpreted as target (mountpoint) or source (device). This option allows to explicitly
 define that the argument is the mount source.

 --target directory
 If only one argument for the mount command is given then the argument might be interpreted as target (mountpoint) or source (device). This option allows to explicitly
 define that the argument is the mount target.

 -T, --fstab path
 Specifies an alternative fstab file. If path is a directory then the files in the directory are sorted by strverscmp(3); files that start with "." or without an .fstab
 extension are ignored. The option can be specified more than once. This option is mostly designed for initramfs or chroot scripts where additional configuration is speci‐
 fied beyond standard system configuration.

 Note that mount(8) does not pass the option --fstab to the /sbin/mount.type helpers, meaning that the alternative fstab files will be invisible for the helpers. This is no
 problem for normal mounts, but user (non-root) mounts always require fstab to verify the user's rights.

 -t, --types fstype
 The argument following the -t is used to indicate the filesystem type. The filesystem types which are currently supported depend on the running kernel. See /proc/filesys‐
 tems and /lib/modules/$(uname -r)/kernel/fs for a complete list of the filesystems. The most common are ext2, ext3, ext4, xfs, btrfs, vfat, sysfs, proc, nfs and cifs.

 The programs mount and umount support filesystem subtypes. The subtype is defined by a '.subtype' suffix. For example 'fuse.sshfs'. It's recommended to use subtype nota‐
 tion rather than add any prefix to the mount source (for example 'sshfs#example.com' is deprecated).

 If no -t option is given, or if the auto type is specified, mount will try to guess the desired type. Mount uses the blkid library for guessing the filesystem type; if that
 does not turn up anything that looks familiar, mount will try to read the file /etc/filesystems, or, if that does not exist, /proc/filesystems. All of the filesystem types
 listed there will be tried, except for those that are labeled "nodev" (e.g., devpts, proc and nfs). If /etc/filesystems ends in a line with a single *, mount will read
 /proc/filesystems afterwards. While trying, all filesystem types will be mounted with the mount option silent.

 The auto type may be useful for user-mounted floppies. Creating a file /etc/filesystems can be useful to change the probe order (e.g., to try vfat before msdos or ext3
 before ext2) or if you use a kernel module autoloader.

 More than one type may be specified in a comma-separated list, for option -t as well as in an /etc/fstab entry. The list of filesystem types for option -t can be prefixed
 with no to specify the filesystem types on which no action should be taken. The prefix no has no effect when specified in an /etc/fstab entry.

 The prefix no can be meaningful with the -a option. For example, the command

 mount -a -t nomsdos,smbfs

 mounts all filesystems except those of type msdos and smbfs.

 For most types all the mount program has to do is issue a simple mount(2) system call, and no detailed knowledge of the filesystem type is required. For a few types however
 (like nfs, nfs4, cifs, smbfs, ncpfs) an ad hoc code is necessary. The nfs, nfs4, cifs, smbfs, and ncpfs filesystems have a separate mount program. In order to make it pos‐
 sible to treat all types in a uniform way, mount will execute the program /sbin/mount.type (if that exists) when called with type type. Since different versions of the smb‐
 mount program have different calling conventions, /sbin/mount.smbfs may have to be a shell script that sets up the desired call.

 -U, --uuid uuid
 Mount the partition that has the specified uuid.

 -v, --verbose
 Verbose mode.

 -w, --rw, --read-write
 Mount the filesystem read/write. This is the default. A synonym is -o rw.

 -V, --version
 Display version information and exit.

 -h, --help
 Display help text and exit.

 

กลุ่มคำสั่ง

mount(2), umount(2), fstab(5), umount(8), swapon(8), findmnt(8), nfs(5), xfs(5), e2label(8), xfs_admin(8), mountd(8), nfsd(8), mke2fs(8), tune2fs(8), losetup(8)

 

Reference:

คำสั่ง Unix – Linux Command

Linux, Unix

 

Author: Suphakit Annoppornchai

Credit: https://saixiii.com

Leave a Reply