Linux System Architecture Detailed

Source: Internet
Author: User
Tags temporary file storage what file type

Linux systems generally have 4 main parts:

cores, shells, file systems, and Applications . The kernel, shell, and file systems together form a basic operating system structure that allows users to run programs, manage files, and use the system. Part of the hierarchy is shown in 1-1.

1. Linux kernel

Kernel is the core of the operating system, has many basic functions, it is responsible for managing the system's processes, memory, device drivers, files and network systems, determine the performance and stability of the system.

The Linux kernel consists of the following components: memory management, process management, device drivers, file systems, and network management.

Figure 1

system call Interface: The SCI layer provides some mechanism for performing function calls from user space to the kernel. This interface relies on architecture, even within the same processor family. The SCI is actually a very useful function call multiplexing and multi-channel decomposition service. In./linux/kernel you can find the implementation of the SCI and find the architecture-dependent parts in./linux/arch.

1. Memory Management

For any computer, its memory and other resources are limited. To allow limited physical memory to meet the application's large memory requirements, Linux uses a memory management approach called virtual memory. Linux divides memory into easy-to-handle "memory Pages" (4KB for most architectures). Linux includes ways to manage available memory, as well as the hardware mechanisms used by physical and virtual mappings.

However, memory management can manage more than 4KB buffers. Linux provides an abstraction of the 4KB buffer, such as the slab allocator. This memory management mode uses 4KB buffers as cardinality, then allocates structures from it, and tracks memory page usage, such as which pages are full, which pages are not fully used, and which pages are empty. This allows the pattern to dynamically adjust memory usage as required by the system.
In order to support the use of memory by multiple users, there are times when available memory is consumed by light. For this reason, the page can be moved out of memory and placed on disk. This process is called swapping because the page is swapped from memory to the hard disk. The source code for memory management can be found in./linux/mm.

2. Process Management

a process is actually a running entity for a particular application . In a Linux system, you can run multiple processes concurrently, and Linux achieves "multitasking" by running these processes in a short interval of time. This short time interval is called the "time Slice", the method that lets the process rotate is called "process Dispatch", the program that completes the dispatch is called dispatcher.

process scheduling controls the process's access to the CPU. When the next process needs to be selected to run, the scheduler chooses the process that is most worth running. A running process is actually a process that waits only for CPU resources, and if a process waits for another resource, the process is not running. Linux uses a relatively simple priority-based process scheduling algorithm to select a new process.

With a multi-tasking mechanism, each process can assume that only its own computer is exclusive, thus simplifying program writing. Each process has its own separate address space and can only be accessed by this process, so that the operating system avoids interference between processes and the possible harm that a "bad" program can cause to the system. In order to accomplish a particular task, it is sometimes necessary to synthesize the functions of two programs, such as one program output text and the other to sort the text. For this reason, the operating system also provides inter-process communication mechanisms to help accomplish such tasks. Common inter-process communication mechanisms in Linux are signals, pipelines, shared memory, semaphores, sockets, and so on.

The kernel provides an application programming interface (API) through the SCI to create a new process (fork, exec, or portable Operating System Interface [Posⅸ] function) to stop the process (kill, exit), and to communicate and synchronize between them (signal or posⅸ mechanisms).

3. File System

Unlike DOS and other operating systems, a separate file system in a Linux operating system is not identified by a drive letter or drive name (such as A: or C:, etc.). Conversely, like the UNIX operating system, the Linux operating system combines a separate file system into a hierarchical tree structure, and a separate entity represents the filesystem. Linux mounts a new file system to a directory with a "mount" or "hang" operation, allowing different file systems to be combined as a whole. An important feature of the Linux operating system is that it supports many different types of file systems. The most commonly used file system in Linux is Ext2, which is also a native Linux file system. However, Linux can also support different types of file systems, such as FAT, VFAT, FAT32, MINIX, and so on, which makes it easy to exchange data with other operating systems. Because Linux supports many different file systems, it organizes them into a unified virtual file system.

