After reading it, you will understand what /dev/sda and /dev/hda are

1. Introduction to Linux file system

In any operating system, file management is one of its basic functions, and file management is completed by the file system. The file system is mainly used to organize and manage a large number of files on computer storage devices and provide user interaction interface. Linux also has a complete file system.

The operating system processes various data, and the data is binary on the hard disk. The file system is used to restore these binary data to the corresponding file form, and realize data query and storage. Linux has a variety of file systems, and different file systems support different systems. The file system manages data, and the physical devices that store data include hard disks, U disks, SD cards, NAND FLASH, NOR FLASH, network storage devices, etc. Different storage devices have different physical structures, so different file systems are required for management, such as the YAFFS file system for NAND FLASH management, and the ext file system for hard disk/SD card management.

Linux is an operating system with high compatibility. It supports many file system formats, which can be roughly divided into the following categories:

  • disk file system: Refers to the file system that can actually be accessed in the local host, including hard disk, CD-ROM, DVD, USB memory, disk array, etc. Common formats are: Ext2, Ext3, Ext4, JFS, NTFS, UFS, FAT, FAT16, FAT32, etc.
  • network file system: It is a file system that can be accessed remotely. It is still a local disk file system on the server side, and the client computer remotely accesses data through the network. Common formats are: NFS, Samba, etc.
  • Proprietary/Virtual File System: A file system that does not reside on disk. Common formats are: TMPFS, PROCFS, etc.

2. Linux disk file system

Next, we mainly introduce the disk file system. at presentExt4(Extended File sytem, ​​extended file system) is a widely used disk file system format. It is developed on the basis of Ext3, and has been improved in terms of validity protection, data integrity, data access speed, and downward compatibility. It is characterized by a log file system: it can completely record the writing actions of the entire disk On a certain area of ​​disk for backtracking if necessary.

A magnetic disk is an external memory device for a computer, consisting of one or more aluminum or glass discs covered with magnetic material, used to store user information, which can be read and rewritten repeatedly. Disks are mainly divided into the following categories:

  • IDE disk: Integrated Drive Electronics, low price, strong compatibility, high cost performance, but slow data transmission, does not support hot swap, etc.
  • SCSI disk: Small Computer System Interface, high transmission rate, good read and write performance, stable operation, can connect multiple devices, support hot swap, low CPU usage, but relatively expensive, generally used on workstations or servers
  • SATA disk: Serial Advanced Technology Attachment, simple structure, support hot swap

In Linux, devices such as hard disks and partitions are represented as files, and the naming rules are as follows:

  • The file name of the IDE disk is /dev/hdxxx
  • SCSI/SATA/USB disk file name is /dev/sdxxx

insert image description here

Here are some specific naming examples:

/dev/hda          #表示第一个IDE硬盘
/dev/hda1         #表示第一块IDE硬盘的第一个主分区
/dev/hda2         #表示第一块IDE硬盘的扩展分区(或第二个主分区)
/dev/hda5         #表示第一块IDE硬盘的第一个逻辑分区
/dev/hda8         #表示第一块IDE硬盘的第四个逻辑分区
/dev/hdb          #表示第二个IDE硬盘
/dev/sda          #表示第一个SCSI硬盘
/dev/sda1         #表示第一个SCSI硬盘的第一个主分区
/dev/sdd3         #表示第四个SCSI硬盘的第三个主分区

Disks are usually partitioned for ease of management and use.

  • Primary partition: The partition that must exist, up to 4 can be created, at least 1, and the number can only be 1-4 (such as sda1, sda2, sda3, sda4), which can be formatted directly, and then install the system and store files directly
  • Extended partition: It will occupy the position of the main partition, that is, the sum of the main partition + extended partition is at most 4. Equivalent to an independent disk, it has an independent partition table, but cannot store data independently
  • Logical partition: The extended partition cannot directly store data, and must be divided into logical partitions before storing data. There can be any number of logical partitions in an extended partition, and the numbers can only start from 5

The partition scheme in the figure below is: 2 primary partitions + 1 extended partition structure, in which the extended partition is divided into 2 logical partitions
insert image description here

Exchange partition (swap): Created when the system is installed, a special hard disk space. When the actual memory is not enough, the operating system will take out some temporarily unused data from the memory and put it in swap to make enough memory space for the current program. swap will not use the mount of the directory tree, no need to specify the mount point (that is, cd cannot enter)

3. Linux file system structure

