Detailed explanation of basic knowledge of Linux operating system file system

Detailed explanation of basic knowledge of Linux operating system file system

1. Linux file structure The
  file structure is the organization method of files stored on storage devices such as disks. Mainly reflected in the organization of files and directories.
  Directories provide a convenient and efficient way to manage files.
  Linux uses a standard directory structure. During installation, the installer has created a file system and a complete and fixed directory composition for the user, and specified the role of each directory and the file types in it.
                      /root
                              ┃
┏━━┳━━━┳━━━┳━━╋━━━┳━━━┳━━┳━━━┓
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃
bin home dev etc lib sbin tmp usr var
                      ┃ ┃
                  ┏━┻━┓ ┏━━┳━━┳━━┳━┻━┳━━┓
                  ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃
                 rc.d cron.d X11R6 src lib local man bin
                  ┃                             
┏ ━━━┳━━┳━┻━┳━━━┓       
┃ ┃ ┃ ┃ ┃
init.d rc0.d rc1.d rc2.d …… linux bin lib src
  Linux uses a tree structure. The top layer is the root directory, and all other directories are generated from the root directory. Microsoft's DOS and Windows also use a tree structure, but in DOS and Windows, the root of such a tree structure is the drive letter of the disk partition. There are several tree structures in several partitions, and the relationship between them is juxtaposed. of. But in linux, no matter how many disk partitions the operating system manages, there is only one such directory tree. Structurally, the tree directories on each disk partition are not necessarily side by side.
  If this is not easy to understand, let me give an example:
  there is a hard disk, which is divided into 4 partitions, namely /; /boot; /usr and fat under windows
  For / and /boot or / and /usr, they are is a dependency; for /boot and /usr, they are side by side.
  If I mount the fat partition under windows to /mnt/winc, (mounting?? Oh, don't worry, hehe, I'll talk about it in a while, I'll talk about it in a while.) Then for /mnt/winc and /usr or As far as /mnt/winc and /boot are concerned, they are two branches that are subordinate to the directory tree without any relationship.
  Because linux is a multi-user system, formulating a fixed directory plan is helpful for unified management of system files and different user files. But this is the headache for many beginners who switch from windows to linux. The functions of some main directories under linux are listed below.
  /bin Binary executable commands
  /dev Device special files
  /etc System management and configuration files
  /etc/rc.d Configuration files and scripts for startup
  /home is the base of the user's home directory. For example, the user's home directory is /home/user. You can use ~user to represent the
  /lib standard programming library, also known as a dynamic link shared library, which acts like a .dll file in Windows
  /sbin system Management commands, here are the management programs used by system administrators
  /tmp public temporary file storage point
  /root system administrator's home directory (hehe, privileged class)
  /mnt This directory is provided by the system to allow users to temporarily mount other File system.
  /lost+found This directory is usually empty. The system shuts down abnormally and leaves a "homeless" file (what is called .chk under Windows) here
  . /proc The virtual directory is the mapping of system memory. This directory can be accessed directly to obtain system information.
  /var The overflow area of ​​some large files, such as log files of various services
  /usr The largest directory, almost all the applications and files used are in this directory. It contains:
  /usr/X11R6 The directory where X window is stored
  /usr/bin Numerous applications
  /usr/sbin Some management programs for superusers
  /usr/doc Linux documentation
  /usr/include Required for developing and compiling applications under linux Header file
  /usr/lib Commonly used dynamic link library and software package configuration file
  /usr/man Help document
  /usr/src Source code, the source code of the linux kernel is placed in /usr/src/linux
  /usr/local/ bin Locally added commands
  /usr/local/lib Locally added library
  2. Linux file system
  The file system refers to the physical space where files exist. Each partition in the Linux system is a file system with its own directory hierarchy. Linux will form these separate file systems belonging to different partitions into a general directory hierarchy of a system in a certain way. The operation of an operating system is inseparable from the operation of files, so it is necessary to have and maintain its own file system.
  The Llinux file system uses inodes to record file information, acting like the Windows file allocation table.
  An inode is a structure that contains information such as the length of a file, creation and modification times, permissions, ownership, and location on disk. A file system maintains an array of inodes, and each file or directory corresponds to a unique element in the inode array. The system assigns a number to each index node, that is, the index number of the node in the array, which is called the index node number.
The linux file system stores both the file inode number and the file name in the directory. So, a directory is just a table that combines the name of a file with its inode number, and each pair of file name and inode number in the directory is called a connection.
  For a file, there is a unique inode number corresponding to it, but for an inode number, there can be multiple file names corresponding to it. Therefore, the same file on disk can be accessed through different paths.
  You can use the ln command to establish a new connection to an existing file without copying the contents of the file. Connections are divided into soft connections and hard connections, and soft connections are also called symbolic connections. Their respective characteristics are:
  hard link: both the original file name and the connection file name point to the same physical address.
Directories cannot have hard links; hard links cannot span file systems (cannot span different partitions)
. There is only one copy of a file on the disk, saving hard disk space;
  since deleting a file can only succeed when the same inode belongs to the only connection, it can be Prevent unnecessary deletion by mistake.
  Symbolic link: Use the ln -s command to create a symbolic link to a file. A symbolic link is a kind of special Linux file. As a file, its data is the path name of the file it is connected to. Similar to the shortcut under Windows.
  You can delete the original file and save the connection file, but there is no function to prevent accidental deletion.
  The content of this paragraph is too abstract, and it is a node and an array. I have tried to make it as simple as possible, and it is not easy to add an example to demonstrate. If you are still in a fog, I have no choice but to remember it first, and then slowly experience and understand it in practical applications in the future. That's one way I've learned.
3. Mounting the file system
  As we know from the previous section, each partition in the Linux system is a file system and has its own directory hierarchy. Linux will form these separate file systems belonging to different partitions into a general directory hierarchy of a system in a certain way. The "in a certain way" mentioned here refers to the mount.
Mounting the top-level directory of one filesystem onto the subdirectories of another filesystem, making them a whole, is called mounting. Call this subdirectory the mount point.
For example:
  root partition:
  /root directory

┏━━━━┳━━━━━┳━━━━━┳━━━━╋━━━━━┳━━━━━┳━━ ━━━┳━━━━┓
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃
bin home dev etc lib sbin tmp usr var

┏━┻━┓
┃ ┃
rc.d cron.d

┏━━━┳━━ ━┳━┻━┳━━━━┓
┃ ┃ ┃ ┃ ┃
init.d rc0.d rc1.d rc2.d  …
  /usr partition:
  usr

┏━━━━┳━━╋━━━┳━━━┳━━━┓
┃ ┃ ┃ ┃ ┃ ┃
X11R6 src lib local man bin
┃ ┃
┃ ┏━━━╋━━ ━┓
┃ ┃ ┃ ┃ After the
linux bin lib src
  is mounted, the picture at the beginning of the article is formed. Does it look like it's hanging up?
  Note: 1. The mount point must be a directory.
  2. A partition is mounted on an existing directory. This directory may not be empty, but the previous content in this directory will not be available after mounting.
The same is true for mounts of filesystems established by other operating systems. But what needs to be understood is that the format of the file system used by CD-ROMs, floppy disks, and other operating systems is different from the file system format used by linux. CD is ISO9660; floppy disk is fat16 or ext2; windows NT is fat16, NTFS; windows98 is fat16, fat32; windows2000 and windowsXP are fat16, fat32, NTFS. Before mounting, it is necessary to know whether Linux supports the file system format to be mounted.
  Use the mount command when mounting:
format: mount [-parameter] [device name] [mount point]
  The commonly used parameters are
  -t to specify the file system type of the device. The common ones are:
  minix linux The earliest used file system
  ext2 linux The currently commonly used file system
  msdos MS-DOS fat is fat16
  vfat windows98 commonly used fat32
  nfs network file system
  iso9660 CD-ROM disc standard file system
  ntfs file system for windows NT 2000
  hpfs OS/2 file system
  auto auto-detect file system
  -o Specifies the option when mounting the file system. Some are also available in /etc/fstab. Commonly used are
  codepage=XXX code page
  iocharset=XXX character set
  ro mount
  rw in read-only mode mount
  nouser in read-write mode so that ordinary users cannot mount
  user can allow ordinary users to mount devices
  Remind that the mount command does not create a mount The function of the mount point, so you should make sure that the mount point already exists when you execute the mount command. (I don't understand? To put it bluntly, where do you want to mount the file system, you must first create a directory. Is this OK?)
  Example: Windows98 is installed in the hda1 partition, and there are floppy disks and CD-ROMs on the computer that need to be mounted.
  # mk /mnt/winc
  # mk /mnt/floppy
  # mk /mnt/cdrom
  # mount -t vfat /dev/hda1 /mnt/winc
  # mount -t msdos /dev/fd0 /mnt/floppy
  # mount -t iso9660 / dev/cdrom /mnt/cdrom
  Now you can enter /mnt/winc and other directories to read and write these file systems.
  To ensure that the last two lines of commands are correct, make sure there are disks in the floppy and CD-ROM drives. (If the disks of the hard disk can also be replaced at any time, I don't think I would make such a mistake :-> )
If there is a Chinese file name in your windows98 directory, after using the above command to mount, it will display a pile of gibberish. This uses the codepage iocharset option in the -o parameter. codepage specifies the code page of the file system, the Chinese code for Simplified Chinese is 936; iocharset specifies the character set, and cp936 or gb2312 is generally used for Simplified Chinese.
  When the mounted file system is not supported by Linux, mount must report an error, such as the ntfs file system of Windows 2000. The linux kernel can be recompiled to gain support for this filesystem. Regarding recompiling the linux kernel, I won't talk about it here.
  Fourth, automatic mount It
  is obviously too cumbersome to run the mount command every time you boot to access the windows partition, why not use the mount command to access other linux partitions?
  In fact, every time you boot up, linux automatically mounts the linux partition that needs to be mounted. So can we set the partition that we want to mount, such as the windows partition, to be mounted when linux starts, so as to realize the automatic mounting of the file system?
  This is totally possible. There is an fstab file in the /etc directory, which lists the list of file systems that are automatically mounted when linux is powered on. My /etc/fstab file is as follows:
  /dev/hda2 / ext3 defaults 1 1
  /dev/hda1 /boot ext3 defaults 1 2
  none /dev/pts devpts gid=5,mode=620 0 0
  none /proc proc defaults 0 0
  none /dev/shm tmpfs defaults 0 0
  /dev/hda3 swap swap defaults 0 0
  /dev/cdrom /mnt/cdrom iso9660 noauto,codepage=936,iocharset=gb2312 0 0
  /dev/fd0 / mnt/floppy auto noauto,owner,kudzu 0 0
  /dev/hdb1 /mnt/winc vfat defaults,codepage=936,iocharset=cp936 0 0
  /dev/hda5 /mnt/wind vfat defaults,codepage=936,iocharset=cp936 0 0
  In the /etc/fstab file, the first column is the device name of the mounted file system, the second column is the mount point, the third column is the type of the mounted file system, and the fourth column is the mounted option. Options are separated by commas. The fifth and sixth columns do not know what they mean, but I still hope that the experts will give guidance.
  In the last two lines, I manually added the C;D disk under Windows, and added codepage=936 and iocharset=cp936 parameters to support Chinese file names. The parameter defaults actually contains a set of default parameters:
  rw mount
  suid in read-write mode enable user ID and group ID set bit
  dev can interpret characters or block devices on the file system
  exec executable binary file
  auto auto mount
  nouser makes it impossible for normal users to mount
  async performs file system input and output operations in an asynchronous manner

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326395666&siteId=291194637