virtual file System (VIRTUALFILESYSTEM,VFS): hides the specifics of various hardware, separates file system operations from the specific implementation details of different file systems, provides a unified interface for all devices, VFS provides up to dozens of different file systems. Virtual file systems can be divided into logical file systems and device drivers. A logical file system is a file system supported by Linux, such as Ext2,fat, which refers to a device driver module written for each hardware controller.

The virtual file system (VFS) is a very useful aspect of the Linux kernel because it provides a common interface abstraction for the file system. VFS provides a switching layer between the SCI and the file systems supported by the kernel. That is, VFS provides a switch layer between the user and the file system.

VFS provides a switch layer between the user and the file system:

Above the VFS is a generic API abstraction for functions such as open, close, read, and write. Below the VFS is the file system abstraction, which defines how the upper function is implemented. These are plug-ins for a given file system (more than 50). The source code of the file system can be found in./linux/fs.

Below the filesystem layer is the buffer cache, which provides a common set of functions for the file system layer (independent of the file system). This cache layer optimizes access to physical devices by keeping the data for a period of time (or by reading the data in advance so that it is available as needed). Under the buffer cache is the device driver, which implements the interface for a particular physical device.

As a result, users and processes do not need to know the file system type in which the files reside, but only need to use them just like files in the Ext2 file system.

4. Device Drivers

Device drivers are a major part of the Linux kernel. Similar to the rest of the operating system, the device driver runs in a highly privileged processor environment, allowing direct manipulation of the hardware, but because of this, any device driver errors can cause the operating system to crash. The device driver actually controls the interaction between the operating system and the hardware device.

The device driver provides a set of operating systems that understand the abstraction of interface completion and the interaction between the operating system, and the specifics of hardware-specific operations are done by the device driver. In general, device drivers and device control chips, for example, if the computer hard disk is a SCSI hard disk, you need to use the SCSI driver instead of the IDE driver.

5. Network Interface (NET)

Provides access to a variety of network standards and support for a variety of network hardware. Network interface can be divided into network protocol and network driver. The Network Protocol section is responsible for implementing each of the possible network transport protocols. As is known to all, the TCP/IP protocol is the standard protocol for the Internet and is also the de facto industry standard.

The Linux network implementation supports BSD sockets and supports all TCP/IP protocols. The network portion of the Linux kernel consists of BSD sockets, network protocol layers, and network device drivers. The network device driver is responsible for communicating with the hardware device, and each of the possible hardware devices has a corresponding device driver.

2.Linux Shell

The shell is the user interface of the system and provides an interface for users to interoperate with the kernel. It receives the command entered by the user and sends it to the kernel to execute, which is a command interpreter. In addition, Shell programming languages have many features of common programming languages, and Shell programs written in this programming language have the same effect as other applications.

Currently, the following versions of the shell are mainly available.

1. Bourne Shell: It was developed by Bell Labs.
2. BASH: Is the GNU Bourne Again Shell, which is the default shell on the GNU operating system, and most Linux distribution kits use this shell.
3. Korn Shell: The development of the Bourne Shell, which is compatible with the Bourne shell in most of the content.
4. C Shell: Is the BSD version of Sun's shell.

3. Linux file system

A file system is an organization method that files reside on storage devices such as disks. Linux systems can support a variety of currently popular file systems such as EXT2, EXT3, FAT, FAT32, VFAT, and ISO9660.

3.1 File types

Linux The following file types are mainly:

1) Ordinary files : C-Language meta-code, shell scripts, binary executable files, etc. Divided into plain text and binary.
2) directory files : directories, the only place where files are stored.
3) linked file : A file that points to the same file or directory.
4) device files : Related to system peripherals, usually under/dev. Divided into block devices and character devices.
5) pipeline (FIFO) file: a way to provide process-building communication
6) Socket file: This file type is related to network communication

You can view information about the type of file by Ls–l, file, Stat, and several commands.

3.2 Linux Directory

A file structure is a method of organizing files on storage devices such as disks. Mainly embodied in the organization of files and directories.
The directory provides a convenient and effective way to manage files.

Linux uses a standard directory structure that, when installed, has created a file system for the user and a complete and fixed directory composition, specifying the role of each directory and the file types in it.

