How to create linux_disk partition and swap file system!

1. Disk Management

1. The physical structure of the hard disk

Pan head: The hard disk has multiple platters, each on two sides. Magnetic
head: One head on each side

2. The data structure of the hard disk

Sector: The disc is divided into multiple sectors, each sector stores 512 bytes of data, which is the smallest storage unit of the hard disk

Track: Concentric circles with different radii on the same disc are circular tracks drawn on the disc surface by the magnetic head

Cylindrical surface: a cylindrical surface composed of different discs with the same radius, composed of multiple tracks with the same radius circle'

Insert picture description here

Insert picture description here
Hard disk storage capacity = number of heads x number of tracks (cylinders) x number of sectors per track x number of bytes per sector (512 bytes)

Cylinder/head/sector can be used to uniquely locate each area on the disk

Disk interface type:
IDE, SATA, SCSI, SAS, Fibre Channel

3. The type of hard disk interface:

IDE: The parallel port data cable connects the motherboard and the hard disk. The anti-interference performance is too poor, and the cable takes up a lot of space, which is not good for the internal heat dissipation of the computer. It has been gradually replaced by SATA.

SATA: strong anti-interference, support hot swap and other functions, fast speed, strong error correction ability.

SCSI: Minicomputer system interface. SCSI hard disks are widely used by workstation-level personal computers and servers. The CPU occupancy rate is low during data transmission, the speed is fast, and it supports hot plugging.

SAS: It is a new generation of SCSI technology, which is the same as SATA hard disks. It adopts serial technology to obtain higher transmission speed, which can reach 6Gb/s.

2. MBR and disk partition representation

主引导记录(MBR:Master Boot Record)

MBR is located at the first physical sector of the hard disk

MBR contains the hard disk's master boot program and hard disk partition table

The MBR has a total of 512 bytes, the first 446 bytes are the master boot record, and the partition table is stored in the 447-512th bytes in the MBR sector.

The partition table has 4 partition record areas, each of which occupies 16 bytes.

In Linux, devices such as hard disks and partitions are all represented as files-in the /dev directory

The master boot record (MBR) disk partition supports a maximum volume of 2.2TB, and each disk has up to 4 primary partitions, or 3 primary partitions, 1 extended partition, and multiple logical partitions in the extended partition.

Insert picture description hereDisk partition means that in
Linux, hard disks, partitions and other devices are represented as files
/dev/sdb5
sd means SCSI device
hd means IDE device
sequence number of hard disk, with letters a, b, ... representing
the sequence number of partitions, with numbers 1, 2 , ... means that the primary partition starts from 1-4, and the first logical partition always starts from 5.

3. Disk partition structure

The number of primary partitions in the hard disk is only 4

The serial number of primary partition and extended partition is limited to 1~4

Extended partition is divided into logical partition

The serial number of the logical partition always starts from 5 (1~4 are always reserved for the primary partition)

4. Master boot record (MBR disk partition)

MBR is the master boot record, located at the first physical sector of the first hard disk (/dev/sda). The MBR contains the master boot program and hard disk partition table of the hard disk. MBRL has a total of 512 bytes, the first 446 bytes are the master boot record, and the partition table is stored in the 447-510 bytes in the MBR sector. The partition table has 4 partition record areas, each of which occupies 16 bytes.

The master boot record (MBR) disk partition supports a maximum volume of 2.2TB, and each disk has a maximum of 4 primary partitions, or 3 primary partitions, 1 extended partition and multiple logical partitions in the extended partition

Five. File system type

XFS file system

1. Partition for storing files and directory data

2. A high-performance log file system, especially good at handling large files, can support millions of terabytes of storage space.

3. The default file system used in the CentOS 7 system

SWAP, swap file system

1. Establish a swap partition for the Linux system (equivalent to virtual memory, conversion between hard disk memory)

2. Generally set to 1.5~2 times the physical memory

Other file system types supported by Linux

EXT3, EXT4, FAT32, NTFS, LVM (scalable file system)

6. Detect and confirm the new hard disk fdisk
fdisk命令:查看或管理磁盘分区
fdisk -l 【磁盘设备】
或
fdisk 【磁盘设备】

1. Create a new hard disk:

Insert picture description here

Insert picture description here
Insert picture description here2.fdisk -l: view the partition situation

Insert picture description here

Device: The device file name of the partition.

Boot: Whether it is a boot partition. If it is, there is a "*" mark.

Start: The starting position (number of cylinders) of the partition in the hard disk.

End: The end position (number of cylinders) of the partition in the hard disk.

Blocks: The size of the partition, in Blocks (block), the default block size is 1024 bytes.

Id: System ID number corresponding to the partition. For example, 83 represents the XFS partition or EXT4 partition in Linux, 82 represents the SWAP swap file system, and 8e represents the LVM logical volume.

System: Partition type.

Manage disk partitions: fdisk/dev/sdb

Seven. Commonly used commands in exchange mode

Common commands in interactive mode:
m: get help menu
n: create partition
p: view partition status
d: delete partition
t: change partition type
w: save partition operation and exit
q: exit without saving partition operation

8. Steps to create a partition
  • Manage disk partitions: fdisk /dev/sdb
  • n
  • p primary partition, e extended partition, 1 logical partition
  • Set partition: 1 (range 1-4, such as press Enter to accept the default value)
  • Set the column and sequence: directly press Enter to accept the default value
  • Set partition size: +20G. (Specify a size of 20GB, such as press Enter to accept the default value means all space)
  • w

Insert picture description hereSet a swap partition: t,
change the partition type: the default is 83, modify it to 82

Insert picture description here

Create extended partitions and logical partitions;
Insert picture description here

Seven. Create file system format mkfs command

Make Filesystem, create a file system (format)
mkfs -t file system type partition device

Command: mkfs -t xfs /dev/sdb1
Insert picture description here
mount:
Insert picture description here

8. Create a swap file system mkswap command
make swap,创建交换文件系统
mkswap分区设备

mkswap /dev/ sdb5
swapon /dev/sdb5 #Enable the newly added swap partition I
swapoff /dev/ sdb5 #Disable the specified swap partition
swapon-S #View the swap status information of each partition
free -m#View the total swap status information

Insert picture description here

Nine. Mount and unmount the file system mount command
挂载文件系统、ISO镜像到指定文件夹
 mount [ -t类型]存储设备挂载点目录
mount -0 loop ISO镜像文件挂载点且录

-t: used to specify the file system type, usually can be omitted, automatically recognized by the system
-o: mount parameter list, separated by English commas: if used to describe special equipment, specify with loop

mount /dev/cdrom /mnt
mount /dev/sdb1 /opt

umount command
unmount the mounted file system
umount storage device location
umount mount point and record

-If: force uninstall

X. View the disk mounting situation

1. Direct mount command

  1. df [Options]
    -h: Display the capacity unit of the partition
    -T: Display the type of file system
    -i: Display the number of inode numbers of the partition
11. Set the automatic mounting of the file system
/etc/fstab配置文件
包含需要开机后自动挂载的文件系统记录
[root@localhost ~]# vi /etc/fstab

[root@localhost data]# vim /etc/fstab
Insert picture description here

Guess you like

Origin blog.csdn.net/Wsxyi/article/details/113625202