Home > System Tutorial > LINUX > Detailed explanation of three disk partitioning tools on CentOS Linux

Detailed explanation of three disk partitioning tools on CentOS Linux

WBOY
Release: 2024-01-15 10:54:05
forward
1011 people have browsed it

With the rapid development of technology, more and more enterprises have higher and higher requirements for the stability of servers. More and more enterprises are beginning to use Linux systems to deploy their own services in order to achieve high efficiency and stability. Of course, Any operating system requires the most basic foundation, which is the hard disk and hard disk partitions. Today I will recommend several partition tools under CentOS Linux and how to view the partition environment. I will also give you some basic knowledge about hard disks

1. Hard disk interface type

Partitioning must be a partition of the hard disk, so let’s first talk about the interface type of the hard disk. The hard disk will be divided now. It is divided into two categories, parallel interface and serial interface. Nowadays, serial interface is commonly used on servers and PCs. OK interface.

Parallel interface is divided into two interfaces: IDE and SCSI. The disadvantage of the parallel interface is that electrical signals will cause interference during transmission.

Interface rate:

IDE:133MB/s

SCIS:640MB/s

Serial interfaces are divided into three interfaces: STAT, SAS, and USB. Our servers and PCs also use SATA interfaces

Serial port:

SATA:6Gbps

SAS: 6Gbps

USB:480MB/s

The current disk partition modes are divided into two types, MBR and GPT.

MBR Mode

MBR: Master Boot Record, 1982, uses 32 bits to represent the number of sectors, and the partition does not exceed 2T

The number of partitions that can be partitioned in MBR mode is: 4 primary partitions; 3 primary partitions 1 extension (N logical partitions)

Of course, when the hard disk is partitioned, it needs some space to store the partition information. This part of the space is in track 0 and sector 0: 512 bytes.

Start 446 bytes to store boot loader

The middle 64 bytes store the partition table, and every 16 bytes: identifies a partition

The last 2 bytes: store 55AA to indicate the hard disk mode type

GPT Mode

GPT: GUID (Globals Unique Identifiers) partition table supports 128 partitions, uses 64 bits, supports 8Z (512Byte/block) 64Z (4096Byte/block)

Use 128-bit UUID (Universally Unique Identifier) ​​to represent the disk and partition. The GPT partition table is automatically backed up in the first and last copies, and has a CRC check digit

UEFI (Unified Extensible Firmware Interface) hardware supports GPT, enabling the operating system to boot

2. Let us see the capabilities of the three partition tools under Linux.

Laodangyizhuang fdisk.

fdisk is a very old partitioning tool in Linux. Although the tool is old, simplicity and convenience are the advantages of fdisk. Of course, gdisk also inherits this advantage. Their functions are very similar, but the fdisk tool is mainly used to To partition a hard disk in MBR mode, the gdisk tool is used to partition a hard disk in GPT mode. Here we will talk about the fdisk tool. fdisk cannot target 2T

fdisk, gdisk tools

fdisk /dev/sdb

fdisk -l [-u] [device...] View hard disk and partition information

Commonly used subcommands:

m Help List

CentOS Linux下的3款分区工具详解

p Partition List

CentOS Linux下的3款分区工具详解

l View partition type

CentOS Linux下的3款分区工具详解

t Change partition type

CentOS Linux下的3款分区工具详解

n Create a new partition

CentOS Linux下的3款分区工具详解

d Delete partition

CentOS Linux下的3款分区工具详解

w Save and exit

After fdisk partitioning, the operation is only in the memory and does not actually partition the hard disk. If you really need to partition w, just save it

CentOS Linux下的3款分区工具详解

q Exit without saving

Of course, if you regret it, entering q will not save the previous operation

After introducing the options, let me do an experiment for you. Let everyone know how to use this tool.

[root@TianRandai ~]#fdisk /dev/sdb#对/dev/sdb进行操作
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n #建立一个分区
Partition type:
 p primary (0 primary, 0 extended, 4 free)
 e extended
Select (default p): p #分区类型为主分区,p是主分区,e是扩展分区
Partition number (1-4, default 1): 1#指定分区号
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +2G
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): t #指定分区标记类型
Selected partition 1
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'

