Linux File System Introduction (a)

1, the operating system

= Operating system kernel (core) + call system (interface)

Acquaintance operating system, we start with a picture:

 

Core: that is, we usually refer to the operating system kernel, resource allocation and management primarily responsible for the entire computer system-related, can be summarized as the following several core functions

  • Program management: resource allocation and scheduling management program execution.
  • Memory management: control and memory usage.
  • File System Management: File format support, data input / output, and so on.
  • Hardware-driven management: hardware drivers for use which is the main work of the kernel, currently supports loadable modules] [manage hardware.

System Call Interface: Easy application developers can easily communicate with the kernel through the use of hardware resources. 

2, computer components

Von Neumann computer out basic works:

  1. Expressed in binary form with data and instructions;
  2. Using the stored program execution mode;
  3. Most arithmetic logic computer 5 by the operator, controller, memory, input devices and output devices. [Into the transport control]

 

Composition of the CPU: The processor cache + 

The computer entity internal structure:

 

The figure is produced by Intel x86 architecture typical of the motherboard.

3, the computer boot process

  Desktop and notebook boot process slightly different, but substantially the same as the main process: pressing the start button -> EC power button is detected (high-low transition) -> completed and the CPU power control -> Read BIOS and CMOS completion of all parameters on the device and power self-checking system -> CPU to find a bootable device according to the first order of the BIOS settings, reads the first sector -> boot loader program in the CPU operation sector, boot loader program according to the partition table to find and load the bootable partition where the kernel -> complete boot.

The boot process, the flowchart follows:

Red font demand our attention, which involves the following concepts or entities: the first sector, boot loader, partition table and the system kernel.

4, disk Overview

  Since the image more mechanical hard, so here is mechanically hard to introduce the concept described above. Contemporary solid gradually become mainstream, with mechanical hard biggest difference is that it works: SSDs based on the state of the semiconductor memory media to do, as the mechanical hard disk is a magnetic memory media.

 

硬盘容量=磁头数*磁轨数*扇区数*扇区大小(512KB)

硬盘的数据存储在一个个的盘片上,每个盘片由多个同心圆磁轨组成,每个磁轨又由多个扇区组成。扇区是数据存储的基本单位,人为规定每个扇区大小为512KB。硬盘可以有多个盘片,每个盘片上相同的磁轨组成了磁柱,而磁柱是分区的基本单位。

磁盘的扇区并不是都一样重要,最最重要的是磁盘的第一个扇区,因为它记录了整颗磁盘的重要信息,主要有以下两个重要信息:

  1. MBR(Master Boot Record),大小446Bytes,用于安装开机管理程序;
  2. 分割表(partition table),记录整颗硬盘的分割状态,64Bytes。

4.1 磁盘分区

分割表所在的64Bytes容量中,总共分为四组记录区,每组记录区记录了该区段(分区)的启始与结束的磁柱号码。

仅有主分区磁盘分区

 

引入扩展分区磁盘分区

 

注意,引入扩展分区的目的是使用额外的扇区来记录分区信息,扩展分区本身不能被格式化,需要将扩展分区的分区段继续分割后(分割后的分区成为逻辑分区)才能进一步格式化。

4.2 加载系统

  加载系统主要用到第一颗可启动设备的第一个扇区的MBR位置。MBR里面放置的就是最基本的开机管理程序(boot loader),它的作用就是加载操作系统内核。Boot loader有3项基本任务:

  • 提供选单:当有多重引导时,可同用户选择不同的开机项目;
  • 载入系统内核:指向可开机的程序区段来开始操作系统;
  • 转交其他loader:将开机管理功能转交其他loader负责------能实现多重引导的根本。

PS:如果电脑安装多系统,需要先安装windows系统,在安装linux系统。

5 Linux目录结构

  在Linux系统中,所有数据都是以文件形式呈现,因此整个Linux系统最重要的地方就在于目录树架构。所谓目录树架构就是以根目录为主,然后向下呈树形分支状的目录结构,因此目录树架构最重要的就是根目录,在Linux中以一条斜线/表示。目录树的呈现方式如下图所示:

 

至于系统有哪些目录,以及各种目录放置哪些数据,为了规范这些东西,于是就有了所谓的FHS(Filesystem Hierachy tandard)。事实上,FHS针对目录树仅定义了三层目录下应该放置的数据:

  • / : 与系统开机、回复、备份相关;
  • /usr : 与软件的安装/执行相关;
  • /var: 与系统运行过程有关。

FHS官方文档可参看: http://www.pathname.com/fhs

6 分区挂载与目录映射

  截止目前,我们知道整个Linux系统使用的是目录树架构,但是我们的文档数据其实是放置磁盘分区中,所以现在的问题是“如何结合目录树架构与磁盘分区内的数据?”答案是“挂载(mount)”。所谓挂载,就是利用一个目录当成进入点,将磁盘分区中的数据放置在该目录下;换种说法就是,进入该目录就可以读取到相应分区内的数据。将目录与分区映射这个动作就叫“挂载”,进入点的目录就叫挂载点。

常见的挂载点与磁盘分区的规划:

  1. 初次接触Linux: 分割为/及swap即可;
  2. 建议分区方式:/, /boot, /var, /usr, /home, swap;
  3. 根据服务器具体用途分区;

# df -T  //查看已挂载的分区和相应的文件系统类型 

7 目录及文件权限、存储与读取

在介绍文件与目录权限之前,简要解释一下拥有者,群组,及非本群组外其他人三个概念,并结合ll命令查看文件权限及目录权限。

用户及用户组常用管理命令可参考: https://blog.51cto.com/taoismli/1977864 

有了上述用户、用户组及权限概念之后,再来了解一下权限之于文档及目录的意义:

权限于文档的意义:

  • r (read):可读取此一档案的实际内容,如读取文本文件的文字内容等; ·
  • w (write):可以编辑、新增或者是修改该档案的内容(但不含删除该档案); ·
  • x (execute):该档案具有可以被系统执行的权限。

权限于目录的意义:

  • r (read):表示具有读取目彔结构列表的权限,所以当你具有读取(r)一个目彔的权限时,表示你可以查询该 目彔下的文件名数据。 所以你就可以利用 ls 这个挃令将该目彔的内容列表显示出来!
  • w (write):表示具有移动该目彔结构列表的权限,也就是底下这些权限:x (execute):代表的是用户能否进入该目彔成为工作目彔。
    • 建立新的文档与目彔;
    • 删除已经存在的文档与目彔(无论该文档的权限为何!);
    • 更名文档与目录;
    • 移动该目彔内的文档、目彔位置;

在Linux系统中,数据的存储是采用“索引式”的方式存取,所谓索引式存储实际上是系统在存储数据时会将权限、属性信息等信息放到一个区域(inode),而将实际的数据放到另外的区域(data block区块),大致样式如下图:

 

iNode:记彔文档的属性,一个文档占用一个inode,同时记彔此文档的数据所在的 block号码;

block:实际记彔文档的内容,若文档太大时,会占用多个 block。

# ll -i[d] //查看文件[目录]的inode号

通常一个文件系统(比如一个分区)的最顶层inode号码是由2开始,因此我们读取文件或者目录的过程大致如下:

由于目录树是由根目录开始读起,因此实际上是去根目录所在分区读inode号为2的内容,根据inode所提供的block号,去读取该目录下的文件名或目录名,以及各自所对应的inode号,再这样一步步鉴权和读取(如果读到block中某个目录的inode号又为2,说明其属于另一个分区,则根据磁盘分区表定位到该分区,再读该分区的inode号为2所指向的block区)。

Guess you like

Origin www.cnblogs.com/wendyw/p/12382088.html