As a developer or geek, Linux deserves your high profile. This article describes the introduction and structure of Linux and introduces you to the sexy Linas lady

What is Linux?

If you’ve never touched Linux before, it’s probably not clear why there are so many different distributions of Linux. When you look at Linux packages, you’re bound to get confused by terms like distribution, LiveCD, and GNU. Entering the Linux world for the first time can feel a little awkward. Before you dive into commands and scripts, this chapter will demystify Linux a little. First,Linux can be divided into the following four parts:

  1. ↪ Linux kernel
  2. ↪ GNU toolchain
  3. ↪ GUI desktop environment
  4. ↪ Application software…
| -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | | APPS application software | | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | | | | | GUI GUI desktop -- -- -- -- -- -- -- -- -- -- -- -- - | | | | GNU The GNU tool chain | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | | kernel | Linux kernel | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | | hardware | computer hardware ----------------------------Copy the code


1. The Linux kernel

The core of a Linux system is the kernel. The kernel controls all hardware and software on a computer system, allocating hardware when necessary, and executing software as needed.

  1. System Memory Management
  2. Application Management
  3. Hardware Device Management
  4. File System Management

1. Manage system memory

One of the main functions of the operating system kernel is memory management. The kernel not only manages the physical memory available on the server, but also creates and manages virtual memory (that is, memory that doesn’t actually exist)

  • The kernel implements virtual memory through storage space on the hard disk, which is called swap space. The kernel constantly swaps the contents of virtual memory back and forth between swap space and actual physical memory. This makes the system think it has more memory available than physical memory

  • Linux memory mapping

| -- -- -- -- -- -- -- -- - | -- -- -- -- -- -- -- -- -- -- - | | | physical memory | | | / -- -- -- -- -- -- -- -- -- - | | -- -- -- -- -- -- -- -- - | core virtual memory | -- - | | | | -- -- -- -- -- -- -- -- - | | \ -- -- -- -- -- -- -- -- -- - | | Exchange space | | | -- -- -- -- -- -- -- -- - | -- -- -- -- -- -- -- -- -- -- -Copy the code

2. Application management

The Linux operating system calls a running program a process. Processes can run in the foreground, displaying output on the screen, or in the background, hiding behind the scenes. The kernel controls how the Linux system manages all the processes running on it.

  • The kernel creates the first process (called the init process) to start all the other processes on the system. When the kernel starts, it loads the init process into virtual memory. When the kernel starts any other process, it allocates a dedicated area of virtual memory to the new process to store the data and code used by the process.

  • The Linux operating system has five boot runlevels

    • At runlevel 1, only the basic system process and one console terminal process are started. We call this the single-user model. Single-user mode is usually used for emergency file system maintenance in the event of a system problem. Obviously, in this mode, only one person (usually the system administrator) can log on to the system to manipulate data.
    • The standard startup run level is 3. At this runtime level, most applications, such as network support programs, start.
    • A common runlevel in Linux is 5. At this runtime level the graphical X Window system is launched, allowing users to log in to the system through a graphical desktop Window.

3. Manage hardware devices

The kernel is also responsible for managing hardware devices. Any device with which the Linux system needs to communicate needs to include its driver code in the kernel code. Driver code acts as a middleman between the application and the hardware device, allowing data to be exchanged between the kernel and the device. There are two ways to insert device driver code in the Linux kernel:

  • Device driver code compiled into the kernel
  • A device driver module that can be inserted into the kernel

Previously, the only way to plug in device driver code was to recompile the kernel. Every time a new device is added to the system, the kernel code is recompiled. As the Linux kernel supports more and more hardware devices, this process becomes increasingly inefficient. Fortunately, Linux developers have devised a better way to plug driver code into a running kernel.

Developers came up with the concept of kernel modules. It allows driver code to be inserted into the running kernel without recompiling the kernel. The kernel module can also be removed from the kernel when the device is no longer in use. This approach greatly simplifies and extends the use of hardware devices on Linux.

  • Linux systems treat hardware devices as special files, called device files. There are three types of device files:

    • Character device file
      • Character device files are devices that process data one character at a time. Most types of modems and terminals are created as character device files.
    • Block device file
      • Block device files are devices that can process large chunks of data at a time, such as hard disks.
    • Network device File
      • Network device files are devices that use packets to send and receive data, including various network cards and a special loopback device. This loopback device allows the Linux system to communicate with itself using common network programming protocols.
  • Linux creates a special file called a node for each device on the system. All communication with the device is done through the device node. Each node has a unique pair of values for the Linux kernel to identify. A value pair consists of a primary device number and a secondary device number. Class devices are grouped under the same main device number. Secondary device ID Identifies a specific device in the primary device group.

