One day learning how to mount a Linux File System

Source: Internet
Author: User

 

Yesterday, we introduced how to manually execute commands to mount a file system. If you often need to mount some file systems, how can I enable the system to automatically mount them at startup? The following two methods are described:

Method 1.

Place the mount command in/etc/rc. d/rc. local.

This is a method, but it is not recommended to do so, because our system has a unified planning solution, so the second method is recommended.

 

 

Method 2.

Modify the configuration file/etc/fstab. This file is used to set the file system to be mounted at startup. Next, let's take a look at/etc/fstab.

 

[Root @ yufei ~] # Cat/etc/fstab

Multiple rows of useless information are omitted here.

UUID = 8e4f6141-20f9-4f5a-aad4-bac048371_2/ext4 ults 1 1

UUID = c70cd6a4-09cd-4aea-ba94-f3641df4e981 swap defaults 0 0

Tmpfs/dev/shm tmpfs defaults 0 0

Devpts/dev/pts devpts gid = 5, mode = 620 0 0

Sysfs/sys sysfs defaults 0 0

Proc/proc defaults 0 0

This content has something to do with your system. The top two lines are our disk file system, and the last four lines are virtual file systems. We don't care about this.

 

This file is divided into six fields. These six fields are very important, so let's take a look at them.

 

Column 1: The name of the disk device, the volume of the device, or the UUID of the device. # You can use tune2fs or dumpe2fs to query the information.

 

[Root @ yufei ~] # Tune2fs-l/dev/sdb1 | more

[Root @ yufei ~] # Dumpe2fs/dev/sdb1 | more

Show only useful information

Filesystem volume name: opsers_tech

Last mounted on:/mnt

Filesystem UUID: 994ae2b7-d28a-4f7c-9464-c176108b

Therefore, the following three methods can be used in this column. The results are the same, indicating the same device.

/Dev/sdb1

LABEL = opsers_tech

UUID = 994ae2b7-d28a-4f7c-9464-c176108b

Column 2: mount point. # We strongly recommend that you use an empty directory

 

Column 3: file system type. # During manual mounting, the system can automatically test the mounting, but the file must be manually written to the file system type. File System types include ext3, ext4, vfat, ntfs, nfs, smbfs, and swap.

 

Column 4: file system parameters. # This is the same as the mount mentioned above. Here we will give a brief introduction, because it is very important.

 

Async/sync asynchronous/Synchronous: sets the disk operation mode. The default value is async (better performance), which is to write the content to the log and save it to the disk.

 

Auto/noauto automatic/non-automatic: when mount-a is issued, whether the file system is actively tested and mounted. The default value is auto.

 

Rw/ro read/write/read-only: if the data you want to share is not changed at will, you can set it to ro, regardless of whether the file system has w permissions, cannot Write content.

 

Exec/noexec executable/unexecutable: Restrict whether operations can be performed in this file system. If the file system is purely used to store data, therefore, it is safer to set noexec.

 

User/nouser allows/does not allow other users to mount: In normal cases, the system does not want users with normal identities to use the mount command for security reasons, because it is too insecure, the default value is nouser.

 

Suid/nosuid has/does not have suid permission: whether the file system allows the existence of SUID. This is also related to system security. If it is not the directory where the execution file is stored, you can set it to nosuid to cancel this function.

 

Do not make a mistake in usrquota. This allows you to support disk quotas when starting a file system. This is for users.

 

Like the above, the disk quota of the user group is supported.

 

Defaults also has the rw, suid, dev, exec, acl, and async parameters.

 

We can use ults by default.

 

Column 5: whether it can be used by the dump BACKUP command. # Dump is a backup command. We can use fstab to specify which file system must be backed up by dump. 0 indicates that dump backup is not performed, 1 indicates that dump is performed every day, and 2 indicates that dump backup is performed on another non-date basis. Generally, this value is 1 if it is not 0.

 

Column 6: whether to use fsck to check the sector: # During the boot process, the system uses fsck to check whether the file system is complete by default. However, some file systems do not need to be tested, such as swap and special file systems/proc and/sys. 0 indicates that the test is not performed. 1 indicates that the test is performed first (generally only the root directory is set to 1), 2 indicates that the test is performed first, and 2 indicates that the test is performed second. This option is only effective for operating system partitions. Other file systems can be set as needed because it does not affect system boot.

 

NOTE 1: The/etc/fstab file has a lot to do with system startup. If you accidentally write the content in it incorrectly, the system may fail to start. To prevent this problem, it is best to use

 

Run the mount-a command to perform a test. If no error occurs, the system can be started normally next time.

 

NOTE 2: If I modify the mount parameters in this file, you need to use mount-o remount to re-apply the new parameters. However, mount-a cannot load the parameter information of the mounted file system. You can run the mount command to view the parameter information.

Finally, we write the partition formatted yesterday into the/etc/fstab file. Before editing a file, I will introduce blkid, a very useful tool, which will display information about all the file systems in the system, including the device name, volume label, UUID, and file system type. See the following results

 

 

 

[Root @ yufei ~] # Blkid

/Dev/sda1: UUID = "8e4f6141-20f9-4f5a-aad4-bac048371_2" TYPE = "ext4"

/Dev/sda2: UUID = "c70cd6a4-09cd-4aea-ba94-f3641df4e981" TYPE = "swap"

/Dev/sdb1: LABEL = "opsers_tech" UUID = "994ae2b7-d28a-4f7c-9464-c176425378b" TYPE = "ext4"

/Dev/sdb2: SEC_TYPE = "msdos" UUID = "7F29-8A7A" TYPE = "vfat"

 

[Root @ yufei ~] # Vim/etc/fstab

/Dev/sdb1/mnt ext4 defaults 0 0

UUID = 7F29-8A7A/test vfat defaults 0 0

 

[Root @ yufei ~] # Mount-

[Root @ yufei ~] # Mount-

If no error message is displayed, it means that our configuration is correct, so there will be no error after the next system start, and the system will not start.

 

After the system is started, df-T is used to view the information about disks attached to the system.

 

 

 

[Root @ yufei ~] # Df-T

Filesystem Type 1K-blocks Used Available Use % Mounted on

/Dev/sda1 ext4 15118728 6980432 7370296 49%/

Tmpfs 255784 0 255784 0%/dev/shm

/Dev/sdb1 ext4 1033560 40980 939568 5%/mnt

/Dev/sdb2 vfat 409424 0 409424 0%/test

Run the mount command to view the mounting information in the system.

 

[Root @ yufei ~] # Mount

/Dev/sda1 on/type ext4 (rw)

Proc on/proc type proc (rw)

Sysfs on/sys type sysfs (rw)

Devpts on/dev/pts type devpts (rw, gid = 5, mode = 620)

Tmpfs on/dev/shm type tmpfs (rw, rootcontext = "system_u: object_r: tmpfs_t: s0 ")

/Dev/sdb1 on/mnt type ext4 (rw)

/Dev/sdb2 on/test type vfat (rw)

None on/proc/sys/fs/binfmt_misc type binfmt_misc (rw)

None on/proc/fs/vmblock/mountPoint type vmblock (rw)

Sunrpc on/var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

/Etc/fstab is the configuration file during startup. In fact, the file system is mounted in the/etc/mtab and/proc/mounts files. If the data written in/etc/fstab is incorrect, the system will fail to start up smoothly and enter the maintenance mode for the single user. At this time, the/is read-only, to modify/etc/fstab, you need to use the following common system repair command.

 

Mount-o remount, rw/

From yufei blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.