[Linux] - parted disk partition

1. Globally uniquely identify the partition table, GPT

全局唯一标识分区表(GUID Partition Table,缩写:GPT)

GPT is a physical hard diskpartition structure. It is part of the Extensible Firmware Interface standard and is used toReplacement of Master Boot Record Partition Table in BIOSTraditional Master Boot Record (MBR) disk partitions support volumes up to 2.2TB, each diskUp to 4 primary partitions,or3 primary partitions, 1 extended partitionstay in peaceMultiple logical partitions in the extended partition

Compared with MBR partition method, GPT has more advantages because itAllows up to 128 partitions per disk, supporting volume sizes up to 18EB (gigabytes),Allows the use of primary and backup disk partition tables for redundancy, also supports unique disk and partition IDs (GUIDs).

2. Disk partition format basis

(1) If the diskLess than 2TB, can be partitioned with fdisk /dev/sdb, namely the MBR partition format;

(2) If the diskMore than 2TB, can be partitioned with parted /dev/sdb, because the MBR partition disk cannot be larger than 2.2TB, soMore than 2TB generally use the GPT partition format

Normally, we chooseUse the fdisk toolto partition, but the disk space used in the actual production environment is getting larger and larger, showingTiB level growth; while the commonly used fdisk tool has a size limit for partitions, it can only divide disks smaller than 2T, and fdisk cannot meet the requirements when partitioning disks larger than 2T; there are two methods at this time, one isIncrease disk space by expanding volumes with volume management, the second isUse the parted tool to implement partitioning operations on GPT disks

3. parted disk partition instance

操作实例:

(1) Turn off the host, add a new hard disk, and restart the host;

insert image description here

(2) First use the parted tool to divide the disk device /dev/sdb into the primary partition parted1";

[root@clr ~]# lsblk   #查看磁盘分区挂载情况
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   60G  0 disk 
├─sda1   8:1    0   37G  0 part /
├─sda2   8:2    0    1K  0 part 
└─sda5   8:5    0  3.9G  0 part [SWAP]
sdb      8:16   0   20G  0 disk 
sr0     11:0    1  4.4G  0 rom  /run/media/root/CentOS 7 x86_64

[root@clr ~]# parted /dev/sdb #进入parted命令交互后,将/dev/sdb进行分区
GNU Parted 3.1
使用 /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel                                                          
新的磁盘标签类型? gpt         #设置磁盘标签格式类型为gpt                                        
(parted) mkpart         #创建分区表                                                      
分区名称?  []? parted1    #分区名称,自定义为parted1
文件系统类型?  [ext2]? ext4   #文件系统类型设置为ext4
起始点? 0%       #起始点设置为从0开始                                                        
结束点? 20GB       #结束点设置为磁盘容量总大小20GB
(parted) print     #打印分区详细信息
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     标志
 1      1049kB  20.0GB  20.0GB               parted1   #此分区的number号为1,也就是删除时指定的id号

查看分区情况,如下所示:

insert image description here

(3) Example of deleting a partition, if the partition is wrong, you can use the rm command to delete the partition";

(parted) rm 1  #rm后面使用分区的号码,也就是print打印出来的number号
(parted) print                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start  End  Size  File system  Name  标志

(4) Formatting operation, it can be mounted and used after completion";

[root@clr ~]# mkfs.ext4 /dev/sdb1  #将分区/dev/sdb1格式化为ext4类型的文件系统
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1220608 inodes, 4882432 blocks
244121 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2153775104
149 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成   

[root@clr ~]# mkdir /data  
[root@clr ~]# mount /dev/sdb1 /data   #将硬盘分区/dev/sdb1挂载到/data目录中
[root@clr ~]# df -hT
文件系统       类型      容量  已用  可用 已用% 挂载点
devtmpfs       devtmpfs  2.0G     0  2.0G    0% /dev
tmpfs          tmpfs     2.0G     0  2.0G    0% /dev/shm
tmpfs          tmpfs     2.0G   13M  2.0G    1% /run
tmpfs          tmpfs     2.0G     0  2.0G    0% /sys/fs/cgroup
/dev/sda1      xfs        38G  5.4G   32G   15% /
tmpfs          tmpfs     394M   32K  394M    1% /run/user/0
/dev/sr0       iso9660   4.4G  4.4G     0  100% /run/media/root/CentOS 7 x86_64
/dev/sdb1      ext4       19G   45M   18G    1% /data

(5) Set the boot to automatically mount";

Method 1: Edit the /etc/fstab file;

[root@clr ~]# vim /etc/fstab
/dev/sdb1               /data             ext4    defaults        0 0      #将挂载信息添加到/etc/fstab文件中,实现永久挂载       

Method 2: Edit the /etc/rc.local file. To edit this file, you need to ensure that /etc/rc.d/rc.local has execution permission;

[root@clr ~]# chmod +x /etc/rc.d/rc.local  #赋予所有用户对/etc/rc.d/rc.local文件的执行权限

[root@clr ~]# vim /etc/rc.local   #编辑/etc/rc.local文件,并添加以下内容
mount /dev/sdb1  /data

[root@clr ~]# reboot  重启系统,进行测试

查看挂载情况,如下所示:

insert image description here

Guess you like

Origin blog.csdn.net/cailirong123/article/details/130015943