The complete directory tree can be divided into smaller sections, which can be stored on their own disks or partitions separately. In this way, relatively stable parts and frequently changing portions can be stored separately in separate partitions for easy backup or system management. The main parts of the directory tree are root,/usr,/var,/home, and so on (Figure 2). This layout makes it easy to share portions of the file system between Linux computers.

Figure 2

Linux uses a tree-based structure. The top level is the root directory, and all other directories are generated from the root directory.

Microsoft DOS and Windows also adopt a tree structure, but in DOS and windows such a tree structure root is the disk partition of the letter, there are several partitions there are several tree structure, the relationship between them is tied. At the top are different disks (partitions), such as: c,d,e,f, etc.

However, in Linux, there is only one directory tree that manages several disk partitions, regardless of the operating system. Structurally, the tree catalogs on each disk partition are not necessarily tied.

3.3 Linux Disk partitioning primary partitions, extended partitions, and logical partitions:

Linux partitions are different from Windows, and hard disks and hard disk partitions are represented as devices in Linux.

There are three types of hard disk partitions: Primary partition, extended partition, and logical partition.

The partitions of the hard disk are mainly divided into primary partitions (Primary partion) and extended partitions (Extension partion), and the sum of the primary and extended partitions cannot be greater than four.

Primary partition (Primary partion): can be used immediately but cannot be partitioned.

Extended partition (Extension partion): Must be partitioned before it can be used, meaning it must also be partitioned two times.

Logical Partitioning ((Logical partion)): A partition established by an extended partition. Logical partitions are not limited in number.

An extended partition is simply a "container" for a logical partition, and essentially only the primary and logical partitions are stored for data.

Second, identification of hard disk partitions under Linux

The identity of the hard disk partition is usually identified by using/dev/hd[a-z]x or/dev/sd[a-z]x, where [A-z] represents the hard disk number, and x represents the partition number within the hard disk.

Block number identification of the entire hard disk partition : Under Linux with HDA, HDB, SDA, SDB and so on to identify different hard drives;


IDE interface hard disk: expressed as/DEV/HDA1,/dev/hdb ... ;

SCSI interface hard disk, SATA interface hard disk is represented as/DEV/SDA,/dev/sdb ... ;

partition within the hard disk: If the value of X is 1 to 4, the primary partition (including the extended partition) of the hard disk, and the logical partition starting from 5, such as/DEV/HDA5 must be logical partition;

For example:

Use HDA1, Hda2, Hda5, Hda6 to identify different partitions. Where the letter a represents the first hard disk, B represents the second hard disk, and so on. The number 1 represents the first partition of a hard disk, 2 represents the second partition, and so on. 1 to 4 corresponds to a primary partition (Primary Partition) or an extended partition (Extension Partition). Starting with 5, the logical partition of the hard disk (Logical Partition) is the corresponding one. a hard disk even if there is only one primary partition, the logical partitions are numbered starting from 5, which should be given special attention.

Summary : A hard disk partition first to confirm on which hard disk, and then confirm which partition on the hard disk.

For/dev/hda similar representations, it is not lonesome to live it; we can find out whether the hard drive is/dev/hda or/dev/hdb in Linux through Fdisk-l;

[Email protected] ~]# fdisk-ldisk/dev/hda:80.0 GB, 80026361856 bytes255 heads, + sectors/track, 9729 cylindersunits = Cylinders of 16065 * 8225280 = bytesdevice Boot Start End Blocks Id system/dev/hda1 * 1 970 7791493+ 7 hpfs/ntfs/dev/ Hda2 971 9729 70356667+ 5 extended/dev/hda5 971 2915 15623181 b W95 fat32/dev/hda6 2916 4131 9767488+-LINUX/DEV/HDA7 41 5590 11719386 linux/dev/hda8 5591 6806 9767488+, linux/dev/hda9 6807 9657 22900626 linux/dev/hda10 9658 9729 57 8308+ Swap/solaris Linux

