Linux disk and file system management (3) _ disk mounting and unmounting

Source: Internet
Author: User

Linux disk and file system management (3) _ disk mounting and unmounting
Attaching and detaching a disk: Associate the system's additional file system with the root file system through the root directory, and change the Directory into a new disk partition (that is, a file system). Unmount: The process of disassociation. Mount point: Device mount directory Note: After the mount point is mounted, the original files and directories under the directory will be temporarily hidden. After the new partition is detached, the original files and directories are displayed again. Therefore, we recommend that you use an empty directory for the mount point. Mount: mount [-l]: Read the/etc/mtab file to display all mounted devices in the current system [root @ localhost test] # mountproc on/proc type proc (rw, nosuid, nodev, noexec, relatime)/dev/sda3 on/type ext4 (rw, relatime, seclabel, data = ordered)/dev/sda2 on/usr type ext4 (rw, relatime, seclabel, data = ordered ).... omitted... debugfs on/sys/kernel/debug type debugfs (rw, relatime)/dev/sda1 on/boot type ext4 (rw, relatime, seclabel, data = ordered)/dev/sda5 o N/home type ext4 (rw, relatime, seclabel, data = ordered) mount-: mount all unmounted disks according to the data in the/etc/fstab configuration file. mount [-fnrsvw] [-t vfstype] [-o options] device mount_point device: device 1 file to be mounted:/dev/sdb5 2 volume label:-L 'label' 3 uuid:-U 'uuuid' 4 pseudo File System 5 file path: bind mount point: it is recommended that you set "-l" to "empty directory" when the current mount information is displayed. "-n" is added to the Label column and "/etc/mtab" is not written. By default, write the actual mounting status to/etc/mtab in real time. If you want to view all the mounted file systems: cat/proc/mounts-t: Specify the file system type to be mounted-L: use the specified volume label la Bel Mount-r: Mount in read-only mode-a: All file systems mounted in/etc/fstab-f: Skip system mounting and Test Run-B: bind a directory to another directory-o options is mainly used to describe the mounting method of the device or file. Parameter: loop: used to mount a file as a hard disk partition to the system ro: Read-Only mounting device rw: read/write mounting device iocharset: Specify the character set async used to access the file system: file System uses asynchronous write sync: The file system uses synchronous write auto, noauto: allows the partition to be automatically mounted by mount-a dev, nodev: whether to allow the creation of Device File suid on this partition, nosuid: whether to allow the suid/sgid File Format user on this partition, nouser: whether to allow any user to execute mount defaults: Default Value rw, suid, dev, exec, auto, nouser, and async. remount: remount. It is often used when a system error occurs or when parameters are updated.

# Mount according to the specified volume label-L [root @ localhost ~] # Mount-L 'mytest'/mnt/test1 [root @ localhost ~] # Mount | grep '/dev/sdb. '30:/dev/sdb1 on/root/test_mount/test1 type ext4 (rw, relatime, seclabel, data = ordered) # Mount partitions in read-only mode [root @ localhost ~] # Mount-r/dev/sdb5/mnt/test2 [root @ localhost ~] # Mount | grep '/dev/sdb. '30:/dev/sdb1 on/root/test_mount/test1 type ext4 (rw, relatime, seclabel, data = ordered) 31: /dev/sdb5 on/root/test_mount/test2 type ext4 (ro, relatime, seclabel, data = ordered) [root @ localhost ~] # DfFilesystem 1K-blocksUsed Available Use % Mounted on .... omitted... /dev/sdb1 9993202564927944 1%/mnt/test1/dev/sdb5 499656 784462176 1%/mnt/test2 # mount the/home directory to the/mnt/test3 directory [root @ localhost mnt] # mount-B/home // mnt/test3/[root @ localhost mnt] # ll/home // mnt/test3 // home /: total 32drwx ------. 2 hadoophadoop 4096 Sep 9 hadoopdrwx ------. 2 root 16384 Aug 20 lost + founddrwx ------. 2 roger 4096 Aug 20 rogerdrwx ------. 3 test1 test1 4096 Sep 7 test1drwx ------. 2 testuser1 testuser1 4096 Sep 13 testuser1/mnt/test3/: total 32drwx ------. 2 hadoophadoop 4096 Sep 9 hadoopdrwx ------. 2 root 16384 Aug 20 lost + founddrwx ------. 2 roger 4096 Aug 20 rogerdrwx ------. 3 test1 test1 4096 Sep 7 test1drwx ------. 2 testuser1 testuser1 4096 Sep 13 testuser1

 

