Linux—— mount

1.官方文档
[root@master ~]# mount -h
Usage:
 mount [-lhV]
 mount -a [options]
 mount [options] [--source] <source> | [--target] <directory>
 mount [options] <source> <directory>
 mount <operation> <mountpoint> [<target>]
Options:
 -a, --all               mount all filesystems mentioned in fstab
 -c, --no-canonicalize   don't canonicalize paths
 -f, --fake              dry run; skip the mount(2) syscall
 -F, --fork              fork off for each device (use with -a)
 -T, --fstab <path>      alternative file to /etc/fstab
 -h, --help              display this help text and exit
 -i, --internal-only     don't call the mount.<type> helpers
 -l, --show-labels       lists all mounts with LABELs
 -n, --no-mtab           don't write to /etc/mtab
 -o, --options <list>    comma-separated list of mount options
 -O, --test-opts <list>  limit the set of filesystems (use with -a)
 -r, --read-only         mount the filesystem read-only (same as -o ro)
 -t, --types <list>      limit the set of filesystem types
     --source <src>      explicitly specifies source (path, label, uuid)
     --target <target>   explicitly specifies mountpoint
 -v, --verbose           say what is being done
 -V, --version           display version information and exit
 -w, --rw, --read-write  mount the filesystem read-write (default)

 -h, --help     display this help and exit
 -V, --version  output version information and exit

Source:
 -L, --label <label>     synonym for LABEL=<label>
 -U, --uuid <uuid>       synonym for UUID=<uuid>
 LABEL=<label>           specifies device by filesystem label
 UUID=<uuid>             specifies device by filesystem UUID
 PARTLABEL=<label>       specifies device by partition label
 PARTUUID=<uuid>         specifies device by partition UUID
 <device>                specifies device by path
 <directory>             mountpoint for bind mounts (see --bind/rbind)
 <file>                  regular file for loopdev setup

Operations:
 -B, --bind              mount a subtree somewhere else (same as -o bind)
 -M, --move              move a subtree to some other place
 -R, --rbind             mount a subtree and all submounts somewhere else
 --make-shared           mark a subtree as shared
 --make-slave            mark a subtree as slave
 --make-private          mark a subtree as private
 --make-unbindable       mark a subtree as unbindable
 --make-rshared          recursively mark a whole subtree as shared
 --make-rslave           recursively mark a whole subtree as slave
 --make-rprivate         recursively mark a whole subtree as private
 --make-runbindable      recursively mark a whole subtree as unbindable

2.参数

-a 安装在/etc/fstab文件中类出的所有文件系统。
-f 伪装mount,作出检查设备和目录的样子,但并不真正挂载文件系统。
-n 不把安装记录在/etc/mtab 文件中。
-r 讲文件系统安装为只读。
-v 详细显示安装信息。
-w 将文件系统安装为可写,为命令默认情况。

2.1 -t

指定文件系统的类型,通常不必指定,mount 会自动选择正确的类型。
光盘或光盘镜像:iso9660
DOS fat16文件系统:msdos
Windows 9x fat32文件系统:vfat
Windows NT ntfs文件系统:ntfs
Mount Windows文件网络共享:smbfs
UNIX(LINUX) 文件网络共享:nfs
linux目前常用的文件系统 ext2
自动检测文件系统 auto

2.2 -o

设备或档案的挂接方式
defaults 使用所有选项的默认值(auto、nouser、rw、suid)
auto/noauto 允许/不允许以 –a选项进行安装
dev/nodev 对/不对文件系统上的特殊设备进行解释
exec/noexec 允许/不允许执行二进制代码
suid/nosuid 确认/不确认suid和sgid位
user /nouser 允许/不允许一般用户挂载
codepage=XXX 代码页
iocharset=XXX 字符集
ro 以只读方式挂载
rw 以读写方式挂载
remount 重新安装已经安装了的文件系统
loop 挂载回旋设备

2.3 source

要挂接(mount)的设备

2.4 directory

设备在系统上的挂接点(mount point)

3. 示例
3.1 挂接光盘镜像文件

读取光驱制作光盘镜像文件
cp /dev/cdrom /home/sunky/mydisk.iso 或
dd if=/dev/cdrom of=/home/sunky/mydisk.iso
将文件和目录制作成光盘镜像文件
mkisofs -r -J -V mydisk-o /home/sunky/mydisk.iso /home/sunky/ mydir
创建挂接点
mkdir /mnt/vcdrom
mount -o loop -t iso9660 /home/sunky/mydisk.iso /mnt/vcdrom

3.2 挂接移动硬盘

对linux系统而言,USB接口的移动硬盘是当作SCSI设备对待的。插入移动硬盘之前,应先用fdisk –l 或 more /proc/partitions查看系统的硬盘和硬盘分区情况。
fdisk -l
fdisk –l 或 more /proc/partitions查看系统的硬盘和硬盘分区情况
mkdir -p /mnt/usbhd1
mkdir -p /mnt/usbhd2
mount -t ntfs /dev/sdc1 /mnt/usbhd1
mount -t vfat /dev/sdc5 /mnt/usbhd2
ntfs格式的磁盘分区应使用-t ntfs 参数,对fat32格式的磁盘分区应使用-t vfat参数。若汉字文件名显示为乱码或不显示,可以使用下面的命令格式。
#mount -t ntfs -o iocharset=cp936 /dev/sdc1 /mnt/usbhd1
#mount -t vfat -o iocharset=cp936 /dev/sdc5 /mnt/usbhd2

