zl程序教程

您现在的位置是:首页 >  系统

当前栏目

Linux命令之mount详解程序员

Linux命令程序员 详解 mount
2023-06-13 09:20:05 时间

mount –a [-fFnrsvw] [-t vfstype] [-O optlist]

mount [-fnrsvw] [-o option[,option]…] device|dir

mount [-fnrsvw] [-t vfstype] [-o options] device dir

-t vfstype指定文件系统的类型,通常不必指定,mount会自动选择正确的类型

光盘或光盘镜像iso9660 

DOS fat16文件系统msdos 

Windows 9x fat32文件系统vfat 

Windows NT ntfs文件系统ntfs 

Mount Windows文件网络共享smbfs 

UNIX(LINUX)文件网络共享nfs

-o option主要用来描述设备或文件的挂载方式

device要挂载的设备

dir目录,设备在系统上的挂载点

 (1)常用选项

没错,就是什么都不跟,作用是列出所有被挂载的文件系统(还有type+类型) 

-l 列出所有被挂载的文件系统,包括卷标 

-h 打印帮助 

-V 打印版本信息 

-a 将/etc/fstab中定义的所有文件系统挂载 

-f 模拟挂载动作,但并不执行。通常用在除错。通常和-v一起使用 

-F 通常和-a一起使用,为每一个挂载动作产生一个行程负责执行。在系统需要挂载大量NFS文件系统时加快挂载动作 

-n 一般而言,挂载后会在/etc/mtab中写入一笔资料。但系统中没有可写入文件系统存在的情况下可以用这个选项取消动作 

-s-r 等于-o ro 

-v 详细模式 

-w 等于-o rw 

-o option单独拿出来,因为光这一项就蛮多的

defaults 使用预设的选项rw,suid,dev,exec,auto,nouser,async(把默认的都用上) 

async(defaults),sync 异步模式,同步模式 

同步模式下,内存的任何修改都是实时的同步到硬盘中,这种模式的安全性基本属于最高,但应为内存的数据基本一直在变化,所以这种模式会使的程序运行变得缓慢,影响效率。而异步模式虽然没有实时同步,但考虑日志文件系统的存在,所以安全性基本不用考虑,一步的效率会更高,所以普遍使用异步模式为默认。 

atime(defaults),noatime 是否在访问时更新atime 

当atime打开时,系统会在每次读取文件时更新文件的上次调用时间 

diratime(defaults),nodiratime 是否在目录访问时更新时间戳 

auto,noauto 打开/关闭自动挂载模式(是否在mount –a时被挂载) 

suid(defaults),nosuid 允许执行档在root权限下执行 

dev(defaults),nodev/exec(defaults),noexec允许执行挡被执行 

user,nouser(defaults) 使用者可以执行挂载/卸载动作 

ro/rw 只读模式/读写模式 

loop把一个文件当作硬盘分区挂载上系统 

remount把已挂载的文件系统重新用不同的方式挂载 

iocharset指定访问文件系统所用字符集 

注意:此选项对应/etc/fstab中的第四项

(2).实例

 1)挂载U 盘或移动硬盘

[[email protected] 桌面]# fdisk -l 

Disk /dev/sda: 107.4 GB, 107374182400 bytes 

255 heads, 63 sectors/track, 13054 cylinders 

Units = cylinders of 16065 * 512 = 8225280 bytes 

Sector size (logical/physical): 512 bytes / 512 bytes 

I/O size (minimum/optimal): 512 bytes / 512 bytes 

Disk identifier: 0x00079700 

 Device Boot Start End Blocks Id System 

/dev/sda1 * 1 64 512000 83 Linux 

Partition 1 does not end on cylinder boundary. 

/dev/sda2 64 13055 104344576 8e Linux LVM 

Disk /dev/sdb: 21.5 GB, 21474836480 bytes 

255 heads, 63 sectors/track, 2610 cylinders 

Units = cylinders of 16065 * 512 = 8225280 bytes 

Sector size (logical/physical): 512 bytes / 512 bytes 