Please note that the first line, disk/dev/hda:80.0 GB, 80026361856 bytes, this means that there is only one hard disk device in the machine/dev/hda, the size of 80.0G, the following is the partition of the hard disk, each partition has detailed information, Not in detail here;

The relationship between disk partitions and directories under Linux is as follows:

– Any partition must be mounted on a directory.

– The directory is a logical distinction. Partitioning is a physical distinction.

– The disk Linux partition must be mounted to a specific directory in the directory tree for read and write operations.

– The root directory is where all Linux files and directories reside, and the previous disk partition needs to be mounted.

3.4 The function of the Linux main directory.

/bin binary Executable command
/dev Device Special files
/etc system administration and configuration files
/ETC/RC.D startup configuration files and scripts
The base point of the home user directory, such as the user's home directory is/home/user, can be represented by ~user
/lib Standard Programming Library, also known as dynamic Link shared library, acts like a. dll file in Windows
/sbin System Management commands, which are stored in the hypervisor used by the system administrator
/tmp Common temporary file storage point
/root system Administrator's home directory (hehe, privileged Class)
The/MNT system provides this directory to allow users to temporarily mount other file systems.
/lost+found This directory is usually empty, the system is not properly shut down and leave the "homeless" files (what is called under Windows. chk) right here.
/proc a virtual directory, which is a mapping of system memory. This directory can be accessed directly to obtain system Information .
/var overflow area for some large files, such as log files for various services
/usr The largest directory, the applications and files to be used almost all in this directory. These include:
/USR/X11R6 the directory where x window is stored
/usr/bin a multitude of applications
/usr/sbin Some management programs for super users
/usr/doc Linux Documentation
/usr/include the header files needed to develop and compile applications under Linux
/usr/lib Common dynamic-link libraries and package profiles
/usr/man Help Documentation
/USR/SRC source code, the Linux kernel source is placed in the/usr/src/linux
/usr/local/bin Local Add-on command
/usr/local/lib local additions to the library

3.5 Linux File System

The file system refers to the physical space in which a file exists, and each partition in a Linux system is a file system with its own directory hierarchy. Linux will form the overall directory hierarchy of a system in a way that is divided into separate file systems that belong to different partitions. An operating system can not operate without the operation of the file, so it is necessary to own and maintain their own file system.

1. File System type:

Ext2: File systems commonly used in early Linux
Upgraded version of EXT3:EXT2 with logging capability
RAMFS: Memory file system, fast
NFS: Network File system, invented by sun, primarily for remote file sharing
Ms-dos:ms-dos File System
Vfat:windows 95/98 file system used by the operating system
Fat:windows the file system used by the XP operating system
Ntfs:windows file system used by NT/XP operating system
File systems used by the HPFS:OS/2 operating system
PROC: Virtual Process file System
ISO9660: The file system used by most discs
File systems used by the Ufssun:os
File system used by the Ncpfs:novell server
Smbfs:samba Shared File system
XFS: Advanced log file system developed by SGI to support ultra-large capacity files
JFS:IBM the log file system used by AIX
ReiserFS: File system based on the balanced tree structure
UDF: rewritable data Disc File system

2. File system Features:

After the partition is complete, the partition needs to be formatted (format) before the operating system can use it. The purpose of formatting is to make the file system format available to the operating system (that is, we mentioned file system types above).

Each operating system can use a different file system. such as Windows 98 before the main use of the Microsoft operating system is FAT (or FAT16), the later version of Windows 2000 has the so-called NTFS file system, as for the Linux Orthodox file system is EXT2 (Linux second Exten Ded file System, EXT2FS) this one. In addition, the Windows operating system will not recognize Linux Ext2 by default.

In the traditional disk and file system application, a partition can only be formatted as a file system, so we can say that a filesystem is a partition. But due to the use of new technologies, such as LVM and software disk arrays (software RAID), which we often hear, these technologies can format a partition as multiple file systems (such as LVM), and also be able to synthesize multiple partitions into one file system (LVM, RAID)! So, at the moment, we're no longer talking about formatting for partition, and we can usually call a data file system instead of a partition that can be mounted.

