Scale-of-evaluation / daily-question

This repo is used to help you better understand the world,Enjoy!
MIT License
4 stars 2 forks source link

【07.27】Linux里如何来做挂载 #68

Open changjl317 opened 3 years ago

changjl317 commented 3 years ago

请在下面作答

BlacAmDK commented 3 years ago

Mount a temporary filesystem (TMPFS) of 4GB to '/mnt'. The contents will vanish when you reboot, but this can be very useful when working with things like bootstrap tarballs or temporary storages for sensitive data.
mount -t tmpfs -o mode=755,size=4096M tmpfs /mnt

To mount / partition as read-write in repair mode: mount -o remount,rw /

To bind mount path to a second location: mount --bind <source> <destination>

To mount Usb disk as user writable: mount -o uid=username,gid=usergroup /dev/sdx /mnt/xxx

To mount a remote NFS directory: mount -t nfs <host>:<remote-dir> <local-dir>

To mount an ISO: mount -o loop disk1.iso /mnt/disk

Show all mounted filesystems: mount

Mount a device to a directory: mount -t filesystem_type path/to/device_file path/to/target_directory

Mount a CD-ROM device (with the filetype ISO9660) to /cdrom (readonly): mount -t iso9660 -o ro /dev/cdrom /cdrom

Mount all the filesystem defined in /etc/fstab: mount -a

Mount a specific filesystem described in /etc/fstab (e.g. "/dev/sda1 /my_drive ext2 defaults 0 2"): mount /my_drive

Mount a directory to another directory: mount --bind path/to/old_dir path/to/new_dir

Derek-94tm commented 3 years ago

挂载文件系统,目前有两种方法,一是通过 mount 来挂载,另一种方法是通过/etc/fstab文件来开机自动挂载; 通过mount 来挂载磁盘分区(或存储设备) mount [-t 文件系统 ] [-o 选项] 设备 目录 注: -t 通过这个参数,我们来指定文件系统的类型,一般的情况下不必指定有时也能识加,-t 后面跟 ext3 、ext2 、reiserfs、vfat 、ntfs 等,其中 vfat 是fat32和fat16分区文件系统所所用的参数;如果您忘记了文件系统,也可以在-t 后面加auto ; -o 这个选项,主要选项有权限、用户、磁盘限额、语言编码等,但语言编码的选项,大多用于vfat和ntfs文件系统;由于选项太多,还是请您看看 man mount ;这里不多说;设备 指存储设备,比如/dev/hda1, /dev/sda1 ,cdrom 等...至于您的系统中有哪些存储设备,主要通过 fdisk -l 或者查看 /etc/fstab 或 dmesg ;一般的情况下光驱设备是/dev/cdrom ;软驱设备是/dev/fd0 ;硬盘及移动硬盘以 fdisk -l 的输出为准;

注意:“挂载点”的目录需要以下几个要求: (1)目录事先存在,可以用mkdir命令新建目录; (2)挂载点目录不可被其他进程使用到; (3)挂载点下原有文件将被隐藏。