mount的几个选项

1、mount -o noatime
表示在读文件时不去更改文件的access time属性了,因此该选项会提高mount操做的执行效率。

2、mount --bind:等同于 -o bind
可用于挂载文件到另外一文件,或目录到另外一目录,便于测试只读文件系统或不想覆盖的文件等。
假设咱们要改的文件是/etc/hosts,可按下面的步骤操做:linux

1. 把新的hosts文件放在/tmp下
2. sudo mount --bind /tmp/hosts /etc/hosts

测试完成了执行 sudo umount /etc/hosts 断开绑定。
若是我须要在/etc下面增长一个exports文件怎么办?原来没有这个文件,不能直接bind。ubuntu

有两个方法:

bash

方法1:绑定整个/etc目录,绑定前先复制/etc
# cp -a /etc /tmp #此处使用tar方法拷贝更好
# mount --bind /tmp/etc /etc
此时的/etc目录是可写的,所作修改不会应用到原来的/etc目录,能够放心测试。

 

方法2:挂载ramfs到/etc,一样要先复制/etc
挂载ramfs
# mkdir /tmp/etc
# mount -t ramfs none /tmp/etc

复制/etc,这里咱们不能用cp -a,改用tar
# cd /etc
# tar cf - . |(cd /tmp/etc; tar xf -)
# cd /

覆盖/etc
# mount --move /tmp/etc /etc #ubuntu 16.04上操做不成功
测试完了记着 umount /etc

 
3、mount --move:等同于 -o move
例如:mount --move mountpoint newdir
第一个参数必须是一个挂载点,该选项表示将挂载点转移,先释放原挂载点,而后挂载到新挂载点newdir。
不过很奇怪的是在ubuntu 16.04上一直未实验成功。提示:oop

mount: bad option. Note that moving a mount residing under a shared
       mount is unsupported.

       In some cases useful info is found in syslog - try
       dmesg | tail or so.

 
4、经过两个示例了解tar进行拷贝测试

# tar cf - . |(cd /tmp/etc; tar xf -) #表示将当前目录下全部文件打包,而后解压到/tmp/etc下
# tar -C /tmp/cproot -cvf - . | tar -C /mnt -xvf -  #表示将/tmp/cproot目录下全部文件打包,而后解压到/mnt下

拷贝系统文件时常常使用该方法,而不是cp -a

5、mount常常使用方法以下

1. mount isocode

sudo mount -o loop a.iso /mnt/iso

2. 挂载fat32到linux下blog

sudo mount -t vat /dev/sda1 /mnt/xp

3. 挂载以后,访问里面乱码的解决ip

sudo mount –o iocharset=gb2312 codepage=936 /dev/hda5 /mnt/hda5

4. 为何mount上去之后分区普通用户不可写?
mount时加上 –o umask=000 便可:io

sudo mount –o umask=000, iocharset=cp936 /dev/hda5 /mnt/hda5

5. 如何挂载samba 分区?class

# mkdir /mnt/share
# mount -t smbfs -o username=root,password=abc,codepage=936,iocharset=gb2312 /<ip-addr>/share /mnt/share
相关文章
相关标签/搜索