Linux disk management-(3) mount mounting,/etc/fstab configuration file, mountfstab

Source: Internet
Author: User

Linux disk management-(3) mount mounting,/etc/fstab configuration file, mountfstab

After partitioning and formatting the file system, the final mount is reached. After mounting, the disk device can be used.

 

1. What is mounting and unmounting?

No block device can be directly accessed and must be mounted to a directory for access.

Mount: AdditionalFile SystemEstablish an association with an existing directory in the root file system, so that this directory acts as an access entry to other files (the mounted device must have a file system)

Unmount: The process of disassociation

Mount[-Option] DEVICE MOUNT_POINT)

(1) device: indicates the device to be mounted.

① Device File: for example,/dev/sda5

② Volume LABEL:-L 'label', for example,-L mage

③ UUID,-u'uuid'

(2) the original files under the mount point will be temporarily hidden after the mount is complete.

It exists beforehand. We recommend that you use an empty directory,The device in use by the process cannot be uninstalled

(3)/etc/mtab: The file displays all mounted devices (in centos 7, it is a soft connection of/proc/mounts. The result is the same as that in centos 6, ASCII text, the query result is different from/proc/mounts)

 

Ii. mount: Mount common command options (The following is an example)

View mounting status: findmnt view mounting status of all devices (tree structure)

View the mounting status of a single device on the findmnt Device

Mount: view the mounting status of all devices

Cat/proc/mounts: ViewKernelAll mounted devices tracked

Mount-option device mount point

-T: vsftype: specifies the type of the file system on the device to be mounted (not commonly used, without-t default built-in file system type). Sometimes, the system reports an error, the file system type is not specified. After-t is specified, there are still errors. (Note 1)

-R: Readonly,Read-OnlyMounting. Other operations are not allowed, and permissions are irrelevant. The media can only be read. It is mostly used for cold backup. Display at mount query timeRo

-W: read and write, read/write mounting (default defaults)

-N:Hide mounting information not displayedBut in/proc/mounts, you can find that only umount/app/sdb2 (mount point) can be uninstalled)

-: Automatically mount devices not mounted to the/etc/fstab file (defined in the/etc/fstab file, and the mounting option has the auto function, which is included by default ), if you modify the settings of a mounted device in/etc/fstab, do not refresh the device;

If you want to refresh and modify a mounted device, mount-o remount/dev/sdX (mount point)

-L'Label': Specify the mounting device as a volume LABEL

-U'Uuid': Specify the device to be mounted with UUID

-B-- Bind: bind the directory to another directory,

For example, mount-B/var/ftp/pub/app/apache shows the/var/ftp/pub directory.

-OOptions: (option for mounting the file system). Multiple options are separated by commas (,).

Async (defaults ),SyncAsynchronous, synchronous, and disk write when memory is changed (can be used for important data)

Atime (defaults), whether to update atime during access by noatime

Diratime (defaults), the Access timestamp of the nodiratime directory

Auto (defaults)/noauto is written in the/etc/fstab partition and whether the partition is mounted during mount-.

Whether the script of exec (defatuls)/noexec in the directory mounted to the partition can be executed.

Dev (defaults)/nodev: whether device files can be used on this file system

Suid (defaults)/nosuid: whether suid and sgid permissions are supported

Ro: Read-Only rw: read/write (defaults)

Nouser (defaults)/user: whether to allow normal users to mount the device. The default administrator can mount the device.

Acl (centos 7)/^ acl (less than centos 6): enable/disable the acl function on this file system

Default Value of ults. For more information, see (defaults)

-O remount, Option: Re-mount. Modify the function options (overwrite if they conflict with the/etc/fstab option, and add if there is no conflict). For example: mount-o remount, ro/dev/sdb1

For example, mount-r/dev/sdb1/app/sdb1 to mount/dev/sdb1 read-only to/app/sdb.

 

3. unmount umount

If a process is in progress, it cannot be uninstalled.

View the processes that are accessing the specified file system:

LsofBoth devices and mount points are supported.

Fuser-vMount point

Terminate all processes that are accessing the specified file system:

Fuser-kmBoth devices and mount points are supported.

After terminating all processes, You can uninstall the umount DEVICE.

 

 

Iv./etc/fstabFile Mounting configuration file

(1) define a file system to be mounted on each line of/etc/fstab

Mount-a automatically mounts the/etc/fstab file to a device that is not mounted, regardless of the mounted device.

If you want to refresh and modify a mounted device, mount-o remount/dev/sdX (or mount point)

Swpon-a automatically activates the/etc/fstab file, regardless of the activated extended space.

If you want to refresh and modify an activated Extension Device, mount-o remount/dev/sdX (or mount point)

When the system restarts, it reads this file. You can enable the settings in the file when the system restarts.

 

(2) format (6 columns ):

① Device or pseudo file system to be mounted: device name, LABEL, UUID, and pseudo file system name

② Mount point (expanded to swap)

③ File system type (auto search for the default one ),

General device mounting: ext #/xfs and other file system types

Swap partition swap: swap

Network Mount address: nfs, ipvs mount: cifs between linux

File cifs

④ Mount Option: defaults can be added if necessary. It cannot be blank.

⑤ Dumping frequency: 0: No backup; 1: dumping every day; 2: dumping every other day

6. self-check (not 0) at startup. self-check sequence: (if the system does not perform self-check, the system cannot start normally)

0: no self-check 1: first self-check, generally/2...: the smaller the number, the highest priority

 

Q: What should I do if the device is accidentally damaged and cannot be enabled properly after self-check is started?

The principle is very simple. You just need to fix the file system. (If you cannot fix it, you can change the self-check to 0 in/etc/fstab.) The procedure is as follows:

① Manually destroy the device dd if =/dev/zero of =/dev/sdc1 bs = 1 count = 2048

② Error prompt during startup

 

③ Go to the shell operation and repair it.

 

 

V. Experiment: migration/home Directory

Now we know about disk management. We can make a small experiment to migrate/home from/to another disk, such as/dev/sda6.

① Init 1 enters the single-user mode to prevent other users from performing operations during migration, leading to missing items after migration.

② Partition/dev/sda6 fdisk

③ Format mkfs. ext4/dev/sda6 in the file system

4. Mount/mnt to the temporary directory and cp-a from/home to the/mnt directory.

⑤ Remove existing/home items, uninstall/mnt, Mount/dev/sda6 to/home, write/etc/fstab, and mount it automatically upon startup.

UUID = 328a3f17-3e4e-440d-9538-c44be3e6465b/home ext4 defaults 0 2

⑥ Reboot or init 5 complete/home migration

 

The process of disk management has been completed, and the next article is a supplement to some extended space, external devices and gadgets.

 

I hope to help you. Please let me know if you have any errors ~

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.