I/O size (minimum/optimal): 512 bytes / 512 bytes 

Disk identifier: 0x00000000 

Disk /dev/mapper/vg_centos6-lv_root: 53.7 GB, 53687091200 bytes 

255 heads, 63 sectors/track, 6527 cylinders 

Units = cylinders of 16065 * 512 = 8225280 bytes 

Sector size (logical/physical): 512 bytes / 512 bytes 

I/O size (minimum/optimal): 512 bytes / 512 bytes 

Disk identifier: 0x00000000 

Disk /dev/mapper/vg_centos6-lv_swap: 4194 MB, 4194304000 bytes 

255 heads, 63 sectors/track, 509 cylinders 

Units = cylinders of 16065 * 512 = 8225280 bytes 

Sector size (logical/physical): 512 bytes / 512 bytes 

I/O size (minimum/optimal): 512 bytes / 512 bytes 

Disk identifier: 0x00000000 

Disk /dev/mapper/vg_centos6-lv_home: 49.0 GB, 48964304896 bytes 

255 heads, 63 sectors/track, 5952 cylinders 

Units = cylinders of 16065 * 512 = 8225280 bytes 

Sector size (logical/physical): 512 bytes / 512 bytes 

I/O size (minimum/optimal): 512 bytes / 512 bytes 

Disk identifier: 0x00000000 

Disk /dev/sdc: 31.0 GB, 31037849600 bytes 

32 heads, 63 sectors/track, 30069 cylinders 

Units = cylinders of 2016 * 512 = 1032192 bytes 

Sector size (logical/physical): 512 bytes / 512 bytes 

I/O size (minimum/optimal): 512 bytes / 512 bytes 

Disk identifier: 0x3e833261 

 Device Boot Start End Blocks Id System 

/dev/sdc1 * 1 30069 30309520+ b W95 FAT32 

[[email protected] 桌面]# mkdir /mnt/usb 

[[email protected] 桌面]# mount /dev/sdc1 /mnt/usb

当然有时候并不是一切都顺利的,在CentOS中没有办法直接挂载NTFS的U盘或移动硬盘,这是因为CentOS没有NTFS需要自行安装

wget https://tuxera.com/opensource/ntfs-3g_ntfsprogs-2017.3.23.tgz //下载速度太慢,可以用windows下载好拷贝过来 

tar -zxvf ntfs-3g_ntfsprogs-2017.3.23.tgz
cd ntfs-3g_ntfsprogs-2017.3.23 ./configure make make install //这里有可能提示缺少依赖关系,例如我的就是缺少gcc,装好后重新运行即可

当然这时候的挂载命令有着细小的变化

mount -t ntfs-3g /dev/sdc1 /mnt/usb 

2)挂载windows共享文件夹

[[email protected] 桌面]# mkdir -p /mnt/cifs 

[[email protected] 桌面]# mount -t cifs -o username=DT,password=Password0 //192.168.128.10/share /mnt/cifs/ 

 3)挂载新硬盘或分区

我单独写了一下,就是fdisk,格式化,最后挂载即可

http://www.cnblogs.com/diantong/p/8855683.html

4)挂载光盘

[[email protected] 桌面]# mkdir /mnt/cdrom 

[[email protected] mnt]# mount /dev/cdrom1 /mnt/cdrom 

mount: block device /dev/sr0 is write-protected, mounting read-only //只读 

 5)挂载光盘镜像

[[email protected] 桌面]# mkdir /mnt/vcdrom 

[[email protected] 桌面]# mount VM11/ toos/ linux.iso /mnt/vcdrom/ 

mount: /root/桌面/VM11 toos linux.iso is not a block device (maybe try `-o loop?) 

[[email protected] 桌面]# mount -o loop VM11/ toos/ linux.iso /mnt/vcdrom/ 

资料:

http://tutu.spaces.eepw.com.cn/articles/article/item/70737

http://www.runoob.com/linux/linux-comm-mount.html

http://www.178linux.com/85066

2848.html

服务器部署程序员系统优化网站设置运维