Mounting a File System
To attach a certain file system, use the mount command in the following form:
mount[option…]devicedirectory
When the mount command is run, it reads the content of the /etc/fstab configuration file to see if the given file system is listed. This file contains a list of device names and the directory in which the selected file systems should be mounted, as well as the file system type and mount options. Because of this, when you are mounting a file system that is specified in this file, you can use one of the following variants of the command:
mount[option…]directorymount[option…]device
Note that unless you are logged in as In most cases, Table 2.1, "Common File System Types" provides a list of common file system types that can be used with the See Example 2.2, "Mounting a USB Flash Drive" for an example usage.
Older USB flash drives often use the FAT file system. Assuming that such drive uses the To specify additional mount options, use the command in the following form:
When supplying multiple options, do not insert a space after a comma, or Table 2.2, "Common Mount Options" provides a list of common mount options. For a complete list of all available options, consult the relevant manual page as referred to in "Installed Documentation".
See Example 2.3, "Mounting an ISO Image" for an example usage.
An ISO image (or a disk image in general) can be mounted by using the loop device. Assuming that the ISO image of the Centos Linux 14 installation disc is present in the current working directory and that the Note that ISO 9660 is by design a read-only file system.
Occasionally, certain system administration tasks require access to the same file system from more than one place in the directory tree (for example, when preparing a chroot environment). To address such requirements, the Although the above command allows a user to access the file system from both places, it does not apply on the file systems that are mounted within the original directory. To include these mounts as well, type:
Additionally, to provide as much flexibility as possible, Community Enterprise Operating System.8 implements the functionality known as shared subtrees. This feature allows you to use the following four mount types:
A shared mount allows you to create an exact replica of a given mount point. When a shared mount is created, any mount within the original mount point is reflected in it, and vice versa. To create a shared mount, type the following at a shell prompt: Alternatively, you can change the mount type for the selected mount point and all mount points under it:
See Example 2.4, "Creating a Shared Mount Point" for an example usage.
There are two places where other file systems are commonly mounted: the Then create its duplicate in You can now verify that a mount within Similarly, you can verify that any file system mounted in the A slave mount allows you to create a limited duplicate of a given mount point. When a slave mount is created, any mount within the original mount point is reflected in it, but no mount within a slave mount is reflected in its original. To create a slave mount, type the following at a shell prompt:
Alternatively, you can change the mount type for the selected mount point and all mount points under it:
See Example 2.5, "Creating a Slave Mount Point" for an example usage.
Imagine you want the content of the Then create its duplicate in You can now verify that a mount within You can also verify that file systems mounted in the A private mount allows you to create an ordinary mount. When a private mount is created, no subsequent mounts within the original mount point are reflected in it, and no mount within a private mount is reflected in its original. To create a private mount, type the following at a shell prompt:
Alternatively, you can change the mount type for the selected mount point and all mount points under it:
See Example 2.6, "Creating a Private Mount Point" for an example usage.
Taking into account the scenario in Example 2.4, "Creating a Shared Mount Point", assume that you have previously created a shared mount point by using the following commands as To mark the You can now verify that none of the mounts within You can also verify that file systems mounted in the An unbindable mount allows you to prevent a given mount point from being duplicated whatsoever. To create an unbindable mount, type the following at a shell prompt:
Alternatively, you can change the mount type for the selected mount point and all mount points under it:
See Example 2.7, "Creating an Unbindable Mount Point" for an example usage.
To prevent the This way, any subsequent attempt to make a duplicate of this mount will fail with an error:
To change the directory in which a file system is mounted, use the following command:
See Example 2.8, "Moving an Existing NFS Mount Point" for an example usage.
Imagine that you have an NFS storage that contains user directories. Assuming that this storage is already mounted in To verify the mount point has been moved, list the content of both directories:
root, you must have permissions to mount the file system (see "Specifying the Mount Options").
Specifying the File System Type
mount detects the file system automatically. However, there are certain file systems, such as NFS (Network File System) or CIFS (Common Internet File System), that are not recognized, and need to be specified manually. To specify the file system type, use the mount command in the following form:
mount -t type device directorymount command. For a complete list of all available file system types, consult the relevant manual page as referred to in "Installed Documentation".
Table 2.1. Common File System Types
Type
Description
ext2
The ext2 file system.
ext3
The ext3 file system.
iso9660
The ISO 9660 file system. It is commonly used by optical media, typically CDs.
jfs
The JFS file system created by IBM.
nfs
The NFS file system. It is commonly used to access files over the network.
nfs4
The NFSv4 file system. It is commonly used to access files over the network.
ntfs
The NTFS file system. It is commonly used on machines that are running the Windows operating system.
udf
The UDF file system. It is commonly used by optical media, typically DVDs.
vfat
The FAT file system. It is commonly used on machines that are running the Windows operating system, and on certain digital media such as USB flash drives or floppy disks.
Example 2.2. Mounting a USB Flash Drive
/dev/sdc1 device and that the /media/flashdisk/ directory exists, you can mount it to this directory by typing the following at a shell prompt as root:~]#
mount -t vfat /dev/sdc1 /media/flashdiskSpecifying the Mount Options
mount -o optionsmount will incorrectly interpret the values following spaces as additional parameters.
Table 2.2. Common Mount Options
Option
Description
async
Allows the asynchronous input/output operations on the file system.
auto
Allows the file system to be mounted automatically using the mount -a command.
defaults
Provides an alias for async,auto,dev,exec,nouser,rw,suid.
exec
Allows the execution of binary files on the particular file system.
loop
Mounts an image as a loop device.
noauto
Disallows the automatic mount of the file system using the mount -a command.
noexec
Disallows the execution of binary files on the particular file system.
nouser
Disallows an ordinary user (that is, other than root) to mount and unmount the file system.
remount
Remounts the file system in case it is already mounted.
ro
Mounts the file system for reading only.
rw
Mounts the file system for both reading and writing.
user
Allows an ordinary user (that is, other than root) to mount and unmount the file system.
Example 2.3. Mounting an ISO Image
/media/cdrom/ directory exists, you can mount the image to this directory by running the following command as root:~]#
mount -o ro,loop Centos Linux-14-x86_64-Live-Desktop.iso /media/cdromSharing Mounts
mount command implements the --bind option that provides a means for duplicating certain mounts. Its usage is as follows:
mount --bind old_directory new_directorymount --rbind old_directory new_directory
mount --make-shared mount_pointmount --make-rshared mount_pointExample 2.4. Creating a Shared Mount Point
/media directory for removable media, and the /mnt directory for temporarily mounted file systems. By using a shared mount, you can make these two directories share the same content. To do so, as root, mark the /media directory as "shared":~]#
mount --bind /media /media
~]# mount --make-shared /media/mnt by using the following command:
~]#
mount --bind /media /mnt/media also appears in /mnt. For example, if you have non-empty media in your CD-ROM drive and the /media/cdrom/ directory exists, run the following commands:
~]#
mount /dev/cdrom /media/cdrom
~]# ls /media/cdrom
EFI GPL isolinux LiveOS
~]# ls /mnt/cdrom
EFI GPL isolinux LiveOS/mnt directory is reflected in /media. For instance, if you have a non-empty USB flash drive that uses the /dev/sdc1 device plugged in and the /mnt/flashdisk/ directory is present, type:
~]#
mount /dev/sdc1 /mnt/flashdisk
~]# ls /media/flashdisk
en-US publican.cfg
~]# ls /mnt/flashdisk
en-US publican.cfg
mount --make-slave mount_pointmount --make-rslave mount_pointExample 2.5. Creating a Slave Mount Point
/media directory to appear in /mnt as well, but you do not want any mounts in the /mnt directory to be reflected in /media. To do so, as root, first mark the /media directory as "shared":~]#
mount --bind /media /media
~]# mount --make-shared /media/mnt, but mark it as "slave":
~]#
mount --bind /media /mnt
~]# mount --make-slave /mnt/media also appears in /mnt. For example, if you have non-empty media in your CD-ROM drive and the /media/cdrom/ directory exists, run the following commands:
~]#
mount /dev/cdrom /media/cdrom
~]# ls /media/cdrom
EFI GPL isolinux LiveOS
~]# ls /mnt/cdrom
EFI GPL isolinux LiveOS/mnt directory are not reflected in /media. For instance, if you have a non-empty USB flash drive that uses the /dev/sdc1 device plugged in and the /mnt/flashdisk/ directory is present, type: :
~]#
mount /dev/sdc1 /mnt/flashdisk
~]# ls /media/flashdisk
~]# ls /mnt/flashdisk
en-US publican.cfg
mount --make-private mount_pointmount --make-rprivate mount_pointExample 2.6. Creating a Private Mount Point
root:~]#
mount --bind /media /media
~]# mount --make-shared /media
~]# mount --bind /media /mnt/mnt directory as "private", type:
~]#
mount --make-private /mnt/media appears in /mnt. For example, if you have non-empty media in your CD-ROM drive and the /media/cdrom/ directory exists, run the following commands:
~]#
mount /dev/cdrom /media/cdrom
~]# ls /media/cdrom
EFI GPL isolinux LiveOS
~]# ls /mnt/cdrom
~]#/mnt directory are not reflected in /media. For instance, if you have a non-empty USB flash drive that uses the /dev/sdc1 device plugged in and the /mnt/flashdisk/ directory is present, type:
~]#
mount /dev/sdc1 /mnt/flashdisk
~]# ls /media/flashdisk
~]# ls /mnt/flashdisk
en-US publican.cfg
mount --make-unbindable mount_pointmount --make-runbindable mount_pointExample 2.7. Creating an Unbindable Mount Point
/media directory from being shared, as root, type the following at a shell prompt:~]#
mount --bind /media /media
~]# mount --make-unbindable /media~]#
mount --bind /media /mnt
mount: wrong fs type, bad option, bad superblock on /media/,
missing code page or other error
In some cases useful info is found in syslog - try
dmesg | tail or soMoving a Mount Point
mount --move old_directory new_directoryExample 2.8. Moving an Existing NFS Mount Point
/mnt/userdirs/, as root, you can move this mount point to /home by using the following command:~]#
mount --move /mnt/userdirs /home~]#
ls /mnt/userdirs
~]# ls /home
jill joe