4. File system management

Unlike some other operating systems, the Linux kernel supports reading and writing data from hard disks through different types of file systems. In addition to its own file systems,Linux also supports reading and writing data from file systems used by other operating systems, such as Microsoft Windows. The kernel must include support for all possible file systems at compile time. Table 1-1 lists the standard file systems used for reading and writing data in Linux.

Ext | Linux extended file system, however the earliest Linux file system | second extended file system, on the basis of the ext provides more functionality ext3 | third extended file system, support logging corruption | the fourth extended file system, support advanced logging HPFS | OS/2High-performance JFS file system | IBM log file system either iso9660 | ISO9660File system (cd-rom) minix | minix file system msdos | Microsoft FAT16 NCP NFS | | Netware file system network file system is NTFS support | Microsoft NT proc file system | access system information ReiserFS | advanced Linux file system, which can provide better performance and hard disk recovery feature SMB | Samba SMB file systems that support the network access sysv | earlier Unix file system it | umsdos BSD file system | Built on msdos Unix file system vfat | Windows95XFS file system (FAT32) | high performance64Bit log file systemCopy the code
  • All disks accessed by the Linux server must be formatted into one of the file system types listed in Table 1-1.
  • The Linux kernel uses a Virtual File System (VFS) as its interface for interacting with each File System. This provides a standard interface for the Linux kernel to communicate with any type of file system. As each file system is mounted and used, the VFS caches information in memory.


2. GNU Toolchain

The GNU organization (GNU stands for GNU’s Not Unix) developed a complete set of Unix tools, but no kernel system to run them. These tools were developed under a software concept called Open Source Software (OSS).

The concept of open source software allows programmers to develop software and distribute it for free. Anyone can use, modify, or integrate the software into their own systems without paying any licensing fees. Combine Linus’ Linux kernel with GNU operating system tools, and you have a complete, feature-rich, free operating system.

  • Although the combination of the Linux kernel and GNU tools is commonly referred to as Linux, you will also see Linux purists on the Internet refer to it as the GNU/Linux system, in recognition of the contributions of the GNU organization

Core GNU tools

The GNU Coreutils software package consists of three parts:

  • A tool for processing files
  • A tool for manipulating text
  • Tools for managing processes

Shell

The GNU/Linux shell is a special kind of interactive tool. It provides users with a way to start programs, manage files in the file system, and processes running on Linux systems. At the heart of the shell is the command line prompt. The command-line prompt is the interactive part of the shell. It allows you to enter a text command, then interpret the command and execute it in the kernel.

  • The commands we type on the command line are provided by the GNU toolchain, not the Linux kernel
  • The default shell for all Linux distributions is the Bash shell. Bash Shell was developed by the GNU Project as an alternative to the standard Unix shell, the Bourne shell(named after its creator).
  • Several different shells that are common in Linux
Bash | developed by the GNU project, be regarded as the standard shell ash | run in memory constrained environment simple, lightweight shell, but with the bash shell is fully compatible with korn | and Bourne Shell, shell compatible programming but support such as an associative array and floating point arithmetic some high-level programming features it | will be introduced to the elements of the C language shell in the shell script ZSH | An advanced shell that combines the features of bash, TCSH, and Korn while providing advanced programming features, shared history files, and themed promptsCopy the code

3. Linux desktop environment

In Linux’s early days (the early 1990s), all that worked was a simple Linux OS text interface. This text interface allows system administrators to run programs, control their execution, and move files around the system.

With the spread of Microsoft Windows, computer users are no longer content to work on old-fashioned text interfaces. This has led to more development activity in the OSS community, resulting in a Linux graphical desktop environment.

  • The X Window system

There are two basic elements that determine the video environment: the graphics card and the display. To display gorgeous graphics on a computer,Linux software needs to know how to communicate with both. X Window system is a core part of graphic display.

X Window system, is directly and THE PC on the graphics card and monitor to deal with the bottom procedures. It controls how Linux programs display beautiful Windows and graphics on the computer

  • Popular desktop environments now haveUnity GNOME Cinnamon Xfce




