Mount

1. The concept of mounting

  1. For Windows, mount is to give a disk partition a disk symbol (C,D,E,...) . For example, if you insert a USB drive and the system automatically assigns it the H drive symbol, it is actually a mount, and the security eject of the USB drive is actually an unmount.
  2. For Linux, unlike Windows, which can have C, D, E, multiple directories, Linux has only one root directory /. When installing the system, all the zones we assign to linux are somewhere under /, such as /home, etc.
  3. insert a new hard disk and divide the new disk area sdb1. but it does not belong to / yet.
  4. we can find its location in some graphical desktop systems and browse to manage its files, but we can't access its directory at the command line, for example, we can't use cd or ls, and we can't specify a directory to operate on it at programming time.
  5. when using "mount /dev/sdb1 /mnt/", mount the new hard drive's partition sdb1 under the /mnt folder, after that accessing /mnt/ is equivalent to accessing the sdb1 partition. Any operation on /mnt/ is equivalent to the operation on the files in sdb1.
  6. So what mount does under Linux is mount a device (usually a storage device) to a directory that already exists. Accessing this directory is accessing that storage device.
  7. The linux operating system treats all devices as files, and it consolidates the resources of the entire computer into one large file directory. To access the files in a storage device, we must mount the partition where the files are located to an existing directory and then access the storage device by accessing that directory. Mounting is the process of putting the device in a directory, letting the system know how to manage the files in this device, and learning about the read/write characteristics of this storage device and so on.
  8. Don't we have /dev/sdb1, so we can operate on it directly? Isn't this its directory?
    It's not its directory. Although /dev is a directory, /dev/sdb1 is not a directory. You can find that ls /dev/sdb1 cannot be executed. /dev/sdb1 is something like a pointer to the raw data block of this partition. before mount, the system does not know which parts of this data block represent files and how to operate on them.
  9. Inserting a CD, the system actually executes "mount /dev/cdrom /media/cdrom" automatically. So you can manage the contents of the CD directly in /media/cdrom.

2. Mount/unmount commands

Mount syntax

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

(1) -t vfstype Specify the type of the file system, which is usually not necessary. mount will automatically select the correct type.

    Common types are
        CD-ROM or CD-ROM image: iso9660
        DOS fat16 file system: msdos
        Windows 9x fat32 file system: vfat
        Windows NT ntfs file system: ntfs
        Mount Windows file network share: smbfs
        UNIX (LINUX) file network share: nfs

(2) -o options is mainly used to describe how the device or file is mounted. Commonly used parameters are

     loop: used to mount a file as a hard disk partition on the system
     ro: use the read-only method to mount the device
     rw: mount the device in read-write mode
     iocharset: specify the character set used to access the file system

(3) device to mount (mount) the device

(4) dir device mount point on the system (mount point)

Unmount syntax

umount device file name or mount point

Mount the CD-ROM image file

mkdir /mnt/cdrom/

mount -t iso9660 /dev/cdrom /mnt/cdrom/

ll /mnt/cdrom/

To unmount a CD-ROM

umount /mnt/cdrom

posted @ 2023-05-19 16:53  LIANG2023  阅读(7)  评论(0)    收藏  举报