So how does the file system work? This is related to the operating system's file data. The newer operating system's file data, in addition to the actual contents of the file, usually contains a lot of attributes, such as the Linux operating system file permissions (RWX) and file attributes (owner, group, time parameters, etc.). The file system typically stores the two parts of the data in separate chunks, with permissions and attributes placed in the inode, and the actual data is placed in the block. In addition, there is a super block (Superblock) that records the overall information of the entire file system, including the total number of inode and block, usage, surplus, etc.

For a disk partition, the entire partition is divided into 1024,2048 and 4096-byte chunks after it is designated as the appropriate file system. Depending on the use of the block, it can be divided into:

    1. Super Block (Superblock): This is the first block of space for the entire file system. This includes information about the entire file system, such as the block size, total amount of inode/block, usage, remaining amount, pointers to spatial inode and data blocks, and so on.
    2. Inode block (file index node): A file system index that records the properties of a file. It is the most basic unit of the file system and is the bridge of any subdirectory or file connected to the file system. Each subdirectory and file has only one inode block. It contains information about the basic properties of files in the file system (length of file, creation and modification time, permissions, affiliation), location of the data stored, and so on. Under Linux, you can view the Inode information for a file by using the "Ls-li" command. Hard connections and source files have the same inode.
    3. Block: The actual record of the contents of the file, if the file is too large, will occupy more than block. In order to improve the efficiency of directory Access, Linux also provides the dentry structure of the corresponding relationship between the expression path and the inode. It describes the path information and connects to the node Inode, which includes various directory information, and also points to inode and super blocks.

It's like a book with a cover, a table of contents, and a text. In the file system, the Super block is equivalent to the cover, from the cover can know the basic information of the book, the Inode block is equivalent to the directory, from the table of contents can know the location of the content, while the data block is equivalent to the text of the book, recording the specific content.

Linux Orthodox file systems (such as ext2, 3, and so on) partition the hard disk into chunks, inode table chunks, and data block regions. A file consists of a super block, Inode, and data region block. The inode contains the attributes of the file (such as read and write properties, owner, and pointers to the data block), and the data region block is the file content. When you view a file, the file attributes and data points are isolated from the Inode table and the data is read from the data block.

Ext2 File System

We use the Inode and block block plots to illustrate, as shown, the file system first format the Inode and block block, assuming that a file's attributes and permissions data is placed in the inode 4th (smaller squares), and this inode records the actual placement of file data points for 2, 7, 13, 15 of these four block numbers, at this time our operating system can arrange the reading order of the disk, can be a breath of four block content read out! Then the reading of the data is like the arrows specified in the shape.

Figure Inode/block Data Access

This method of data access is called an indexed file system (indexed allocation). is there any other idiomatic file system that can be compared? Yes, that's our usual flash drive (flash), the file system used in the flash drive is generally in FAT format. The FAT file system does not exist in this format, so fat has no way to read all blocks of the file from the beginning. Each block number is recorded in the previous block, which reads a bit like the following:

Figure, FAT file system data access

We assume that the data in the file is written sequentially to the four block numbers of the 1->7->4->15 number, but this filesystem has no way of knowing the number of four blocks in one breath, and he will have to read the block in a single time before he knows where the next block is. If the block that writes the same file data is too fragmented, our disk read head will not be able to read all the data on the disk, so the disk will be more than a few laps to complete the contents of this file!

do you often hear the so-called "defragmentation" ? The reason for defragmentation is that the block of file writes is too discrete, and the performance of the file reads becomes poor. This time can be through the defragmentation of the same file belongs to the blocks together, so that the data will be easier to read! Assuming that the FAT file system needs to be regularly defragmented, does Ext2 need disk re-use?

since EXT2 is an indexed file system , it is largely not necessary to defragment it frequently. However, if the file system is used too long, often delete/edit/Add files, then it is possible to cause the file data is too discrete problem, this time may need to be restructured. However, to be honest, brother Bird is not in the Linux operating system above the Ext2/ext3 file system defragmentation said! It doesn't seem to be necessary! ^_^

