概念
在磁盘或分区上创建好的文件系统, 需要挂载到一个目录才能使用
windows和Mac会进行自动挂载, 即文件系统一创建好就自动挂载到系统上
挂载到windows上的文件系统称之为 C盘 D盘 E盘 等
Linux需要手动进行挂载操作 或者 更改配置文件/etc/fstab进行自动挂载
/dev/sdb1 ext4 --挂载到--> /mnt
mount
说明: 通过mount命令将 格式化好(创建好文件系统)的磁盘或分区 挂载到一个目录
格式: mount /dev/sdb1 /mnt
mount 要挂载的分区 挂载点
常用参数
无参数 : 显示所有已经挂载的文件系统
[root@wuqinfei ~]# mount /dev/sda2 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") none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
-t : 指定文件系统类型, 一般情况下可不指定(自动识别)
-o :指定挂载选项, 多个参数之间用逗号分隔
ro, rw 以只读或读写形式挂载, 默认是rw
sync 不使用缓存,所有操作直接写入磁盘
async 使用缓存, 默认. (使用缓存提升读写速度,降低磁盘损耗)
atime 每次访问文件 更新访问时间
noatime 每次访问文件 不更新访问时间(可提升性能)
remount 重新挂载
示例
[root@wuqinfei ~]# mount -o remount,ro /dev/sdb1 /mnt [root@wuqinfei ~]# mount /dev/sda2 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") none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) /dev/sdb1 on /mnt type ext4 (ro) [root@wuqinfei ~]# touch /mnt/1.txt touch: cannot touch `/mnt/1.txt': Read-only file system
[root@wuqinfei ~]# mount /dev/sdb1 /mnt [root@wuqinfei ~]# mount /dev/sda2 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") none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) /dev/sdb1 on /mnt type ext4 (rw)
umount
说明: 卸载已挂载的文件系统, 相当于windows中的弹出U盘
格式1 : umount /dev/sdb1
umount 文件系统
格式2 : umount /mnt
umount 文件系统对应的挂载点
注意: 报错 "device is busy" 说明该文件系统正在被使用, 无法卸载
fuser -m /mnt : 查看使用文件系统的进程
lsof /mnt : 查看正在被使用的文件
示例
[root@wuqinfei ~]# mount /dev/sda2 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") none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) /dev/sdb1 on /mnt type ext4 (ro) [root@wuqinfei ~]# cd /mnt [root@wuqinfei mnt]# umount /mnt umount: /mnt: device is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1)) [root@wuqinfei mnt]# fuser /dev/sdb1 [root@wuqinfei mnt]# fuser -m /dev/sdb1 /dev/sdb1: 1737c [root@wuqinfei mnt]# lsof /mnt COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 1737 root cwd DIR 8,17 1024 2 /mnt lsof 2184 root cwd DIR 8,17 1024 2 /mnt lsof 2185 root cwd DIR 8,17 1024 2 /mnt [root@wuqinfei mnt]# cd .. [root@wuqinfei /]# lsof /mnt [root@wuqinfei /]# umount /mnt [root@wuqinfei /]# mount /dev/sda2 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") none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) [root@wuqinfei /]#
自动挂载
/etc/fstab :定义需要自动挂载的文件系统,系统启动后自动挂载
每行的格式
需要挂载的设备 挂载点 文件系统类型 挂载选项(rw ro等等) dump及fsck相关选项
/dev/sdb1 /mnt ext4 defaults 0 0
UUID=2340ab26-2078-4979-968a-ab9b25ef97f7 / ext4 defaults 1 1 UUID=e0d145a0-4096-42d1-bbc8-0ca843b4ac4d swap 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 proc defaults 0 0
要挂载的设备可以通过 LABEL=卷标名 进行识别
[root@wuqinfei ~]# e2label /dev/sdb1 MYPARTITION LABEL=/dev/sdb1 /mnt ext4 defaults 0 0
mount -a : 挂载所有fstab中定义的自动挂载项(用于挂载 还没有挂载的设备)
[root@wuqinfei ~]# umount /mnt [root@wuqinfei ~]# mount /dev/sda2 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") none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) [root@wuqinfei ~]# mount -a [root@wuqinfei ~]# mount /dev/sda2 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") none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) /dev/sdb1 on /mnt type ext4 (rw) [root@wuqinfei ~]#