Home > Article > Operation and Maintenance > mount mount
mount
1 Mount mount
Mounting: Establish an association between the additional file system and the existing directory of the root file system, so that this directory can be accessed and stored as other files. Behavior
Uninstall: The process of disassociating
Note: The original files under the mount point will be temporarily hidden after the mount is completed, but the data Will not be lost. Therefore, it is best to set the mounting directory to an empty directory.
2Mounting method
mount DEVICE MOUNT_POINT
DEVICE is the device to be mounted, which can be a disk partition, volume label (LABEL), or UUID Or a file (the file can also be mounted as a disk after formatting); MOUNT_POINT is the mount point.
For example:
[root@local ~]# mount /dev/sdc1 /mnt/sdc1 [root@local ~]# mount -U "95c37ae8-7bd9-4d8b-ba17-61aaf39f292f" /mnt/sdc1 [root@local ~]# mount -L "SDC1" /mnt/sdc1/ #SDC1位分区?dev/sdc1的卷标。
The above three methods can mount the /dev/sdc1 partition to the /dev/sdc1 directory, and you can enter it now The /mnt/sdc1 directory accesses the /dev/sdc1 disk. At this time, all data operations on /mnt/sdc1 will be saved to the /dev/sdc1 partition.
The file system must be created before mounting, which is to format the partition.
3 Check the mounted command
df、lsblk或者cat /proc/mounts
Yes Display current and mounted devices by executing the df command
[root@local ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 12254344 6357184 5251632 55% / devtmpfs 1001592 0 1001592 0% /dev tmpfs 1016064 88 1015976 1% /dev/shm tmpfs 1016064 9292 1006772 1% /run tmpfs 1016064 0 1016064 0% /sys/fs/cgroup /dev/sda1 194235 123782 56117 69% /boot tmpfs 203216 16 203200 1% /run/user/0 /dev/sr0 8086368 8086368 0 100% /run/media/root/CentOS 7 x86_64 /dev/sdc1 1998672 6144 1871288 1% /mnt/sdc1 #可以看到分区已经挂载成功
##
[root@local ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8:0 0 20G 0 disk ├─sda1 8:1 0 200M 0 part /boot ├─sda2 8:2 0 12G 0 part / └─sda3 8:3 0 1G 0 part [SWAP] sdb 8:16 0 5G 0 disk ├─sdb1 8:17 0 976M 0 part ├─sdb2 8:18 0 975.6M 0 part └─sdb3 8:19 0 975M 0 part sdc 8:32 0 5G 0 disk └─sdc1 8:33 0 2G 0 part /mnt/sdc1 sr0 11:0 1 7.7G 0 rom
[root@local ~]# cat /proc/mounts rootfs / rootfs rw 0 0 sysfs /sys sysfs rw,seclabel,nosuid,nodev,noexec,relatime 0 0 proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0 devtmpfs /dev devtmpfs rw,seclabel,nosuid,size=1001592k,nr_inodes=250398,mode=755 0 0 securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0 tmpfs /dev/shm tmpfs rw,seclabel,nosuid,nodev 0 0 [. . . . .] tmpfs /run/user/0 tmpfs rw,seclabel,nosuid,nodev,relatime,size=203216k,mode=700 0 0 /dev/sdc1 /mnt/sdc1 ext4 rw,seclabel,relatime,data=ordered 0 0
4 mount common command options
-t vsftype: Specify the file system type on the device to be mounted -r: readonly, read-only mount -w: read and write, read-write mount -n: No -a: Automatically mount all files that support automatic mounting Device (specified in the /etc/fstab file, and the mount option has the auto function) -L"LABEL": Specify the mounting device with the volume label -U "UUID ": Specify the device to be mounted with UUID -B, --bind: Bind the directory to another directory -o option: Options for mounting the file system, multiple Options used simultaneously are separated by commas. is an amazing option. async: one-step mount sync: synchronous mount atime/noatime: disable or enable automatic update of atime, including directories and files ##diratime/nodiratime: directory access timestamp auto/noauto: whether to support automatic mounting and whether to support the -a option
exec/ noexec: Whether to support running applications on the file system
dev/nodev: whether to support the use of device files on the secondary file system
suid/nosuid: whether to support suid and sgid permissions
remount: remount
ro: read-only mount
rw: read-write mount
user/nouser: whether to run a normal user to mount this device , the default administrator can mount it
acl: Enable the acl function on this file system
Default: equivalent to re, nosuid, dev, exec, auto, nouser, async
5 Other mount-related commands
(1) Check the mounting status of the mount point: findmnt MOUNT_POINT
[root@local ~]# findmnt /mnt/sdc1 TARGET SOURCE FSTYPE OPTIONS /mnt/sdc1 /dev/sdc1 ext4 rw,relatime,seclabel,data=ordered [root@local ~]# findmnt /mnt/sdc2 TARGET SOURCE FSTYPE OPTIONS /mnt/sdc2 /dev/sdc2 xfs rw,relatime,seclabel,attr2,inode64,noquota
: lsof MOUNT_POINT, fuser –v MOTN_POINT
[root@local ~]# lsof /mnt/sdc1 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 1615 root cwd DIR 8,33 4096 2 /mnt/sdc1 bash 2024 root cwd DIR 8,33 4096 2 /mnt/sdc1
可以看到有两个用户正在访问/mnt/sdc1目录
[root@local ~]# fuser -v /mnt/sdc1 USER PID ACCESS COMMAND /mnt/sdc1: root kernel mount /mnt/sdc1 root 1615 ..c.. bash root 2024 ..c.. bash
(3)终止所有正在访问指定的文件系统的进程
[root@local ~]# fuser -km /mnt/sdc1 /mnt/sdc1: 1615c 2024c
接下来查看是否成功
[root@local ~]# lsof /mnt/sdc1
可以看到以及踢成功,不过在实际应用时,最好提前发通知,以免用户在线导数据丢失
6 卸载
卸载命令:umount DEVICE
或者umount MOUNT_POINT
[root@local ~]# umount /dev/sdc1 #卸载/dev/sdc1
以及看不到/dev/sdc1说明卸载成功
[root@local ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 12254344 6869184 4739632 60% / devtmpfs 1001592 0 1001592 0% /dev tmpfs 1016064 84 1015980 1% /dev/shm tmpfs 1016064 9232 1006832 1% /run tmpfs 1016064 0 1016064 0% /sys/fs/cgroup /dev/sda1 194235 123782 56117 69% /boot tmpfs 203216 16 203200 1% /run/user/42 tmpfs 203216 0 203216 0% /run/user/0 /dev/sdc2 1038336 32944 1005392 4% /mnt/sdc2
下来用另一种方法卸载/dev/sdc2
[root@local ~]# umount /mnt/sdc2 [root@local ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 12254344 6869184 4739632 60% / devtmpfs 1001592 0 1001592 0% /dev tmpfs 1016064 84 1015980 1% /dev/shm tmpfs 1016064 9232 1006832 1% /run tmpfs 1016064 0 1016064 0% /sys/fs/cgroup /dev/sda1 194235 123782 56117 69% /boot tmpfs 203216 16 203200 1% /run/user/42 tmpfs 203216 0 203216 0% /run/user/0
以及看不到/dev/sdc2,说明卸载成功
7 修改/etc/fstab文件,设置自动挂载
查看/etc/fstab文件
[root@local ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Sun Apr 16 10:18:50 2017 # # 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=dddd23d1-1012-4bac-9717-56b9b469e0c2 / ext4 defaults 1 1 UUID=316d8677-25b8-49af-b4eb-54daa20b6595 /boot ext4 defaults 1 2 UUID=dacd6ddd-d765-4646-b98c-0579f2732749 swap swap defaults 0 0
可以看到,每行定义一个要挂载的文件系统,有六个字段,每个字段对于的含义:
第一个字段:要挂载的设备或者伪文件系统
设备文件、卷标(LABEL)、UUID、伪文件系统名称(proc、sysfs)
第二个字段:指定挂载点
第三个字段:文件系统类型
第四个字段:挂载选项
sync、atime/noatime、diratime/nodiratime、auto/noauto、exec/noexec、dev/nodev、suid/nosuid、
remount、ro、rw、user/nouser、 acl
第五个字段:转存频率
0:不做备份
1:每天转存
2:没隔一天转存
第六感字段:启动时自检次序
0:表示不自检
1:首先自检,一般只有rootfs才用1
The above is the detailed content of mount mount. For more information, please follow other related articles on the PHP Chinese website!