You can use the LN command to create a new connection to an already existing file without copying the contents of the file. The connection has the soft connection and the hard connection cent, the soft connection is also called the symbolic connection. Each of them is characterized by:

Hard Connect: Both the original file name and the connection file name point to the same physical address. The directory can not have a hard connection, hard connections can not cross the file system (not across different partitions) file on the disk only one copy, save hard disk space;
Because deleting a file succeeds when the same index node belongs to a unique connection, you can prevent unnecessary accidental deletions.

Symbolic Connection: establishing a symbolic connection for a file with the Ln-s command is a special file of Linux, and as a file, its data is the pathname of the file it is connected to. Like a shortcut under Windows.
Can delete the original file and save the connection file, there is no prevention of accidental deletion function.

This paragraph of the content is too abstract, but also the node is an array, I have tried to popular again, and not good examples for demonstration. If you are still foggy, I have no way, only first remember, in the future in the practical application of slowly experience, understanding. This is also my study of a method.

3.6 File system representation in the kernel

Kernel data structure

The VFS subsystem of the Linux kernel can be illustrated as follows:

File and IO: Each process maintains a file descriptor table in the PCB (process Control Block), which is the index of the list, each table entry has a pointer to the open file. Now let's be clear: The opened file is represented in the kernel with the file struct, and the pointer in the document descriptor table points to the file structure body.

Maintains the file Status Flag (member f_flags of the file struct) and the current read and write location in the file structure (member F_pos of the file struct). In, Process 1 and Process 2 both open the same file, but correspond to different file structure bodies, so you can have different file Status flags and read and write locations. The more important members of the file struct are the F_count, which represents the reference count (Reference count), which we'll talk about, which will cause multiple file descriptors to point to the same document struct, such as DUP, fork, and so on. For example, FD1 and FD2 both refer to the same file struct, then its reference count is 2, when close (FD1) does not release the file structure, but only the reference count to 1, if close (FD2), the reference count will be reduced to 0 while releasing the file structure, This really closed the file.

Each file struct points to a file_operations struct, the members of which are function pointers to kernel functions that implement various file operations. For example, in the user program read a file descriptor, read through the system call into the kernel, and then find the file descriptor pointed to the document structure, to find the structure of the file_operations, which is pointed to the body, Invokes the kernel function pointed to by its read member to complete the user request. In the user program calls Lseek, read, write, IOCTL, open and other functions, and ultimately by the kernel calls file_operations the members of the kernel function point to complete the user request.

The release member in the File_operations struct is used to complete the close request of the user program, which is called release instead of close because it does not necessarily close the file, but reduces the reference count, and only the reference count is reduced to 0 to close the file. For regular files that are open on the same file system, the steps and methods for file operations such as read, write, and so on, should be the same, and the calling function should be the same, so the file structure of the three open files in the diagram points to the same file_operations struct. If you open a character device file, then its read, write operation must be different from the regular file, not read and write disk data block, but read and write hardware devices, so the file structure should point to the various file_operations structure body, The various file manipulation functions are implemented by the driver of the device.

Each file struct has a pointer to the dentry struct, and "Dentry" is an abbreviation for the directory entry (directory entry). The arguments we pass to the open, stat, and other functions are a path, such as/home/akaedu/a, where the inode of the file needs to be found based on the path. To reduce the number of reads, the kernel caches the tree structure of the directory, called the Dentry cache, where each node is a dentry struct, as long as the dentry is searched along the parts of the path, from the root directory/to the home directory, then to the akaedu directory, and then to the file a. Dentry cache saves only recently accessed directory entries, and if the directory entry you are looking for is not in the cache, it will be read from disk to memory.

Each dentry struct has a pointer pointing to the INODE structure. The INODE structure holds the information read from the disk inode. In the example, there are two dentry, representing/home/akaedu/a and/home/akaedu/b, each pointing to the same inode, stating that the two files are mutually hard links. The inode structure holds information that is read from the inode in the partition, such as owner, file size, file type, and permission bit. Each inode struct has a pointer to the inode_operations struct, which is a set of function pointers that point to some kernel functions that complete the file directory operation.