3.3 挂接U盘

和USB接口的移动硬盘一样对linux系统而言U盘也是当作SCSI设备对待的。
fdisk -l
插入U盘后,再用fdisk –l 或 more /proc/partitions查看系统的硬盘和硬盘分区情况。
mkdir -p /mnt/usb
mount -t vfat /dev/sdd1 /mnt/usb
若汉字文件名显示为乱码或不显示,可以使用下面的命令。
mount -t vfat -o iocharset=cp936 /dev/sdd1 /mnt/usb

3.4 挂接Windows文件共享

Windows网络共享的核心是SMB/CIFS,在linux下要挂接(mount)windows的磁盘共享,就必须安装和使用samba 软件包。现在流行的linux发行版绝大多数已经包含了samba软件包。
mkdir –p /mnt/samba
mount -t smbfs -o username=administrator,password=pldy123 //10.140.133.23/c$ /mnt/samba
administrator 和 pldy123 是ip地址为10.140.133.23 windows计算机的一个用户名和密码,c$是这台计算机的一个磁盘共享

3.5 挂接UNIX系统NFS文件共享

类似于windows的网络共享,UNIX(Linux)系统也有自己的网络共享,那就是NFS(网络文件系统)。
3.5.1配置好NFS服务端。
修改 /etc/exports,增加共享目录
/export/home/sunky 10.140.133.23(rw)
/export/home/sunky1 (rw)
/export/home/sunky2 linux-client(rw)
注:/export/home/目录下的sunky、sunky1、sunky2是准备共享的目录,10.140.133.23、
、 linux-client是被允许挂接此共享linux客户机的IP地址或主机名。如果要使用主机名linux-client必须在服务端主机 /etc/hosts文件里增加linux-client主机ip定义。格式如下:
10.140.133.23 linux-client
3.5.2 启动与停止NFS服务
/etc/rc.d/init.d/portmap start (在REDHAT中PORTMAP是默认启动的)
/etc/rc.d/init.d/nfs start 启动NFS服务
/etc/rc.d/init.d/nfs stop 停止NFS服务
若修改/etc/export文件增加新的共享,应先停止NFS服务,再启动NFS服务方能使新增加的共享起作用。使用命令exportfs -rv也可以达到同样的效果。
3.5.3 Linux客户端挂接(mount)其他linux系统或UNIX系统的NFS共享
mkdir –p /mnt/nfs
mount -t nfs -o rw 10.140.133.9:/export/home/sunky /mnt/nfs

4. 注意事项

4.1 使用多个-o参数的时候,-o 只用一次,参数之间用半角逗号隔开:
mount –o remount,rw /
mkdir /mnt/hda5 //创建hda5的目录作为挂载点,位置和目录名可自定义//
mount -t vfat /dev/hda5 /mnt/hda5
一般而言,Linux会自动探测分区的文件系统,除非让你指定时,否则-t vfat 可以省掉。
mount /dev/hda5 /mnt/hda5
4.2 mount上分区后显示乱码
显示问号表明你的系统中没有可识别使用的中文字体,请先安装中文字体。确保你的系统已经可以很好的显示中文。显示为乱码一般是mount默认使用的文件系统编码和文件系统中文件的实际编码不一致造成的。要想正常显示中文文件,mount时需要用到 -o 参数里的codepage和iocharset选项。codepage指定文件系统的代码页,简体中文中文代码是936;iocharset指定字符集,简体中文一般用cp936或gb2312。
mount –o iocharset=gb2312 codepage=936 /dev/hda5 /mnt/hda5
一般来说 mount –o iocharset=cp936 /dev/hda5 /mnt/hda5 就可以解决问题了。
如果这样做了以后还有问题,尝试UTF-8编码
mount –o iocharset=utf8 /dev/hda5 /mnt/hda5
4.3 mount上去以后分区普通用户不可写
mount时加上 –o umask=000
mount –o umask=000, iocharset=cp936 /dev/hda5 /mnt/hda5
4.4 mount上去后的分区中的文件都变成短文件名
这是文件系统挂错的原因,将FAT32挂载成FAT16时就会出现这种情况,先umount,然后用 –t vfat 重新挂载即可解决问题。
mount –t vat /dev/hda5 /mnt/hda5
4.5 挂载软驱
mkdir /mnt/floppy
mount /dev/fd0 /mnt/floppy //挂载软驱 //
4.6 开机自动挂载分区
vim /etc/fstab
/dev/hda5 /mnt/hda5 vfat defaults,iocharset=cp936, rw 0 0
4.7 挂载samba 分区
mkdir /mnt/share
mount -t smbfs -o username=root,password=abc,codepage=936,iocharset=gb2312//192.168.1.100/share /mnt/share
4.8 mount --bind
mount --bind 是将一个目录中的内容挂载到另一个目录上,用法是
mount --bind olddir newdir
取消挂载
mount --move olddir newdir
vim /etc/fstab
olddir newdir none bind 0 0
4.9 umount的时候老显示 device busy
umount -l /mnt/hda5
选项 –l 并不是马上umount,而是在该目录空闲后再umount。
————Blueicex 2020/03/10 18:20 blueice1980@126.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值