parted分区

1.查看新增的磁盘
[root@localhost ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a5090

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 8837119 3905536 82 Linux swap / Solaris
/dev/sda3 8837120 83886079 37524480 83 Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

这里/dev/sdb是新加入的,下面我们对该磁盘使用parted进行分区


parted /dev/sdb

2.对新加的磁盘进行parted分区
[root@localhost ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: /dev/sdb: unrecognised disk label
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
(parted) mklabel gpt ##定义gpt格式
(parted) mkpart primary 0% 100% ##划分分区,这里将整个盘给到该分区,这里primary是分区名,也可以mkpart p1 0% 100%
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 10.7GB 10.7GB primary

(parted) quit
Information: You may need to update /etc/fstab.
这里直接退出,系统会自动保存分区信息

3.格式化分区
使用parted划分分区后,会生成/dev/sdb1文件
[root@localhost ~]# ls -al /dev/sdb*
brw-rw----. 1 root disk 8, 16 Jun 23 23:39 /dev/sdb
brw-rw----. 1 root disk 8, 17 Jun 23 23:39 /dev/sdb1

[root@localhost ~]# mkfs.xfs /dev/sdb1

查看分区
[root@localhost ~]# parted -l
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
1 1049kB 525MB 524MB primary xfs boot
2 525MB 4525MB 3999MB primary linux-swap(v1)
3 4525MB 42.9GB 38.4GB primary xfs


Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 10.7GB 10.7GB xfs primary

5.挂载分区
[root@localhost /]# mkdir /mnt11
[root@localhost /]# mount /dev/sdb1 /mnt11

6.加入到自启动
[root@localhost /]# more /etc/fstab

#
# /etc/fstab
# Created by anaconda on Wed Jun 23 20:55:43 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=afd64c95-6181-4e36-82d3-f5e138fa7969 / xfs defaults 0 0
UUID=da2aa6ea-e9f8-42b1-baf4-bcf8c8ea2d85 /boot xfs defaults 0 0
UUID=bd950941-0b3f-493f-abe4-ecd94cdab708 swap swap defaults 0 0
/dev/sdb1 /mnt11 xfs defaults 0 0

原文地址:https://www.cnblogs.com/hxlasky/p/14926246.html