Linux distributions

Now that you know the four key components needed to make a complete Linux system, you’re probably wondering how you can put them together. Fortunately, someone has done it for you


Core Linux distributions

The core Linux distribution contains the kernel, one or more graphical desktop environments, and precompiled almost every Linux application in sight. It provides a one-stop complete Linux installation

Slackware | one of the earliest Linux distributions, popular in the Linux geeks Redhat | commercial distribution is mainly used for Internet server Gentoo | designed for senior Linux user distribution, contains only Linux source packages | distributions on commercial and household Debian | in the Linux experts and commercial Linux products popular distributionsCopy the code


The system catalog

|—— bin             # binary directory for user-level GNU tools (bash command)| - the bootThe boot directory is used to store various files used during system boot
|—— dev             Device directory, store hardware devices, create device nodes
|—— etc             The system configuration file directory is used to store system management and configuration files
|—— home            # home directory for ordinary users
|—— lib             Library directory, a dynamically linked library for systems and applications| - lost + found# This directory is usually empty, and the system shuts down abnormally, leaving "homeless" files
|—— media           Media directory, a common mount point for removable media devices| - MNTMount directory, another common mount point for removable media devices
|—— opt             Optional directory for storing third-party software packages and data files
|—— proc            The process directory, which stores information about existing hardware and current processes, is a mapping of system memory. You can access this directory directly to obtain system information
|—— root            The home directory of the superuser
|—— run             Run directory, which stores runtime data while the system is running
|—— sbin            System binary directory, which houses many GNU administrator level tools| - the SRVThe service directory is used to store files related to local services
|—— sys             System directory, store system hardware information related files| - TMPTemporary directory in which temporary working files can be created and deleted, and then cleared after a restart
|—— usr             User binary directory, where a large number of user-level GNU tools and data files are stored
|   |—— bin         Contains executables for the system installation. Typically, this directory will contain many programs
|   |—— games       # 
|   |—— include     # Some header files needed to write the program
|   |—— lib         Contains shared libraries used by programs in the /usr/bin directory| | -local       The installation directory of a program that comes with a non-system distribution but is intended to be used by the system. Typically, programs compiled from source code are installed in the /usr/local/bin directory
|   |—— sbin        Contains many hypervisors
|   |—— share       Save help files and shared files| | - SRC# 
|—— var             Mutable directory for files that change frequently, such as log files
Copy the code


File permissions – Permission characters

  • Command line execution:ls -l
drwxr-xr-x

File type belongs to sovereign limit member permission Other user permissionD RWX r - r - x x | - file type | | -- -# file
|   |—— d # folder
|   |—— l # link
|   |—— c # Character device
|   |—— b # block device
|   |—— n # Network equipment
|
|—— r Read permission| - w.Write permission
|—— x # execute permission
Copy the code


The file system

  • ext

The first filesystem introduced in Linux was called an extended filesystem (ext for short). It provides Linux with a basic Unix-like file system that uses virtual directories to operate hardware devices and stores data in fixed-length chunks on physical devices.

The Ext file system uses a system called index nodes to hold information about files stored in a virtual directory. The index node system creates a separate table (called the index node table) in each physical device to store information about these files. Each file stored in the virtual directory has an entry in the index node table. The extended part of the ext file system name comes from additional data for each file it tracks

- File name - File size - File owner - File owner group - File access permission - Pointer to each hard disk block that stores file dataCopy the code

Linux refers to each index node in the index node table by a unique value (called the index node number) that is assigned by the file system when the file is created. File systems identify files by inode numbers rather than by full file names and paths.

  • ext2

The original Ext file system had some limitations, such as limiting file sizes to 2 GB. Shortly after the advent of Linux, the Ext file system was upgraded to a second-generation extended file system called ext2

Log file system

Journaling file systems add a layer of security to Linux systems. Instead of writing the data directly to the storage device and then updating the index node table, it writes the changes to the file to a temporary file (called a journal)

After the data is written to the storage device and the index node table, delete the corresponding log entry. If the system crashes or fails before data can be written to the storage device, the log file system reads the log file next time and processes the unwritten data left over from the last time

  • ext3

