<Laruence private dish> record
Chapter 2 Introduction to computer
- CPU type
CPU is mainly divided into two types: simplified instruction set-defined memory (PROTEUS) and Complex Instruction Set-defined memory (CISC.
For simplified instruction sets, common series include the sun series, IBM's PowerPC series, and arm series.
Complex Instruction sets mainly include AMD, Intel, and via x86 series CPUs
Chapter 2 host planning and disk partitioning
1. Disk Introduction
The first sector of the entire disk is particularly important. It records two important information:
(1) MBR (Master Boot Record) Main Boot Record area: where the boot management program can be installed, there are 446 bytes
(2) Partition Table: records the partition status of the entire disk, with 64 bytes
MBR is very important. The system should actively read the content of this partition during boot so that it can know how to boot the system.
2. Disk Partition Table
In the 64-bytes capacity of the partition table, there are four groups of record areas. Each record area records the start and end magnetic column numbers of the segment. If you look at the hard disk in a long bar and then the column, then the 64 bytes record segment is a bit like the bottom:
If the above hard drive device file is named/dev/hda, the device file name obtained in Linux is as follows:
P1:/dev/hda1
P2:/dev/hda2
P3:/dev/hda3
P4:/dev/hda4
Because the partition table only has 64 bytes, it can only accommodate a maximum of four partition records. The records of these four partitions are called primary or extended partition slots. Based on the illustration and description above, we can get the following key information:
(1) In fact, the so-called "partition" is only for the 64 bytes partition table!
(2) by default, the partition table on the hard disk can only write information about four partitions.
(3) The information of these four groups is called the primary partition or extended partition slot.
(4) the smallest unit of the partition slot is cylinder)
(5) When the system needs to write data to the disk, it must refer to the disk partition table to process data in a partition slot.
3. Benefits of disk partitioning
(1) Data Security
(2) system efficiency considerations
The binning slot is used to move the data in the segment of a column. For example, the first slot in the two column number 1 ~ 100, so when there is data to be read from the partition slot, the disk will only search for the first 1 ~ 100 of the magnetic column range, because the data is concentrated, will be conducive to the speed and efficiency of data reading! Therefore, partitioning is very important!
4. Extended partitions
If you want more than 4 partitions, you can use the extended partitions to divide them. The four partitions mentioned above can be divided as the primary partition or extended partition.
Among them, we know that the four partition record areas of the hard disk only use two, P1 is the main partition, and P2 is the extended partition.
Note that the purpose of an extended partition is to use an additional sector to record the partition information. The extended partition itself cannot be formatted. However
Then we can continue to record the partition through the block to which the extended partition points.
Similarly, the device file names of the above partition slots in Linux systems are as follows:
P1:/dev/hda1
P2:/dev/hda2
L1:/dev/hda5
L2:/dev/hda6
L3:/dev/hda7
L4:/dev/hda8
L5:/dev/hda9
The partition termination is as follows:
The features of main partitions, extended partitions, and logical partitions are as follows:
(1) A maximum of four primary and extended partitions are allowed (Hard Disk restrictions)
(2) A maximum of one extended partition can be created (Operating System Restrictions)
(3) logical partitions are the partition slots continuously cut out by extended partitions;
(4) After being formatted, the partition slot used as the primary partition and logical partition for data access. Extended partitions cannot be formatted;
(5) The number of logical partitions varies according to the operating system. In Linux, the IDE Hard Disk can have a maximum of 59 logical partitions (numbers 5 to 63 ), the SATA hard drive has 11 logical partitions (numbers 5 to 15 ).
5. Boot Process and main startup record area (MBR)
To put it simply, the actions taken before the entire boot process reaches the operating system are as follows:
(1). BIOS: the first device that can be started will be recognized when the firmware is automatically executed during startup;
The BIOS will analyze the storage devices in the computer. Taking the hard disk as an example, the BIOS will obtain the hard disk that can be turned on based on the user's settings, and read the MBR location of the first sector from the hard disk. MBR, which has only 446 bytes of hard disk capacity, will be placed with the most basic boot Management Program. At this time, the BIOS is complete, and the next step is the work of the boot Management Program in MBR.
(2). MBR: The main startup record block in the first sector of the first device that can be started, which contains the boot management program;
(3) Boot Loader: a software that can read core files for execution;
The purpose of this boot Management Program is to load the core file, because the boot management program is provided by the operating system during installation, so he will know the file system format in the hard disk, so he can read the core file, and then the Core File work will be completed after the boot.
(4). Core File: Start operating system functions...
From the above description, we will know that bios and MBR are both functions supported by the hardware, and boot loader is a set of software installed on MBR by the operating system. Since the MBR only has 446 bytes, this boot management program is very small and beautiful. The main components of this boot loader are the following:
(1) menu provided: users can select different boot items, which is also an important feature of Multi-boot!
(2) load the core file: directly point to the program segment that can be started to start the operating system;
(3) transfer to other loaders: transfer the boot management function to other loaders.
In addition to MBR, the boot management program can be installed in the boot sector of other partitions.
6. Dual System Boot
For example, assume that your PC has only one hard disk, which is split into four split slots. The first and second split slots are installed with Windows and Linux respectively, how do you choose to use Windows or Linux when starting the system? If the MBR is installed with a boot management program that allows you to know the Windows/Linux operating system at the same time, the entire process can be shown as follows:
We can find that the MBR boot Management Program provides two menus, menu 1 (M1) can directly load windows core files to boot; menu 2 (m2) it is to hand over the boot management work to the Boot Sector (Boot Sector) of the second split slot ). When the user selects option 2 during boot, the entire boot management work will be handed over to the boot Management Program in the second split slot. After the second boot management program is started, the boot Management Program (medium) has only one boot menu, so you can use the Linux core file to boot. This is how multi-boot works! We will make a summary:
(1) Each split slot has its own Boot Sector (Boot Sector)
(2) The system slot in the figure is the first and second split slots,
(3) The core files that can be turned on are placed in different bins!
(4) loader only recognizes the core file that can be started in its system slot and other loaders;
(5) loader can direct or indirectly forward the management right to another management program.
Why do people often say, "If you want to install multiple boot times, you 'd better install windows before installing Linux? This is because:
(1) When installing Linux, you can choose to install the boot Management Program in MBR or the Boot Sector of Separate slots, and the loader of Linux can be manually set to the menu (that is, M1, m2 ...), therefore, you can add the Windows boot option to the Linux boot loader;
(2) When Windows is installed, its installer will automatically overwrite the MBR and the start sector of its own split slot. You have no chance to choose from it, in addition, he did not allow us to select a menu by ourselves.
Therefore, if you first install Linux and then install windows, then the MBR boot management program will only have windows projects, there will be no Linux Project (because the Linux boot Management Program originally in MBR will be overwritten ). Do you need to reinstall Linux once? Of course you don't need it. You just need to use various methods to process the MBR content. For example, the use of all Chinese spfdisk (http://spfdisk.sourceforge.net/) software to install a Windows/Linux management program, but also can use the Linux rescue mode to save MBR.
Chapter 4 install centos
1. Disk Partition
As mentioned above, disk partitioning is the most important part of the installation process. By default, centos provides four split modes:
(1) Remove all partitions on the selected disk and create the default split mode: If this mode is selected, Linux deletes all partitions on the hard disk, create a new split slot by default.
(2) Remove the LINUX partition on the selected disk and establish the default partitioning mode: In this hard disk, only the LINUX partition slot will be deleted, then, re-create the split slot in the default mode of the installer.
(3) Use the unused space on the selected disk to establish the default split mode: if there is still unsplit disk space in your hard disk (note that it is not split, instead of having no data in the split slot !), After using this project, he will not change the original split slot, but will only build the remaining unsplit blocks.
(4) Establish a custom segmentation Mode
2. File System Selection
These file system types are:
(1) ext2/ext3: The file system type applicable to Linux. Because the ext3 file system has a log record while restoring the system quickly, we recommend that you select a new ext3 instead of using ext2.
(2) physical volume (LVM): This is a mechanism used to elastically adjust the file system capacity. It can increase or decrease the file system capacity without changing the original file data content!
(3) software raid: simulates the disk array function using the features of the Linux operating system!
(4) Swap: Memory Replacement space! Because SWAp does not use directory tree mounting, you do not need to specify a mount point when using swap!
In the traditional Linux instruction file, it is particularly specified that "swap should be 1.5 to 2 times the physical memory 』. Swap swap space is very important because it can avoid low system performance caused by insufficient physical memory. But if you have more than 4 GB physical memory, to be honest, swap does not have to be set.
The swap memory swap space function is: when data is stored in the physical memory, but the data is not often used by the CPU, these infrequently used programs will be thrown into the swap space of the hard disk's swap, and the fast physical memory space will be released to the really needed program! Therefore, if your system is not very busy and the memory is large, you naturally do not need swap.
(5) vfat: File System Types supported by both Linux and Windows. If your host's hard drive has Windows and Linux operating systems, you can build a vfat file system for data exchange!
3. SELinux
It is short for security enhanced Linux. This software was developed by the National Security Agency (NAS). It is not a firewall! SELinux is a detailed setting of access control in a Linux system. The focus is on the permission restriction of the control program on system files. Since centos 5.x and later Linux versions are very appropriate for SELinux settings, we recommend that you enable this function!
4. kdump
Kdump is whether to write the information in the memory to the archive when the core encounters an error, and this archive can be used by the core developer to find out why it will go down. We are not a core developer, and the data in the memory is too large. Therefore, frequent kdump may cause a waste of hard disk space. Therefore, we recommend that you do not start the kdump function!
5. Dual-system installation
The new host only has one hard disk.
If your system is new and you want to install multiple operating systems, the installation of these multiple operating systems will be very simple! Assuming that the current mainstream 160 GB hard drive is well planned, and you want to have Windows XP, Windows XP data disks, Linux, swap, and a shared partition slot, first, let's plan hard disk partitioning! If this is the case, you can plan as follows:
To install Windows X, you must first install Windows X and then Linux!
- Install Windows XP
At this stage, Windows XP is still used for installation after boot. When the split is installed, remember to create two main split slots according to the above table and format the file system as NTFS, then install Windows XP in the C-cell. Theoretically, only/dev/sda1 and/dev/sda2 are available!
- Install centos 5.x
The next step is to install linux. During installation, note that the parts are also separated. Go back to the disk partition section in the previous section to set the partitions. Another important thing to note is that it is in the place where the boot management program is located, especially for the "Default Boot" project. Do you want to start Windows or Linux by default? This requires your choice! In addition, grub must be installed on the MBR header.
- Precautions for subsequent maintenance
Note: (1) in windows, the linux root directory and swap can be unmounted. Otherwise, when you open the file manager in the future, the software will require you to "format! 』 If you don't care, your Linux system will be ruined. (2) You cannot delete Linux as you like! Grub will read the/boot/directory content under the linux root directory. If you remove Linux, your windows will not be able to boot! Because the entire boot menu will disappear!
Chapter 2 First Login and online help
1. commands related to shutdown/restart
Let's talk about several commands related to shutdown/restart:
(1) write data synchronously to the hard disk. Command: sync
(2) The usual shutdown command: Shutdown
(3) restart and shut down: reboot, halt, poweroff
2. Switch execution level: init
This chapter first talked about the run level issue. We talked about the system operation model, which is dividedRun level 3 and run level 5). Are there other modes besides the two modes? In fact, there are seven levels of execution in Linux. We will discuss the significance of these seven levels later. In this chapter, you only need to know the following four execution levels:
Run level 0: Shutdown
Run level 3: plain text mode
Run level 5: graphic interface mode
Run level 6: restart
How can we switch between different modes? You can use the init command to handle it! That is to say, if you want to shut down, you can also use the following command to shut down the system in addition to the shutdown-H now and poweroff commands:
[Root @ WWW ~] # Init 0
3. Hard Disk Protection
How can I prevent file system errors on a hard disk?
(1) properly maintain the hard disk:
For example, when the host is powered on, it needs to be moved to avoid moving or shaking the hard disk. To minimize the hard disk temperature, you can install a fan to cooling the hard disk, or replace the SCSI hard disk.
(2) Partition different partitions:
Why is disk partitioning so important! Because each directory in Linux is read and written at different frequencies, proper segmentation will make Linux safer! We recommend that you divide the following disk blocks:
O/
O/boot
O/usr
O/home
O/var
This division has some advantages. For example,/var is the default storage directory of some data stored by the system or cache data, which is included in e-mail. If a proxy is used, the disk may be damaged because it is frequently accessed. When this part of the disk is damaged, it is okay in other places, therefore, data can be stored and processed easily!
Chapter 6 file permissions and directory configuration in Linux
1. permission settings
Chgrp: Change the group to which the archive belongs
Chown: Change the archive owner
Chmod: changes the permissions of files, and features such as SUID, SGID, and sbit
In fact, chown can also use "chown user. group file", that is, add the decimal point "." between the owner and the group! However, many users prefer to add decimal points (such as vbird. Tsai) to their accounts when setting accounts, which may lead to system misjudgment! Therefore, we recommend that you use the colon ":" To separate owners from groups! In addition, chown can also simply modify the group to which it belongs! For example, "chown. sshd install. log" is used to modify a group ~ Have you seen it? That's the purpose of the decimal point!
2. Importance of permissions on Archives
3. Importance of permissions on directories
File Type in Linux: regular file)-, Directory)D, Link)L, Device (Block device)BAnd character DevicesC], Interface file (socket)S, Data transmission file (PIPE)P
4. Linux directory configuration basis-FHS
Because there are too many communities, companies, and individuals using Linux to develop products or distributions. If everyone uses their own ideas to configure the directory where files are stored, this may cause many management problems. As you can imagine, after you enter an enterprise, the Linux directory configuration method you have come into contact with is totally different from what you have learned before? Therefore, the so-called filesystem Hierarchy Standard (FHS) standard was introduced later!
According to FHS (http://www.pathname.com/fhs/) official documents, their main objective is to give users the knowledge that installed software is typically placed under that directory, therefore, they want independent software developers, operating system creators, and users who want to maintain the system to comply with FHS standards. That is to say, the focus of FHS is to regulate what data should be placed in each specific directory. In this way, the Linux operating system is able to develop the unique style that developers want under the existing appearance (the directory architecture remains unchanged.
In fact, FHS has been continuously revised based on past experience. FHS is based on the frequent usage of file systems and whether users are allowed to change the OS at will, the directory is defined as the form of four interactions, which is a bit like the following in the table:
The directory in the Table above is a representative directory. The data stored under the directory will be discussed below. What we need to know is, what are the four types?
Shareable:It can be shared to directories used for mounting by other systems. Therefore, data such as execution files and users' emails can be shared to other hosts on the network;
Not shareable:Device Files running on your machine or socket files related to the program are not suitable for sharing with other hosts because they are only related to your machine.
Unchanged:Some data does not change frequently, but does not change with distribution. For example, the library, file description file, and host service configuration file managed by the system administrator;
Changeable: Frequently changed data, such as logon files and newsgroups that can be accepted by common users.
In fact, FHS only defines what data should be placed under the three-tier directory for the directory tree architecture, which are the definitions of the three directories respectively:
/(Root, root directory): Related to the boot system;
/Usr (UNIX Software Resource): related to software installation/execution;
/Var (variable): it is related to the system operation process.
Why should we define these three levels of directories? Actually it makes sense! The directories that should be placed under each layer of directories are also specified!
5. the meaning and content of the root directory:
The root directory is the most important directory of the entire system, because not only all directories are derived from the root directory, but also the root directory is related to boot/restore/system repair and other actions. Because the system requires specific boot software, core files, programs required for boot, and library files during boot, if an error occurs in the system, the root directory must also contain programs that can repair the file system. Because the root directory is so important, in terms of FHS requirements, he hopes that the root directory should not be placed in a very large split slot, because the larger the split slot, the more data you will put into it. As a result, the split slot of the root directory may lead to more errors.
Therefore, the FHS Standard suggests that the split slot of the root directory (/) should be smaller, the better, and the software installed by the application should not be placed in the same split slot as the root directory, the smaller the root directory, the better. This is not only more efficient, but also less prone to problems in the file system where the root directory is located.
In view of the above description, FHS defines that the root directory (/) should have the following directories:
In addition to the contents of these directories, note that, because the root directory is related to boot, only the root directory will be mounted during boot, other split slots are mounted after the boot is complete. Because of this, the directory related to the boot process under the root directory cannot be put in different split slots with the root directory! Which directories cannot be separated from the root directory? There are the following:
/Etc: Configuration File
/Bin: Important execution files
/Dev: Device File required
/Lib: the Library required by the execution file and the modules required by the core
/Sbin: important system execution files
These five directories cannot be separated from the root directory in different split slots!
6. meaning and content of/usr:
According to the basic definition of FHS, data stored in/usr is shareable and unchangeable ), if you know how to mount split slots through the network (for example, the NFS friends server mentioned in the friend Server article ), then/usr can be shared with other hosts in the local area network!
Many readers may misunderstand that/usr is the abbreviation of user. In fact, USR is the abbreviation of UNIX software resource.That is, the directory where "UNIX operating system software resources" are stored, rather than user data! FHS recommends that all software developers properly place their data in the sub-directories under this directory instead of creating their own independent directories. Because all the default software (the software provided by the Distribution publisher) is placed under/usr, this directory is a bit similar to the Windows system's "C: \ WINDOWS \ + C: \ Program Files \ "is a combination of the two directories. When the system has just been installed, this directory will occupy the most disk capacity. In general, the/usr sub-directory is recommended to have the following:
7. Significance and content of/var:
If/usr is a directory that will occupy a large disk capacity during installation,/var is the directory that will gradually occupy the hard disk capacity after the system is running. Because the/var directory is mainly used for files that change frequently, including cache files, log files, and files generated by some software operations, including lock files, run file), or MySQL database files. Common Sub-directories include:
For FHS, the similarities and differences between various distributions are as FHS only defines the files and directory data to be placed in the directory content of the upper (/) and lower (/usr,/var) layers, therefore, you can configure it with the developer at other directory levels. For example, the network configuration data of centos is stored in the/etc/sysconfig/network-scripts/directory, but SuSE stores the network in the/etc/sysconfig/Network/directory, the directory names are different! However, as long as you remember the FHS standard, the difference is actually limited!
8. directory tree)
In addition, in Linux, all files and directories start with the root directory! That is the source of all directories and archives ~ The next branch is like a tree branch. Therefore, we also call this directory configuration method "directory tree". What are the features of this directory tree? Its main features include:
- The start point of the directory tree is the root directory (/, root );
- Each directory can use not only the local partition file system, but also the filesystem on the network. For example, you can use the Network File System (NFS) server to mount a specific directory.
- Each file name (including the full path) in this directory tree is unique.
If we display the entire directory tree as an image and list more important archive data, the directory tree architecture is a bit like this:
According to the FHS definition, it is best to separate/var, which provides some security protection for System Data! Because at least/var will die, and your root directory will still be alive! You can also enter the rescue mode!
Partition recommendations:
/Boot
/:
/Var:
/Usr:
/Home:
Chapter 4 file and directory management
1. ls Command Parameter Parsing
2. Get the path file name and directory name
As mentioned above, the complete file name (including the directory name and file name) can contain a maximum of 4096 characters. So how do you know that is the file name? Which is the directory name? Is to use the slash (/) to distinguish! In fact, to get the file name or directory name, the general purpose should be to judge when writing a program ~ Therefore, this part of commands can be used in shell scripts in Article 3! Let's talk about the use of basename and dirname in a few simple examples!
3. Check the file content:
What should we do if we want to view the content of an archive? There are quite a few interesting commands to share: the most commonly used commands for displaying file content can be said to be Cat, more, and less! In addition, if we want to view a large file (several hundred MB), but we only need a few lines of words at the backend, what should we do? Haha! Use tail. In addition, the TAC command can also be reached! Okay. Let's talk about the usage of each command!
Cat displays the file content from the first line
The TAC is displayed from the last line. We can see that the TAC is written by CAT!
When NL is displayed, the line number is output!
More page-by-page display of File Content
Less is similar to more, but it is better than more. He can flip the page forward!
Head only looks at the first few rows
Tail only looks at the last few lines
Od reads the file content in binary format!
4. Modify the file time or create a new file: Touch
When we introduced the LS command, we mentioned that each file will record a large number of time parameters under Linux. In fact, there are three major changes, so what is the meaning of three times?
- Modification time (mtime ):
This time will be updated when the "content data" of this file is changed! Content data refers to the file content, not the attributes or permissions of the file!
- Status time (ctime ):
When the "status" of the file changes, the time will be updated. For example, the permission and attribute will be updated.
- Access time (atime ):
When "the content of the file is used", the access time is updated ). For example, if we use Cat to read/etc/man. config, The atime of the file will be updated.
5. umask usage
On the default permission attribute, the directory and file are different. From Chapter 6, we know that X permissions are very important to directories! However, the creation of an archive should not have the execution permission, because the archive usually uses data records! Of course, no execution permission is required. Therefore, the Preset conditions are as follows:
- If the user creates an archive, the default "No executable (x) Permission" is set. That is, only the RW project has a maximum of 666 points. The default permissions are as follows: -RW-
- If the user creates a "directory", X is enabled for all permissions by default, that is, 777 points. The default permission is as follows: drwxrwxrwx
Note that umask refers to the "permission to be removed for this default value !』 As described in the preceding example, because umask is set to 022, the user has not been assigned any permissions, but the permissions of group and others have been removed 2 (w ), when users:
When creating an archive: (-RW-)-(----- w -- w-) ==>-RW-r --
When creating a directory: (drwxrwxrwx)-(D ---- w -- w-) ==> drwxr-XR-x
6. Find command
The special function of find is to perform additional actions ). Let's illustrate the Example 8 as follows: