3 partitioning tools under CentOS Linux

Introduction

With the rapid development of science and technology, more and more companies have higher and higher requirements for the stability of servers. More and more companies are beginning to use the Linux system to deploy their services in order to achieve efficient stability. Of course, any operating system All need a basic foundation, that is, hard disk and hard disk partitioning. Today I will recommend several partitioning tools under CentOS Linux and how to check the partition environment. I will also bring you some basic knowledge of hard disks.

  1. The interface type of the hard disk

Partitioning is definitely to partition the hard disk, so let’s talk about the interface type of the hard disk first. Now the hard disk is divided into two categories, parallel interface and serial interface. Nowadays, serial interfaces are commonly used on servers and PCs. .

Parallel interfaces are divided into IDE and SCSI interfaces. The disadvantage of parallel interfaces is that electrical signals will interfere during transmission.

Interface rate:

IDE:133MB/s

SCIS:640MB/s

Serial interface, divided into STAT, SAS, USB, three kinds of interfaces, our server and PC also use SATA interface

Serial port:

SATA:6Gbps

SAS:6Gbps

USB:480MB/s

The current disk partition mode is divided into two types, MBR and GPT.

MBR mode

MBR: Master Boot Record, 1982, uses 32 bits to indicate 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 expansion (N logical partitions)

Of course, when the hard disk is partitioned, a part of the space is needed to store the partition information. This part of the space is at track 0 and sector 0: 512bytes.

Start 446bytes to store the boot loader

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

The last 2bytes: 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) and 64Z (4096Byte/block)

Use 128-bit UUID (Universally Unique Identifier) to indicate that the disk and partition GPT partition table is automatically backed up at the beginning and the end, and there is a CRC check bit

UEFI (Unified Extended Firmware Interface) hardware supports GPT to enable the operating system to boot

  1. Let us see the capabilities of 3 partitioning tools under Linux.

Always strengthen fdisk.

fdisk is a very old partitioning tool in Linux. Although the tool is old, its 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 for MBR mode. The hard disk is partitioned. The gdisk tool is used to partition the hard disk in GPT mode. Here is a fdisk tool. fdisk cannot partition disks above 2T because MBR mode does not support partition formats above 2T.

fdisk, gdisk tools

fdisk /dev/sdb

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

Commonly used subcommands:

m help list

p partition list

l View partition type

t change the partition type

n Create a new partition

d Delete partition

w save and exit

After fdisk is partitioned, the operation is just that the hard disk is not partitioned in the memory, if you really need to partition w to save

q Exit without saving

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

After the options are introduced, let me give you an experiment. Let everyone know how to use this tool.

[ root@TianRandai ~]#fdisk /dev/sdb            #Correct/dev/sdb to operate
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                       #Create a partition
Partition type:
 p   primary(0 primary,0 extended,4 free)
 e   extended
Select(default p): p                         #Partition type is primary partition,p is the primary partition,e is the extended partition
Partition number(1-4,default1):1          #Specify the partition number
First sector(2048-41943039,default2048): 
Using default value 2048
Last sector,+sectors or +size{K,M,G}(2048-41943039,default41943039):+2G
Partition 1of type Linux and of size 2 GiB is setCommand(m for help): t                       #Specify the partition mark type
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                       #Save operation
The partition table has been altered!

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

Powerful partition tool parted

parted

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

Usage: parted [option]... [equipment [command [parameter]...]...]

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

parted /dev/sdb print shows disk information

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

parted /dev/sdb rm 1 delete partition

parted -l displays information about all disks

After the options are introduced, let me give you an experiment. Let everyone know how to use this tool.

