linux文件系统之文件和分区基础


InUnix/Linux, a file is a sequence of bytes withoutstructure. Any necessary structure (e.g. for a database) isadded by the programs that manipulate the data in the file. Linuxitself doesn’t know about the internal structure of a database file– all it does is return bytes.

对于Linux系统来说,文件都是无结构的字节序列。所谓任何一个有结构文件(比如数据库文件)都是针对应用程序来讲的,也就是说,linux不会知道文件是什么结构(也不需要知道的),linux只负责返回或者写入文件的字节序列,具体如何解析这个文件是由应用程序负责。

Unix/Linuxtries its best to treat every device attached to it as if it were alist of bytes. Therefore, everything, including network cards, harddrives, partitions, keyboards, printers, and plain files are treatedas file-like objects and each has a name in the file system.

Yourcomputer memory is /dev/mem.

Yourfirst hard disk is /dev/sda.

Aterminal (keyboard and screen) is /dev/tty1.

Etc.

Linux的另一个特点是,一切皆文件的思想。linux尽最大努力把所有的设备当成由字节序列构成的文件看待(其实这个思想咋一看不可思议,但是我们想一想,所有的物理设备,最终做的是什么?存储数据。不管是显示屏/打印机/键盘/磁盘/usb等,都是要存储数据的,这些数据不就是字节序列么,字节序列不就是文件么,所以这是一种很好的面向对象的抽象思想,并且很好的实现了统一管理和透明性)。

Thereare two kinds of major partitions on a Linux system:

datapartition: normal Linux system data, including the rootpartition containing all the data to start up and run thesystem; and

swappartition: expansion of the computer's physical memory, extramemory on hard disk.

Oneof the goals of having different partitions is to achieve higher datasecurity in case of disaster. By dividing the hard disk inpartitions, data can be grouped and separated. When an accidentoccurs, only the data in the partition that got the hit will bedamaged, while the data on the other partitions will most likelysurvive.

Linux下对磁盘的组织是分区,那么为什么需要分区呢?一块磁盘统一管理不就行了么。计算机里面所有的一切都是在tradeoff(权衡),我们会牺牲某个东西去换取另一个东西,如果另一个东西在实际生产环境中更有价值。计算机时间空间和安全永远都在博弈。Linux分区的一个主要考虑是security安全问性。分区能够实现更好的数据安全性从而避免灾难。通过对磁盘分区,数据可以分别存放在不同的组中。一旦发生事故,只有发生事故的分区数据会损坏,而其他分区的数据不会受到太大的影响。

下面我们来看看linux下面如何查看磁盘分区和文件系统类型:

The df command only displays information about active non-swappartitions.

df命令只会显示已挂载的分区(文件系统)和非交换分区的信息。

\

 

下面我们挂载一个分区:

\

 

把/dev/sda6分区挂载到/media/kitian目录下面。查看自己的分区,可以使用fdisk-l命令,再次df,就可以看到挂载上的/dev/sda6了

df命令看不到文件系统的类型,那么我们使用另一个工具parted;parted可以看到所有分区的具体信息(包括文件系统类型)

 

进入parted工具后输入printlist命令,就可以看到了。
 

相关内容