Linux disk management and file system (see it at a glance)

1. Disk Basics

Insert picture description here

1.1 Disk structure

1) Physical structure
Disc: The hard disk has multiple discs, each with 2 sides
Magnetic head: One head on each side
2) Data structure

Sector: The disk is divided into multiple sectors. Each sector stores 512 bytes of data. The smallest storage unit of the hard disk.
Track: Concentric circles with different radii on the same disk are drawn on the surface of the disk by the magnetic head. Circular track
Cylinder: A cylindrical surface composed of different discs with the same radius, composed of multiple tracks with the same radius circle.
Cylinders, heads, and sectors can be used to uniquely locate each area on the disk

3) Hard disk storage capacity
Capacity = number of heads × number of tracks (cylinders) × number of sectors per track × number of bytes per sector (512 bytes)

4) Disk interface type
IDE: The parallel port data cable connects the motherboard and the hard disk. The anti-interference is too poor, and the cable takes up a large 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-class personal computers and servers. The CPU occupancy rate is low during data transmission, the speed is fast, and it supports hot swapping.
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.
Fibre Channel: Fibre Channel disk greatly improves the communication speed of a multi-disk system. Hot plugging, high broadband, remote connections, and a large number of connected devices are the main characteristics of Fibre Channel.

1.2 Disk partition representation

1) Master boot area (MBR: Master Boot Record)

  • MBR is located at the first physical sector of the hard disk
  • MBR contains the master boot program and hard disk partition table of the hard disk
  • The MBR has a total of 512 bytes, the first 466 bytes are the master boot record, and the partition table is stored in the 477-510 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
/dev/sdb5中的sdb5
sd 表示SCSI设备(常用) hd 表示IDE设备
硬盘的顺序号,以字母a、b、c……表示
分区的顺序号,以数字1、2、3……表示。主分区从1-4,第一个逻辑分区始终从5开始。

2) 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 will always start from 5

  • The master boot record (MBR) disk partition supports a maximum volume of 2.2TB, and patede will be used if it is larger than 2.2T; each disk has a maximum of 4 primary partitions, or 3 primary partitions, 1 extended partition, and multiple partitions in the extended partition. Logical partitions).

  • Insert picture description here

2. File system

2.1 File system type

■XFS file system

  • Partition for storing file and directory data

  • The high-performance journal file system is particularly good at handling large files and can support millions of terabytes of storage space.

  • The file system used by default in CentOS 7
    SWAP——Swap file system

  • Create swap partition for Linux system

  • Generally set to 1.5~2 times the physical memory
    Other file system types supported by Linux

  • EXT4、FAT32、NTFS、 LVM

3. Manage disks and partitions

3.1 Detect and confirm the new disk

format:

fdisk -l [磁盘设备]

Insert picture description here
7 fields

  • Device: The device file name of the partition.
  • Boot: Whether it is a boot partition. If it is, it is marked with "*".
  • Start: The starting position (number of cylinders) of the partition in the hard disk.
  • End: The ending 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: The system ID number corresponding to the partition. For example, 83 represents the XFS partition or EXT4 partition in Linux, and 8e represents the LVM logical volume.
  • System: Partition type.

3.2 Manage Disk Partitions

fdisk /dev/sdb

交互模式中的常用指令:
m:获取帮助菜单
n:新建分区
p:查看分区情况
d:删除分区
t:变更分区的类型
w:保存分区操作并退出
q:不保存分区操作并退出

创建分区步骤
n
	--> p 主分区、e 扩展分区、l 逻辑分区
		--> 设置分区:1  (范围1-4,如按 Enter 键接受默认值)
			--> 设置柱面序列:直接按 Enter 键接受默认值
				--> 设置分区大小:+20G  (指定大小为 20GB,如按 Enter 键接受默认值表示所有空间)
					--w

变更硬盘(特别是正在使用的硬盘)的分区设置以后,建议最好将系统重启一次,或者执行
“partprobe”命令使操作系统检测新的分区表情况。以防格式化分区时损坏硬盘中已有的数据。
                            partprobe /dev/sdb

4. Create a file system

4.1 Create a file system (format): mkfs

Make Filesystem, create a file system (format)

mkfs -t 文件系统类型 分区设备   mkfs -t xfs /dev/sdb1
或
mkfs.(分区类型) 分区设备      mkfs.xfs /dev/sdb1

4.2 Create file system swap

Command format: mkswap partition device

创建交换文件系统
创建swap之前,目标分区应先通过fdisk 工具将分区类型ID 号设为 82
fdisk /dev/sdb
-->t
	-->5
		-->82

mkswap /dev/sdb5
swapon /dev/sdb5	         启用新增加的交换分区
swapoff /dev/sdb5	         停用指定的交换分区
swapon -s 			         查看每个分区的swap状态信息
free -m				         查看总的swap状态信息
创建交换分区之前,目标分区应先通过 fdisk 工具将分区类型号设置为 82
fdisk   /dev/sdb
--->t
    --->5(分区号)
         --->82(设置类型为swap)
mkswap   /dev/sdb5
swapon   /dev/sdb5       #启用新增加的交换分区
swapoff  /dev/sdb5       #停用指定的交换分区
swapon  -s               #查看每个分区的swap状态
free    -m               #查看总的swap状态信息

4.3 Mount and unmount the file system-mount, umount

挂载文件系统、ISO镜像到指定文件夹
mount  [-t 类型]  存储设备  挂载点目录
mount  -o loop  ISO镜像文件  挂载点目录
-t:用于指定文件系统类型,通常可以省略,由系统自动识别
-o:挂载参数列表,以英文逗号分隔;如用来描述特殊设备,用loop指定

卸载已挂载的文件系统
卸载前提:挂载的设备或者目录没有被在使用中,要先退出挂载目录
umount [-lf] 存储设备目录或者挂载点目录

-lf:强制卸载

查看磁盘使用情况
1.直接 mount 命令

2. df [选项]
-h:显示分区的容量单位
-T:显示文件系统的类型
-i:显示分区的inode号码数量

查看设备的UUID和文件系统类型
blkid [设备]

4.4 Set up automatic mounting of the file system

Set the automatic mounting of the file system. The
Linux operating system will automatically read the contents of the /etc/fstab file and automatically mount the specified file system every time it is turned on.
vim /etc/fstab
/dev/sdb1 /opt xfs defaults 0 0
/dev/sr0 /mnt iso9660 defaults 0 0

Field 1: Device name or device volume label name. (Partition)
The second field: the location of the mount point directory of the file system. (Mount point)
The third field: file system type, such as xfs, swap, etc. (File system type)
The fourth field: Mount parameters, that is, the parameters that can be used after the "-o" option of the mount command. For example, defaults (default parameters), rw (read and write), ro (read only), noexec (disable the execution of the program). (Mount parameter)
The fifth field: indicates whether the file system needs dump backup (dump is a backup tool). Generally, it is set to 1 to indicate need, and to 0, it will be ignored by dump. (Backup)
The 6th field: This number determines the sequence of disk checks when the system is started. 0 means no inspection, 1 means priority inspection, and 2 means second inspection. The root partition should be set to 1, and the other partitions should be set to 2. (Disk check sequence)

After entering the correct format, restart after wq, the two mounts written will be automatically mounted when restarting.
Insert picture description here

Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/zhangyuebk/article/details/113655388