Command (m for help): w #保存操作
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
Copy after login

Powerful partitioning tool parted

parted

The partitioning of the parted tool is instantaneous, so you must be careful when partitioning, because you may accidentally partition the reused hard disk, so you must be cautious and cautious when using it.

Usage: parted [options]... [device [command [parameters]...]...]

parted /dev/sdb mklabel gpt|msdos specifies the mode for the disk

parted /dev/sdb print Display disk information

parted /dev/sdb mkpart primary/extended/logical 0 200 (default M) Create partition type and size

parted /dev/sdb rm 1 delete partition

parted -l displays information about all disks

选项介绍完,我来给大家做一个实验。让大家了解一下这款工具的使用方式。

[root@TianRandai ~]#parted /dev/sdb mklabel gpt #指定磁盘模式为GPT
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk
will be lost. Do you want to continue?
Yes/No? yes 
Information: You may need to update /etc/fstab.

[root@TianRandai ~]#parted /dev/sdb mkpart primary 0 2G #创建分区,分区类型为主分区,大小为2G
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
Information: You may need to update /etc/fstab.

[root@TianRandai ~]#parted /dev/sdb print #查看磁盘信息
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

NumberStart End SizeFile systemName Flags
 117.4kB2000MB2000MB primary

[root@TianRandai ~]#parted /dev/sdb rm 1 #删除分区1
Information: You may need to update /etc/fstab.

[root@TianRandai ~]#parted /dev/sdb print#再次查看磁盘信息
 Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
NumberStartEndSizeFile systemNameFlags
Copy after login

介绍完了分区就要介绍格式化了

格式化的命令可以使用

mkfs.文件系统类型 分区

#mkfs.ext4 /dev/sdb1

格式化后就可以使用挂载了

[root@TianRandai ~]#mkfs #文件系统的各个类型
mkfs mkfs.cramfsmkfs.ext3mkfs.fat mkfs.msdos mkfs.xfs
mkfs.btrfs mkfs.ext2mkfs.ext4mkfs.minix mkfs.vfat
[root@TianRandai ~]#mkfs.ext4 /dev/sdb1#将/dev/sdb1格式化为ext4
Copy after login

[root@TianRandai ~]#mkdir /mnt/disk1#在/mnt/下建一个disk1目录
[root@TianRandai ~]#mount /dev/sdb1 /mnt/disk1#将格式化号的分区挂载到/mnt/disk1撒花姑娘
[root@TianRandai ~]#df -h #查看挂载及使用情况
FilesystemSizeUsed Avail Use% Mounted on
/dev/sda210G4.5G5.5G45% /
devtmpfs898M 0898M 0% /dev
tmpfs 912M 88K912M 1% /dev/shm
tmpfs 912M9.0M903M 1% /run
tmpfs 912M 0912M 0% /sys/fs/cgroup
/dev/sda11014M169M846M17% /boot
tmpfs 183M 20K183M 1% /run/user/0
/dev/sdb1 1.9G5.7M1.7G 1% /mnt/disk1
Copy after login

mkswap 格式化swap类型的分区

格式化后需要swapon来启用格式化后的分区

开机自动挂载需要讲这些配置写到/etc/fstab中

具体的挂载的方法会在后面具体讲解。

[root@TianRandai ~]#free -h#先看一下swap的大小
totalusedfreesharedbuff/cache available
Mem: 1.8G483M429M 10M911M1.1G
Swap:2.0G0B2.0G
[root@TianRandai ~]#mkswap /dev/sdb1 #格式化/dev/sdb1分区
mkswap: /dev/sdb1: warning: wiping old ext4 signature.
Setting up swapspace version 1, size = 1953104 KiB
no label, UUID=5d9a150e-c247-4c7f-a4be-273a72bd3b5a
[root@TianRandai ~]#swapon /dev/sdb1 #启用swap分区
[root@TianRandai ~]#free -h#再次查看swap大小
totalusedfreesharedbuff/cache available
Mem: 1.8G484M427M 10M911M1.1G
Swap:3.9G0B3.9G
Copy after login

 

The above is the detailed content of Detailed explanation of three disk partitioning tools on CentOS Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template