1.分区构成
LBA 0:存放MBR分区表(考虑兼容性)用有效标识符决定是否启用那种(0055H和0xEE)
LBA 1:存放GPT的引导信息,分区表结构、以及规划要求:每个分区的信息需要用128ybte存储
LBA 2-33:32个扇区可用,用来存放分区表(128个)限于Windows,Linux没有限制,有一个分区存储分区表信息
LBA 34:后面是第一个分区的开始
2.parted下的命令
mklabel:创建新的磁盘标签(分区表类型)
print:查看分区表信息
quit:退出程序
mkpark:创建一个分区
3.GPT分区实操
[root@lianxi ~]# parted /dev/sdb #进入分区
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel 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? y
(parted) mkpart #创建分区
Partition name? []? abc #分区名称
File system type? [ext2]?
Start? 1m #起始点
End? 5G #终点
(parted) quit #退出
Information: You may need to update /etc/fstab.
[root@lianxi ~]#mount /dev/sdb1 /abc #挂载
[root@lianxi ~]# df -h #查看挂载信息
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.7G 16G 10% /
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 1014M 133M 882M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 4.7G 33M 4.7G 1% /abc
[root@lianxi ~]# vim /etc/fstab #设置启动挂载/dev/sdb1 /abc xfs defaults 0 0
4.gdisk命令
[root@lianxi ~]# parted /dev/sdc #进入分区
GNU Parted 3.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt #分区格式
Warning: The existing disk label on /dev/sdc will be destroyed and all data on this
disk will be lost. Do you want to continue?
Yes/No? yes
(parted) quit #退出
Information: You may need to update /etc/fstab
[root@lianxi ~]# gdisk /dev/sdc #进入gdisk
-bash: gdisk: command not found #需要安装gdisk
[root@lianxi ~]# yum install -y gdisk #安装gdisk安装完成
[root@lianxi ~]# gdisk /dev/sdc #再次进入
GPT fdisk (gdisk) version 0.8.10
Partition table scan:MBR: protectiveBSD: not presentAPM: not presentGPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): n #添加分区
Partition number (1-128, default 1): #默认名称sdc1
First sector (34-41943006, default = 2048) or {
+-}size{
KMGTP}: #默认或者自动选择起点
Last sector (2048-41943006, default = 41943006) or {
+-}size{
KMGTP}: +2G #选择终点
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8300
Changed type of partition to 'Linux filesystem'
Command (? for help): w #保存退出
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.
[root@lianxi ~]# mkfs.xfs /dev/sdc1 #格式化
meta-data=/dev/sdc1 isize=512 agcount=4, agsize=131072 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=524288, imaxpct=25= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@lianxi ~]# mkdir /book #创建挂载目录
[root@lianxi ~]# mount /dev/sdc1 /book #挂载
[root@lianxi ~]# df -h #查看挂载信息
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.7G 16G 10% /
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 1014M 133M 882M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 4.7G 33M 4.7G 1% /abc
/dev/sdc1 2.0G 33M 2.0G 2% /book
[root@lianxi ~]#
使用gdisk创建swap分区
swap(8200)可以将两个不同位置的分区合并成一个存储空间,普通分区类型(8300),不可以使用
free -h :查看swap的标准信息,以实际单位列出
mkswap :格式化
swapon:挂载
[root@lianxi ~]# gdisk /dev/sdd
GPT fdisk (gdisk) version 0.8.10
Partition table scan:MBR: protectiveBSD: not presentAPM: not presentGPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-41943006, default = 9764864) or {
+-}size{
KMGTP}:
Last sector (9764864-41943006, default = 41943006) or {
+-}size{
KMGTP}: +5G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8200
Changed type of partition to 'Linux swap'
Command (? for help): p
Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 1DC82D10-C35D-4E1B-843F-ABEFA71362F3
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 21694397 sectors (10.3 GiB)
Number Start (sector) End (sector) Size Code Name1 2048 9764863 4.7 GiB 0700 abc2 9764864 20250623 5.0 GiB 8200 Linux swap
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdd.
The operation has completed successfully.
[root@lianxi ~]# mkswap /dev/sdd1
Setting up swapspace version 1, size = 5242876 KiB
no label, UUID=87ef08f0-dff6-4c7f-8250-eb9973d01567
[root@lianxi ~]# swapon /dev/sdd1
[root@lianxi ~]# free -htotal used free shared buff/cache available
Mem: 972M 127M 700M 7.6M 144M 681M
Swap: 7.0G 0B 7.0G
[root@lianxi ~]#