Umount: unmount command umount [-fn] DEVICE file name umount [-fn] MOUNT_POINT mount point parameter:-f: Force unmount-n: example of uninstalling without updating/etc/mtab:
# Uninstall the device name [root @ localhost ~] # Umount/dev/sdb1 # because the directory is mounted, it can only be detached from the same mount point [root @ localhost ~] # Umount/mnt/test3/
The device is occupied during uninstallation [root @ localhost ~] # Umount/dev/sdb1umount:/mnt/test3: target is busy. (In some cases useful info about processes that use the device is found by lsof (8) or fuser (1) to view the process that is accessing the specified mount point:
 # fuser -v MOUNT_POINT[root@localhost ~]# fuser -v /mnt/test3/USER PID ACCESS COMMAND/mnt/test3:   root kernel mount /mnt/test3root3356 ..c.. bash

 

Terminate all processes that are accessing the specified mount point:
# Fuser-km MOUNT_POINT [root @ localhost ~] # Fuser-km/mnt/test3 // mnt/test3: 3356c # unmount [root @ localhost ~] # Umount/dev/sdb1

 

Note: fuser command: displays all files in use, file system or sockets Process Information fuser [-fuv] [-a |-s] [-4 |-6] [-c |-m |-n space] [-k [-I] [-M] [-w] [-SIGNAL] File Name/File System/sockets parameters: -k, -- kill: process that kills the file being accessed-I: Confirm before killing the process in interactive mode-m: the file name that follows will take the initiative to mention the top-level of the file system, which is effective for umount failure-u: The process owner-v: output process details by default, each process number is followed by a letter indicating how the process uses files. C file as the current directory e file as the executable object of the program r file as the root directory m file as the mmap file or shared library example:
[root@localhost ~]# fuser /mnt//mnt:   3427c[root@localhost ~]# fuser -u /mnt//mnt:   3427c(root)[root@localhost ~]# fuser -v /mnt/USER PID ACCESS COMMAND/mnt:  root3427 ..c.. bash[root@localhost ~]# fuser -ki /mnt//mnt:   3427cKill process 3427 ? (y/N) n

 

Mount related configuration files:/etc/fstab (file system table) records the file system to be mounted.
[root@localhost ~]# cat /etc/fstab ## /etc/fstab# Created by anaconda on Thu Aug 20 06:13:01 2015## Accessible filesystems, by reference, are maintained under '/dev/disk'# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info#UUID=8306bbdb-4c6b-4975-8596-c3721eeb6998  /ext4defaults 1 1UUID=4bfd1d98-b114-4685-84a0-d44130fb3128  /bootext4defaults 1 2UUID=86be1f1b-e7b0-4d86-a743-7cc99ba332ec  /homeext4defaults 1 2UUID=cc4474b4-402e-4e99-9b04-f55327d94faa  /usr ext4defaults 1 2UUID=f885b330-d561-454f-90d2-259c4a81a5f9  swap swapdefaults 0 0

 

Each line in the/etc/fstab file defines a file system. Each line has six fields: device to be mounted or pseudo file system mount point file system type Mount Option dump frequency self-check order name of the device to be mounted/dev/sda5, UUID =, Label =, pseudo file system name mount point: directory file system type: ext2/ext3/ext4, xfs... mount options: defaults, rw/ro, nouser, async/sync, auto/noauto... dumping frequency: 0 indicates that no backup is performed. 1 indicates that the dump operation is performed every day. 2 indicates that the dump operation is performed irregularly. Self-Check order: fsck checks that the slice is 0. 1 indicates that the first self-check 2 has a lower priority than 1. Example:
# Edit/etc/fstab [root @ localhost ~] # Vim/etc/fstab/dev/sdb1/mnt/test3 ext4defaults 0 0 # Mount [root @ localhost ~] # Mount-a # view [root @ localhost ~] # DfFilesystem 1K-blocksUsed Available Use % Mounted on/dev/sda3 9947976 554736 8864856 6%/devtmpfs 4930160493016 0% 9993202564927944/dev.../dev/sdb1 1%/mnt/test3

 

/Etc/mtab file: records the file systems mounted by the current system, including virtual files created by the operating system;
[root@localhost ~]# cat /etc/mtabrootfs / rootfs rw 0 0proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0sysfs /sys sysfs rw,seclabel,nosuid,nodev,noexec,relatime 0 0devtmpfs /dev devtmpfs rw,seclabel,nosuid,size=493016k,nr_inodes=123254,mode=755 0 0securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0tmpfs /dev/shm tmpfs rw,seclabel,nosuid,nodev 0 0devpts /dev/pts devpts rw,seclabel,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0tmpfs /run tmpfs rw,seclabel,nosuid,nodev,mode=755 0 0tmpfs /sys/fs/cgroup tmpfs rw,seclabel,nosuid,nodev,noexec,mode=755 0 0....

 

When mount and umount are used to detach partitions, mtab is updated in real time. mtab always keeps information about the partitions already mounted in the current system. programs such as fdisk and df must read the mtab file, to obtain the partition mounting information in the current system. You can also read/proc/mount to obtain the current mount information.

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.