Unlike File_operations, inode_operations points to a function that does not operate on a file, but functions that affect the layout of files and directories, such as adding deleted files and directories, tracking symbolic links, and so on. Each inode structure that belongs to the same file system can point to the same inode_operations struct.

The inode struct has a pointer to the Super_block struct. The Super_block structure holds information that is read from a super block on a disk partition, such as file system type, block size, and so on. The S_root member of the Super_block struct is a pointer to Dentry, indicating where the root directory of the filesystem is being mount, in which case the partition is mount to the/home directory.

The structure of file, Dentry, inode and Super_block constitute the core concept of VFS. For ext2 file systems, there is also the concept of inode and Super block on disk storage layouts, so it is easy to establish correspondence with the concepts in VFS. Other file system formats from non-UNIX systems (such as Windows FAT32, NTFS), may not have inode or Super block concept, but in order to mount to the Linux system, but also in the driver hard to gather, Looking at FAT32 and NTFS partitions under Linux will find that the permission bits are wrong, and all files are rwxrwxrwx, because they do not have the concept of inode and permission bit, which is hard to come out of.

3.6 Mounting The file system

Each partition in a Linux system is a file system with its own directory hierarchy. Linux will form the overall directory hierarchy of a system in a way that is divided into separate file systems that belong to different partitions. The word "in a certain way" means the mount.

Hang the top-level directory of one file system on a subdirectory of another file system, making them a whole, called mounts. Refer to this subdirectory as a mount point.

For example, to read a well-formatted partition, disc, or software on a hard disk, you must first map these devices to a directory, which is called a mount point, so that you can read these devices. After mounting, the physical partition details are screened out and the user has only a unified logic concept. Everything is a file.

Note: 1, mount point must be a directory.
2, a partition is mounted on an existing directory, this directory can not be empty, but the contents of the previous directory will not be available after mounting.

This is true for the mounting of file systems created by other operating systems. However, it is necessary to understand that the format of the file system used by the CD, floppy disk, and other operating systems is not the same as the file system format used by Linux. The disc is ISO9660, the floppy disk is FAT16 or Ext2;windows NT is FAT16, NTFS;WINDOWS98 is FAT16, fat32;windows2000 and WindowsXP are FAT16, FAT32, NTFS. Before mounting, see if Linux supports the file system format that you want to mount.

Mount when Mount command is used, format: Mount [-parameter] [device name] [Mount Point]

Among the parameters commonly used are
-t specifies the file system type of the device (what file type is mentioned)
-o Specifies the option to mount the file system. Some are also available in/etc/fstab. Commonly used to have

CODEPAGE=XXX code page
Iocharset=xxx Character Set
RO mount in read-only mode
RW mount in read-write mode
Nouser makes it impossible for ordinary users to mount
User can mount a device to a normal user

For example:

1. Mount the file system for Windows:
1) First we use sudo fdisk-l to view mounted devices, such as the bottom:/dev/hda5
2) mkdir Create a directory where the directory is to be hung in the directory, that is, you want to put the e-disk into this directory: Mk/mnt/winc
3) Windows and Linux are not using a file system, typically Linux does not mount the Windows file system, so you manually mount:
# mount-t Vfat/dev/hda5/mnt/winc (-t vfat points out the file system FAT32 here)
You are now ready to read and write these files into directories such as/mnt/winc.

2. Mount Disc: # Mk/mnt/cdrom
# mount-t Iso9660/dev/cdrom/mnt/cdrom (the name of the switch is usually CDROM, this command is generally common)

3. Virtual Machine shared folder: For example, under VirtualBox, the host is Windows,ubuntu is guest. It is divided into three steps:

1). First install the Virtual Computer Toolkit: In the VirtualBox menu, select "Device", "Install the virtual computer Kit", you will find the Ubuntu desktop with a more disc icon, this disc is automatically loaded into the folder/media/cdom0 by default, and/ CDROM automatically points to this folder. By default, the File Manager will automatically open this disc and you will see a "" file in it. Open a command-line terminal, enter "Cd/cdrom" and "sudo sh./", without double quotes, to begin the installation of the toolkit. After installation, you will be prompted to restart Ubuntu in English, it is recommended to restart immediately. After rebooting, the obvious change is that the mouse is in shared mode, and the Clipboard is shared with Windows. If there are these changes, the Virtual Machine Toolkit has been installed successfully.