The ext3 file system was introduced into the Linux kernel in 2001 and until recently was the default file system for almost all Linux distributions. It uses the same index node table structure as the ext2 file system, but adds a log file to each storage device to log data that is ready to be written to the storage device.

  • ext4

The ext4 file system was officially supported by the Linux kernel in 2008 and is now the default file system for most popular Linux distributions

In addition to data compression and encryption, the ext4 file system supports a feature called extents. Extents allocate space by block on the storage device, but only hold the location of the starting block in the index node table. Because you don’t have to list all the data blocks used to store the data in the file, it saves some space in the index node table.

Ext4 also introduced block preallocation. If you want to reserve space on a storage device for a file that you know is going to get bigger, the ext4 filesystem can allocate all the blocks that the file needs, not just the ones that are already in use. The ext4 file system fills reserved blocks of data with zeros and does not allocate them to other files

In Linux LVM

Linux LVM was developed by Heinz Mauelshagen and released to the Linux community in 1998. It allows you to manage a complete logical volume management environment on Linux with simple command line commands

  • LVM1

The original LVM package was released in 1998 and was only available for version 2.4 of the Linux kernel. It provides only basic logos

  • LVM2

A newer version of LVM, available for Linux kernel version 2.6. It provides additional functionality in addition to standard LVM1 functionality.

  • The snapshot

The original Linux LVM allowed you to copy a logical volume to another device while it was online. This feature is called snapshot. Snapshots are useful when backing up important data that cannot be locked due to high reliability requirements. Traditional backup methods typically lock files when copying them to backup media. Snapshots allow you to keep a mission-critical Web server or database server working while you replicate. Unfortunately LVM1 only allows you to create read-only snapshots. Once a snapshot is created, nothing can be written

LVM2 allows you to create read-write snapshots of online logical volumes. With a read-write snapshot, you can delete the original logical volume and mount the snapshot as a substitute. This feature is useful for fast failover or for program trials that involve modifying data and need to recover the modified data if they fail.

  • striping

Another compelling feature that LVM2 provides is striping. With striping, logical volumes can be created across multiple physical disks. When Linux LVM writes a file to a logical volume, the data blocks in the file are spread across multiple disks. Each subsequent block of data is written to the next hard drive. Striping helps drive performance because Linux can simultaneously write multiple blocks of data from a file to multiple drives without waiting for a single drive to move read/write heads to multiple locations. This improvement also applies to sequential files, since LVM can read data from multiple disks at the same time.

  • The mirror

Just because a file system is installed through LVM doesn’t mean it won’t have problems again. Like physical partitions,LVM logical volumes are vulnerable to power outages and disk failures. Once a file system is corrupted, it may never be restored.

The LVM snapshot feature provides some comfort that you can create a backup copy of a logical volume at any time, but it may not be enough for some environments. For systems that involve large data changes, such as a database server, hundreds or thousands of records may be stored since the last snapshot.

One solution to this problem is LVM mirroring. A mirror is a full copy of a logical volume that is updated in real time. When you create a mirrored logical volume,LVM synchronizes the original logical volume to the mirror copy. Depending on the size of the original logical volume, this may take some time to complete.

Once the original synchronization is complete,LVM performs two writes for each write to the file system — one to the primary logical volume and one to the mirror copy. As you can imagine, this process degrades the write performance of the system. Even if the original logical volume is corrupted for some reason, you already have a complete and up-to-date copy!


summary

Using storage devices on Linux requires a little knowledge of file systems. Knowing how to create and manipulate file systems from the command line can help when working on Linux. Linux differs from Windows in that the former supports a large number of different ways of storing files and directories. Each file system approach has different features that make it suitable for different scenarios

Using the fdisk command, you can partition a storage device to install a file system. When partitioning a storage device, you must define what type of file system to use on it. After you have partitioned the storage device, you can choose a file system for the partition. Popular Linux file systems include ext3 and ext4. Both provide journaling file system functionality, reducing their chances of experiencing errors or problems in the event of a Linux system crash

One of the limitations of creating a file system directly on a storage device partition is that you can’t easily resize the file system if your hard drive runs out of space. But Linux supports logical volume management, which is a way to create virtual partitions across multiple storage devices. This approach allows you to easily extend an existing file system without completely rebuilding it. The Linux LVM package provides command-line commands to create logical volumes across multiple storage devices.


If there is anything wrong or wrong, please correct itCopy the code