[ root@TianRandai ~]#parted /dev/sdb mklabel gpt             #Specify the disk mode as 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     #Create a partition, the partition type is primary partition, the size is 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                   #View disk information
Model: VMware, VMware Virtual S(scsi)
Disk /dev/sdb:21.5GB
Sector size(logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 117.4 kB  2000MB  2000MB               primary

[ root@TianRandai ~]#parted /dev/sdb rm 1                   #Delete partition 1
Information: You may need to update /etc/fstab.[root@TianRandai ~]#parted /dev/sdb print                  #View disk information again
 Model: VMware, VMware Virtual S(scsi)
Disk /dev/sdb:21.5GB
Sector size(logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
Number  Start  End  Size  File system  Name  Flags

After the introduction of partitions, we will introduce formatting.

The formatted command can be used

mkfs. File system type Partition

mkfs.ext4 /dev/sdb1

After formatting, you can use mount

[ root@TianRandai ~]#mkfs                   #Various types of file systems
mkfs         mkfs.cramfs  mkfs.ext3    mkfs.fat     mkfs.msdos   mkfs.xfs
mkfs.btrfs   mkfs.ext2    mkfs.ext4    mkfs.minix   mkfs.vfat    
[ root@TianRandai ~]#mkfs.ext4 /dev/sdb1    #will/dev/sdb1 is formatted as ext4
[ root@TianRandai ~]#mkdir /mnt/disk1                  #in/mnt/Create a disk1 directory
[ root@TianRandai ~]#mount /dev/sdb1 /mnt/disk1        #Mount the formatted partition to/mnt/disk1 flower girl
[ root@TianRandai ~]#df -h                             #View mounting and usage
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        10G  4.5G  5.5G  45% /
devtmpfs        898M     0  898M   0%/dev
tmpfs           912M   88K  912M   1%/dev/shm
tmpfs           912M  9.0M  903M   1%/run
tmpfs           912M     0  912M   0%/sys/fs/cgroup
/dev/sda1      1014M  169M  846M  17%/boot
tmpfs           183M   20K  183M   1%/run/user/0/dev/sdb1       1.9G  5.7M  1.7G   1%/mnt/disk1

mkswap format swap type partition

After formatting, swapon is required to enable the formatted partition

To automatically mount at boot, you need to write these configurations to /etc/fstab

The specific mounting method will be explained in detail later.

[ root@TianRandai ~]#free -h              #First look at the size of swap
    total        used        free      shared  buff/cache   available
Mem:1.8G        483M        429M         10M        911M        1.1G
Swap:2.0G          0B        2.0G
[ root@TianRandai ~]#mkswap /dev/sdb1     #format/dev/sdb1 partition
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     #Enable swap partition
[ root@TianRandai ~]#free -h              #Check the swap size again
    total        used        free      shared  buff/cache   available
Mem:1.8G        484M        427M         10M        911M        1.1G
Swap:3.9G          0B        3.9G

If there is the next issue, it will bring you mount mounting, soft Raid technology, and logical volume configuration methods.

Recommended Posts

3 partitioning tools under CentOS Linux
Install MySQL under Linux (CentOS 7)
CentOS 6.8 under linux install mongodb
Install mysql8.0.13 version under Linux CentOS7 system
Deploy GitBook under CentOS7
Linux Network Foundation (CentOS7)
Linux (centos7) build gitlab
Compile Hadoop-2.7.6 under CentOS7.4
Install ActiveMQ under Centos7
Install PostgreSQL12 under CentOS7
Install CentOS under VMware
Linux Centos7 install jdk1.8
CentOS (linux) install PostgreSQL
Deploy JDK+Tomcat8 under CentOS
Install mysql under Centos 7
Configure lamp under centos6.8
Linux notes (1): CentOS-7 installation
Install Jenkins under Centos 7
Redis3 installation under Centos7
Install MariaDB under MariaDB Centos7
Install mysql5.1 under CentOS6.5
Linux CentOS 7 installation tutorial
Centos 7 install JDK (Linux install jdk)
Linux | Will JDK be played under CentOS7? you sure?
Compile and install Lnmp shell script under Linux centos
Xen virtualization combat under CentOS 6.6
[CentOS environment deployment] Java7/Java8 deployment under CentOS
Build docker environment under Centos6.5
Build OpenV** Server under CentOS7
Know Linux and install CentOS
Build OpenLDAP server under CentOS7
Install python environment under Linux
Linux Centos7 install redis tutorial
Configure static IP under CentOS 7
Install MySQL 8.0.16 on Linux Centos
Install Oracle11gR2 database under CentOS6.9
Redis cluster installation under CentOS
Linux CentOS 7 virtual machine clone
Root password cracking under CentOS 7
SELinux security settings under CentOS
Install Java JDK8 under CentOS6
Install MongoDB database under CentOS7
Set static IP under Centos
Suid mention rights under Linux
CentOS8 Linux 8.0.1905 installation process (illustration)
Linux centos system boot process
Install Mesos tutorial under CentOS7
Install and configure keepalived under CentOS 5.9
Common Linux operations (based on centos7)
Compile and install LAMP under Centos 5.2
[Introduction to redis] Install redis under Centos
RabbitMQ cluster deployment record under Centos6.9
Elasticsearch cluster deployment record under CentOS7
Linux CentOS 7 install JDK detailed steps
Install MySQL on Linux CentOS7 (Windows)
Deploy and optimize Tomcat under Centos
[Linux] Some high-efficiency tools of Ubuntu
Linux: Centos7 upgrade the original kernel
Install Harbor mirror warehouse under CentOS
Build an FTP server under centos7
​Install Oracle database on CentOS Linux