2). Next set up the shared folder.
In the Shared Folder Settings window, click "Add a Shared folder" on the right, the path to choose the Windows folder you want to share, the share name whichever one you like, such as "myshare", the option read-only is to allow only Ubuntu to read this folder, Please select this option as needed.

3). Mount this shared folder under Ubuntu: sudo mount-t vboxsf myshare/media/share
where "MyShare" is the name of the shared folder previously taken, "/media/share" is the target file to mount.

3.7 Automatically mount Windows partitions

It's obviously too cumbersome to run the Mount command every time you access the Windows partition, why not use the Mount command to access other Linux partitions?

In fact, Linux automatically mounts the Linux partitions that need to be mounted on each boot. So can we set Linux to mount the partitions we want to mount, such as Windows partitions, when booting up, to automatically mount the file system?

This is perfectly possible. There is a 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
/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 mounted file system type, the fourth column is the Mount option, and the options are separated by commas. The 56th column does not know what to mean, but also looks at the expert pointing.

The last two lines are the c;d disks that I added manually under Windows, plus the codepage=936 and iocharset=cp936 parameters to support Chinese filenames. The parameter defaults actually contains a set of default parameters:
RW is mounted in read/write mode
SUID Open User ID and group ID setting bit
Dev interprets character or block devices on a file system
EXEC executable binary file
Auto Mount automatically
Nouser makes it impossible for ordinary users to mount
Async performs a file system's input-output operation in an unsynchronized manner

As you can see in this list, the optical drive and floppy drive are not mounted automatically and the parameters are set to Noauto. (If you want to set the automatic mount, you have to make sure that every time you turn on the CD-ROM drive and floppy disk, hehe.) )

3.8. Soft connection, Hard link

You can use the LN command to create a new connection to an already existing file without copying the contents of the file. The connection has the soft connection and the hard connection cent, the soft connection is also called the symbolic connection. Each of them is characterized by:
Hard Connect: is a copy of the file, both the original file name and the connection file name point to the same physical address. The directory can not have a hard connection, hard connections can not cross the file system (not across different partitions) file on the disk only one copy, save hard disk space;

Modify one, and the file to which it is connected is modified at the same time. If you delete any of the remaining files, it will not be affected.
Because deleting a file succeeds when the same index node belongs to a unique connection, you can prevent unnecessary accidental deletions.
Symbolic connection (soft connection): establishing a symbolic connection for a file with the Ln-s command is a special file of Linux, and as a file, its data is the pathname of the file it is connected to. Like a shortcut under Windows.
Of course, the deletion of this connection will not affect the source file, but the use of the connection file, reference is directly called the source file.

The specific relationship can be seen:

Figure 5: Soft links and hard links

The difference between a hard link and a soft link can be seen from the diagram:

1: The inode number of the hard link original file and the new file is the same. and soft links are different.

2: Deleting the original file causes soft links to be unavailable, and hard links are not affected.

3: The original file modification, soft and hard link file content is also modified, because all points to the same file content.

3.9. File Directory Management commands

disk and file space:fdisk df du

file directory and management: CD pwd mkdir rmdir LS CP RM MV

View file Contents Cat, TAC, more, less, head, tail

file directories and permissions:chmod chown chgrp umask

file Lookup:which, Whereis, locate, find, find

4. Linux Applications

Standard Linux systems generally have a set of assemblies called applications, including text editors, programming languages, X windows, Office suites, Internet Tools, and databases.

5. Linux Kernel parameter optimization

The kernel parameter is an interface between the user and the system kernel, through which the user can dynamically update the kernel configuration while the system is running, and these kernel parameters are available through the Linux proc file system. Therefore, you can optimize the performance of Linux by adjusting the proc file system.

Linux System Architecture Detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.