Partitions in Linux belong to a directory structure, and the partition and directory are linked by loading/mounting, and the storage space of the partition can be accessed by accessing the directory. The mount point is the mount point of the corresponding partition after the hard disk partition is mounted to a certain directory of the file system. The files created at the mount point are actually stored on the partition of the hard disk. The files on the partition can be accessed through the mount point. If the mount relationship between the hard disk partition and the directory is deleted, the files on the partition will not be deleted. It's just that the original mount point cannot access the files on the partition

Except for the swap partition, other primary partitions, extended partitions, and logical partitions are all operated on the root partition (/) directory. The Linux file system is a tree-shaped hierarchical organizational structure. The root is the only starting point of the entire file system, and all other directories start from this point. As shown below:insert image description here

Since Linux is completely open source software, the directory structures of many Linux distributions are also different. In order to standardize file directory naming and storage standards, the File Hierarchy Standard (FHS) was issued, and the Ubuntu system also follows this standard.

4. Commands related to file system and disk management

There are many commands related to file system and disk management. The following is a brief introduction to a few commonly used commands.

4.1 df command

Abbreviation for disk free, used to list the overall disk usage of the file system. The format of the command is:

df [-a -h -i -k -H -T -m] [目录或文件名]

When used without parameters, all the files in the system (excluding the file system and swap in special memory) will be listed with a capacity of 1 Kbytes by default. Commonly used options are as follows:

  • -a : List all file systems, including system-specific /proc and other file systems;
  • -k : Display each file system in KBytes capacity;
  • -m : Display each file system in MBytes capacity;
  • -h : Display in GBytes, MBytes, KBytes and other formats that are easier for people to read;
  • -H : Replace the carry mode of M=1024K with M=1000K;
  • -T : Display the file system type, together with the filesystem name (eg ext3) of the partition is also listed;
  • -i: Instead of hard disk capacity, it is displayed by the number of inodes

4.2 du command

The abbreviation of disk used is used to view the disk space used by files and directories. The format of the command is:

du [-a -h -s -k -m] 文件或目录名称

When used without parameters, the hard disk space occupied by the subdirectories in the current directory will be analyzed by default. Commonly used options are as follows:

  • -a : list all files and directories
  • -h : display in human-readable capacity format (G/M)
  • -s : List the total amount, not the capacity occupied by a single directory
  • -S : Do not include totals under subdirectories
  • -k : list capacity display in KB
  • -m : list capacity display in MB

4.3 fdisk command

Disk partition table manipulation tool. The format of the command is:

fdisk [-l] 装置名称

Commonly used options are as follows:

  • -l : Output all the partition contents of the subsequent device. If the device name is empty, the partitions of the devices that can be found in the system will be listed

4.4 file command

The file command is used to identify the file type. The format of the command is:

file [-b -c -L -v -z][-f <名称文件>][-m <魔法数字文件>...][文件或目录...]

Commonly used options are as follows:

  • -b Do not display file names when listing identification results.
  • -c Displays the execution process of the instruction in detail, which is convenient for troubleshooting or analyzing the execution of the program.
  • -f<name file> Specifies the name file. When its content has one or more file names, let file identify these files in order. The format is one file name per column.
  • -L Display directly the class of the file pointed to by the symbolic link.
  • -m <magic number file> Specifies the magic number file.
  • -v Display version information.
  • -z Attempt to decipher the contents of the compressed file.
  • [file or directory...] List of files to determine type, separated by spaces, shell wildcards can be used to match multiple files.

4.5 mkdir command

Short for make directory, used to create a directory. The format of the command is:

mkdir [-p] dirName

Commonly used options are as follows:

  • -p Make sure the directory name exists, if it does not exist, create one

4.6 ln command

The abbreviation of link files is to establish a synchronous link for a certain file in another location. When we need to use the same file in different directories, we don't need to put a file that must be the same in every required directory, we just need to put the file in a fixed directory, and then in other You can use the ln command to link (link) it in the directory, and you don’t have to take up disk space repeatedly. The format of the command is:

 ln [参数][源文件或目录][目标文件或目录]

Commonly used options are as follows:

  • -b delete, overwrite previously established links
  • -d allows superuser to make hard links to directories
  • -f enforce
  • -i interactive mode, if the file exists, the user will be prompted whether to overwrite
  • -n treat symbolic links as normal directories
  • -s soft link (symbolic link)
  • -v displays detailed processing
  • -S "-S<suffix backup string> "or "--suffix=<suffix backup string>"
  • -V "-V<backup method>" or "--version-control=<backup method>"
  • --help display help information
  • --version display version information

Guess you like

Origin blog.csdn.net/Chuangke_Andy/article/details/125037880