hard disk file system

1. Disk structure and partition representation

1.1 Disk Basics

A hard disk (Hard Disk Driver, HDD for short) is one of the commonly used storage devices for computers.

1.1.1. Hard disk structure

insert image description here
1. Data structure:

  • Sector : The smallest unit for storing data is 512 bytes
  • Magnetic Tracks : Convenient Data Storage
  • Cylinder : The same sectors are stacked together
    2. Physical structure:
  • Disk : The hard disk has multiple disks, and each disk has two sides
  • Magnetic head : one magnetic head per side
    3. Storage capacity:
  • Hard disk storage capacity = number of heads x number of tracks x number of sectors per track x number of bytes per sector ( 512 bytes )
  • Can use cylinder/head sector to uniquely locate each area on the disk
  • View partition information
    insert image description here

1.1.2 Hard disk interface

According to different data interfaces, hard disks are roughly divided into ATA (IDE), SATA, and SCSL. The interface speed is not the transmission speed of the hard disk.

  • IDE (parallel port): connect the motherboard and hard disk, poor anti-interference, occupy a large space
  • SATA (serial port): strong anti-interference, fast speed, strong error correction ability
  • SCSI : low CPU usage, fast speed
  • SAS : New SCSI technology, same as SATA hard disk, adopts serial technology to obtain higher transmission speed.

1.2 Disk partition representation

1.2.1 MBR

  • MBR is located in the first physical sector of the hard disk
  • MBR has a total of 512 bytes, the first 446 bytes are the master boot record, and the partition table is stored in bytes 447-512 of the MBR sector
  • The partition table has 4 partition records, and each partition record area occupies 16 bytes

1.2.2 Disk partition representation

When the linux kernel reads resources such as optical drives and hard disks, it is done in the form of " device files ". Therefore, hard disks and partitions are represented as different files

  • Indicates: /etc/hda5
    - /dev/: the directory where the hardware device files are located
    - hd: indicates the IDE device
    - a: the serial number of the hard disk, indicating the number of the hard disk
    - 5; the serial number of the partition, indicating the number of the first hard disk interface five partitions

1.2.3 Disk partition structure

insert image description here

  • The number of primary partitions in the hard disk is only 4
  • The serial numbers of primary partitions and extended areas are limited to 1-4
  • Extended partition subdivided logical partition
  • The serial number of the logical partition will always start from 5

1.2.4 View disk usage

insert image description here

1.2.5 File system types used in linux

The file system type determines the method and efficiency of storing and reading data in the partition

  • XFS file system

  • Store file and directory data partitions

  • High-performance log file system, especially good at processing large files and supporting storage space above 2T

  • The file system used by default in the cenos7 system

  • Swap exchange file system

  • Create swap partition for linux system

  • Generally set to 1.5~2 times of physical memory

2. Manage disk partitions

2.1 Disk Management

2.1.1 Check and confirm the new hard disk

基本格式:
查看磁盘分区:fdisk -l 【磁盘设备】
【root@cheng0307~】#fdisk -l /dev/sda
管理磁盘分区:fdisk  【磁盘设备】
【root@cheng0307~】#fdisk  /dev/sda

Identify Disks Without Rebooting

 echo "- - -" >/sys/class/scsi_host/host0/scan
 echo "- - -" >/sys/class/scsi_host/host1/scan
 echo "- - -" >/sys/class/scsi_host/host2/scan

If the system still cannot recognize the hard disk, you can restart the system

insert image description here
Device ; the device file name of the partition
Boot : boot partition, if yes, there will be a '*' sign
Start : the partition
End : the end position of the partition in the hard disk
Blocks : the size of the partition, in units of Blocks, the default block The size is 1024 bytes
Id : the system ID number corresponding to the partition, 83 represents the default partition in the LINUX system, 8e represents the LVM logical volume
System ; partition type

2.1.2 Planning the partitions in the hard disk

  • interoperability command
options effect
m get help menu
p View partition status
n New partition
d delete partition
t Change partition type
w Save the partition operation and exit
q Exit without saving the partition operation

(1) Use fdisk /dev/sdb to enter the hard disk interactive management interface, and enter m to get help
insert image description here
(2) Example:

  • Add a 20GDE SCSI hard disk for the host

  • Partition the hard disk
    2.1 Divide 2 primary partitions, each 20GB, and the remaining space is an extended partition
    2.2 Create 2 logical partitions in the extended partition, with a capacity of 2GB and 10GB
    2.3 Change the type of the first logical partition to swap
    2.4 Confirm Partition settings, save and exit

  • Use partprobe to detect the hard disk partition, save and exit

  • step:

     lsblk 命令可以详细查看分区信息
     1.先添加硬盘,并让系统识别,可以重启,或者不重启的情况下输入下一命令
     2.fdisk分区,方便使用,最大化硬盘性能
     3.格式化后确定文件系统
     4.挂载
    
  • Specific steps

insert image description here

insert image description here
insert image description here

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

2.2 Manage file system Make Filesytem (formatting)

Format;

mkfs  -t   文件系统类型   分区设备 (要用绝对路径)

insert image description here

3.2 Unmount the mounted file system

Format;

umount  存储设备位置或挂载点
【root@chen0370/】# nmount /dev/cdrom
【root@chen0370/】# nmount /mnt

3.3 Set the file system to automatically mount

In the /etc/fstab file, each line records the mounting configuration information corresponding to a partition or device, including six automatics from left to right (separated by spaces or tabs), and the meaning of each part is as follows:

  • The first field: device name or device volume label name;

  • The second field: the location of the mount point directory of the file system;

  • The third field: file system type, such as EXT4, swap, etc.;

  • The fourth field: mount parameters, that is, the parameters that can be used after the "-o" option of the mount command (defaults, rw, ro, and noexec respectively represent default parameters, writable, readable, and disabled execution);

  • The fifth field: Indicates whether the file system needs dump backup, set to 1 to indicate yes, 0 to ignore;

  • Sixth field: This number is used to determine the order of the disk check when the system starts, 0 means no check, 1 means check first, and 2 means check second. The root partition can be set to 1, and other partitions can be set to 2. Generally, it is not checked, which will affect system performance.

  • The automatic mount of the cdrom is not set, and after restarting the virtual machine, the mount of the principle disappears automatically

insert image description here

insert image description here

  • Set the automatic mount of cdrpm

insert image description here

insert image description here

Four. Summary

1. Why partition ;
optimize read and write performance, realize disk space quota limit, improve repair speed, isolate system and program

2. The old technology of mbr partition. The hard disk below 2T
is divided into mbr by fdisk tool gpt: master boot record, which is the first sector on the hard disk. If you want to read data, you must start from this sector

3.mbr has a total of 512 bytes,
the first 446 bytes bootloader, guide the hardware to find our operating system

4. The last 64 bytes represent the partition table : it indicates the partition range, where the partition starts and ends. The new technology can support the hard disk gdisk tool above 2T

5. Logical partition: It can be used directly. The extended partition for storing files is a special primary partition. The sequence number of the primary partition is 1-4. The sequence number of the logical partition starts from 5.

6. Disadvantages of partitioning
can only divide continuous space, once the area is divided, the space cannot be increased or decreased, and the space is fixed

Guess you like

Origin blog.csdn.net/fyb012811/article/details/131892966