挂载使用已经格式化好的文件系统
1.磁盘创建好文件分区以后需要挂载到系统的一个目录才能正常的使用
所有操作系统都有挂载操作,只不过有的会自动挂载
LINUX一般需要进行手工挂载或者配置系统进行自动挂载
/mnt 默认挂载目录 其他任何目录都可以
2.使用mount命令进行挂载操作
(1)命令操作
root@ming-computer:~# mount /dev/sdb1 /mnt
root@ming-computer:/mnt# mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro) ------------->>>>>>>>>挂载根分区
proc on /proc type proc (rw,noexec,nosuid,nodev) ---------->>>>>>>>>创建proc(存在于内存中的文件系统)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) --------->>>>>创建sysfs(存在于内存中的文件系统)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
share on /media/sf_share type vboxsf (gid=125,rw)
gvfs-fuse-daemon on /home/ming/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=ming)
/dev/sdb1 on /mnt type ext4 (rw) --------->>>>挂载成功
root@ming-computer:/mnt# touch ming -------------->>>>>>>>>>在读写模式下创建文件ming
root@ming-computer:/mnt# ls
lost+found ming
root@ming-computer:/mnt# cd
root@ming-computer:~# mount -o remount,ro /dev/sdb1 /mnt ------------->>>>>>>>>>多个参数用逗号隔开(以只读方式重新挂载)
root@ming-computer:~# mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
share on /media/sf_share type vboxsf (gid=125,rw)
gvfs-fuse-daemon on /home/ming/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=ming)
/dev/sdb1 on /mnt type ext4 (ro) --------------->>>>只读方式挂载
root@ming-computer:/mnt# touch linuxcast
touch: 无法创建"linuxcast": 只读文件系统 ------------>>>>>>>>>>>>只读无法创建
(2)LINUX中会拿出一大部分内存来用作缓存
先把数据写到缓存中,再在系统空闲时将缓存中的数据写入磁盘,不使用缓存一般用在数据要求很安全的时候(比如说,断电时内存中数据还没来得及写进磁盘)
root@ming-computer:~# mount -o remount,sync /dev/sdb1 /mnt
root@ming-computer:~# mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
share on /media/sf_share type vboxsf (gid=125,rw)
gvfs-fuse-daemon on /home/ming/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=ming)
/dev/sdb1 on /mnt type ext4 (rw,sync) ------------------->>>>>>>>>>>>>>不实用缓存直接将数据写到磁盘中
root@ming-computer:~#
(3)atime ---->>access time (可以关闭保存这个参数有时没有多大意义,但是它比较消耗性能)
3.umount来卸载已经挂载的文件系统
fuser--------------->>>>查看进程
lsof ---->>>list open file,查看使用的文件
root@ming-computer:~# cd /mnt
root@ming-computer:/mnt# ls
lost+found ming
root@ming-computer:/mnt# umount /dev/sdb1
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@ming-computer:/mnt# fuser -m /mnt
/mnt: 2807c ------------->>>>>2807进程
root@ming-computer:/mnt# lsof /mnt
lsof: WARNING: can't stat() fuse.gvfs-fuse-daemon file system /home/ming/.gvfs
Output information may be incomplete.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 2807 root cwd DIR 8,17 4096 2 /mnt
lsof 2843 root cwd DIR 8,17 4096 2 /mnt
lsof 2844 root cwd DIR 8,17 4096 2 /mnt
root@ming-computer:/mnt#
4.自动挂载
通过配置/etc/fstab来定义需要自动挂载的文件系统
打开/etc/fstab
#开头的为注释部分
每一行代表一个挂载配置
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda1 during installation
UUID=266e3c2c-d4da-49d5-a5e4-e4e1b4af94be / ext4 errors=remount-ro 0 1 --------------->>>>>>>>根分区用UUID进行挂载
# swap was on /dev/sda5 during installation
UUID=42ad50bb-e7ab-4e96-928a-3f56e4ba3cc9 none swap sw 0 0
/dev/sdb1 /mntext4 ro0 0 #自己加入的自动加载配置
#加载的配置是要用tab键
然后重启,查看是否已经自动挂载
ming@ming-computer:~$ mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
/dev/sdb1 on /mnt type ext4 (ro) ---------------------->>>>>>>>>>发现已经自动挂载,参数也是正确的
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
share on /media/sf_share type vboxsf (gid=125,rw)
gvfs-fuse-daemon on /home/ming/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=ming)
ming@ming-computer:~$
对磁盘进行任何操作(修改磁盘的配置信息)时,必须把磁盘卸载掉
通过卷标来挂载磁盘
root@ming-computer:~# e2label /dev/sdb1
LINUXCAST
root@ming-computer:~# vi /etc/fstab
LABEL=LINUXCAST /mnt ext4 ro 0 0 #自己加入的自动加载配置 --------------->>>>>>>>>>卷标形式的挂载
#加载的配置是要用tab键
还可以使用UUID进行挂载像是根分区就是用UUID挂载的