磁盘与文件系统管理之四:挂载文件系统

文件系统管理(挂载)


一、挂载文件系统

Mount [-a]

-a :挂载/etc/fstab中所有具备auto挂载参数的FS.

Mount [-t FSTYPE] [-o MOUNT_OPTIONS] [DEVICE] [MOUNT_POINTER]

每个FS都会有个根目录(root directory),该文件系统所有的文件都存放在根目录。DOS/Win都是以盘符(Driver Letter)直接指定某个磁盘的根目录,但RHEL整个系统只允许有一个根目录,其他的磁盘的根目录必须挂载到根文件系统(root filesystem)下的某一个目录下.

关于根文件系统:

挂载起来成为根目录的文件系统,又称'根设备'. 根文件系统必须包含的目录:/bin/,/sbin/,/lib/,/dev/,/etc/五个目录,其他目录可以在其他的文件系统中.




二、挂载的好处

减少用户调用文件的不便:对于终端用户知道其文件放在哪个目录就够了,无需关注硬盘的情况,这个由系统管理员来处理.

灾难恢复,一旦发生灾难,系统管理员可轻松替换备份盘.

独立于平台,用户可在不同的硬件平台中继续原来的工作,如企业系统升级,新系统为SCSI磁盘代替旧的IDE磁盘,用户只要记得数据放在哪个目录就行.

[root@gwan ~]# mkdir /newdisk

[root@gwan ~]# ls /newdisk    #显示文件为空

[root@gwan ~]# mount /dev/sda4 /newdisk

[root@gwan ~]# ls /newdisk

lost+found       #该目录便是存放在/dev/sda4分区中的文件系统




三、挂载文件系统

1. 挂载数据表

涉及的文件

/etc/fstab         file system table

/etc/mtab         table of mounted file systems

/etc/mtab~        lock file

/etc/mtab.tmp     temporary file

/etc/filesystems    a list of filesystem types to try


如何知道RHEL共挂载了哪些文件系统?查看当前的挂载数据分区表(Mounting Table)


格式为:

DEVICE    on  MOUNT_POINTER  type  FSTYPE  (MOUNT_OPTIONS)

/dev/sda1  on         /          type   ext3         (rw)

若device显示为none则表示不是实体的磁盘空间

[root@gwan ~]# mount

/dev/sda1 on / type ext3 (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)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)   

none on /proc/fs/vmblock/mountPoint type vmblock (rw)

/dev/sda4 on /newdisk type ext2 (rw)

挂载卸载文件系统,RHEL会自动将变更信息写入/etc/mtab文件,它会以/etc/fstab文件的格式显示当前的挂载信息

[root@gwan ~]# cat /etc/mtab

/dev/sda1 / ext3 rw 0 0

proc /proc proc rw 0 0

sysfs /sys sysfs rw 0 0

devpts /dev/pts devpts rw,gid=5,mode=620 0 0

tmpfs /dev/shm tmpfs rw 0 0

none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0

none /proc/fs/vmblock/mountPoint vmblock rw 0 0

/dev/sda4 /newdisk ext2 rw 0 0



2. 挂载参数

使用mount挂载文件系统时,可以指定挂载参数来修改文件系统的功能. 挂载参数包括共享挂载参数(Common Mount Options)和文件系统专用挂载参数(Filesystem Specific Mount Options)


1. 共享挂载参数:两两一组,相互排斥

async  All I/O to the file system should be done asynchronously.  

sync   All I/O to the file system should be done synchronously. In case of media with limit

-ed number of write cycles (e.g. some flash drives) "sync" may cause life-cycle shorening.

#异步效率高

auto    Can be mounted with the -a option.

noauto  Can only be mounted explicitly (i.e., the -a option will not cause the file system to be mounted).

# auto 必须在/etc/fstab文件中指定此选项。执行-a参数时,会加载设置为auto的设备,取消选取为noauto。

atime    Update inode access time for each access. This is the default.

noatime  Do not update inode access times on this file system (e.g, for faster access on the news  spool  to speed up news servers).

# 更新访问文件的时间戳

dev    Interpret character or block special devices on the file system.

nodev  Do not interpret character or block special devices on the file system.

#

suid    Allow set-user-identifier or set-group-identifier bits to take effect.

nosuid  Do not allow set-user-identifier or set-group-identifier bits to take effect. (This seems safe, but is in fact rather unsafe if you have suidperl(1) installed.)

# 启动特殊权限, 最好别动!

user    Allow an ordinary user to mount the file system. The name of the mounting user is written to mtab so that he can unmount the file system again. This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line user,exec,dev,suid).

nouser  Forbid an ordinary (i.e., non-root) user to mount the file system. This is the de-

fault.

# 允许普通用户挂卸载文件系统

rw     Mount the file system read-write.

ro     Mount the file system read-only.

Defaults Use default options: rw, suid, dev, exec, auto, nouser, and async.

# 参数组合

             

2. 文件系统专用挂载参数

参见man手册里面,Mount options for ext2, Mount options for ext3


3. 修改与指定挂载参数

如果没有指定,系统会把defaults作为挂载参数,若需其他的挂载参数,可:

第一次挂载FS:mount -o MOUNT_OPTIONS

不卸载直接修改FS里的挂载参数:Mount -o remount,MOUNT_OPTIONS

# 记得‘,’之间不要留空格

[root@gwan ~]# mount /dev/sda4 /newdisk                  ① 缺省挂载

[root@gwan ~]# mount | grep '/dev/sda4'                    ② 显示挂载数据表

/dev/sda4 on /newdisk type ext2 (rw)

[root@gwan ~]# touch /newdisk/MBI001                     ③ 挂载分区上创建文件

[root@gwan ~]# umount /dev/sda4                          ④ 卸载挂载数据表

[root@gwan ~]# mount -o ro /dev/sda4 /newdisk              ⑤ 指定参数ro挂载 

[root@gwan ~]# mount | grep '/dev/sda4'

/dev/sda4 on /newdisk type ext2 (ro) 

[root@gwan ~]# touch /newdisk/MBI002                     ⑥只读FS中创建文件

touch: cannot touch `/newdisk/MBI002': Read-only file system

[root@gwan ~]# mount -o remount,rw /dev/sda4 /newdisk      ⑦不卸载,修改参数 

[root@gwan ~]# mount | grep '/dev/sda4'                     ⑧显示变更的挂载参数

/dev/sda4 on /newdisk type ext2 (rw)

[root@gwan ~]# touch /newdisk/MBI003

[root@gwan ~]# ls /newdisk

lost+found  MBI001  MBI003


挂载特性

挂载将遮住挂载点原来的文件,窗帘与窗户的关系

存储介质挂载后就无法退出,如挂载CD后无法退出. 因为磁盘的数据全部写入了内存,如果不卸载就取出存储介质会造成数据丢失. 所以先要卸载文件系统.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24463783/viewspace-681624/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/24463783/viewspace-681624/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值